From 8edd1d8aa597514d5089f8cf2aa640ec14c1e389 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 7 Jun 2022 14:21:19 +1000 Subject: CMake: optionally disable OBJ, STL & GPencil SVG support The following CMake options have been added (enabled by default), except for the lite build configuration. - WITH_IO_STL - WITH_IO_WAVEFRONT_OBJ - WITH_IO_GPENCIL (for grease pencil SVG importing). Note that it was already possible to disable grease pencil export by disabling WITH_PUGIXML & WITH_HARU. This is intended to keep the lite builds fast and small for building, linking & execution. Reviewed By: iyadahmed2001, aras_p, antoniov, mont29 Ref D15141 --- CMakeLists.txt | 3 ++ build_files/cmake/config/blender_lite.cmake | 3 ++ release/scripts/startup/bl_ui/space_topbar.py | 26 +++++++---- source/blender/editors/io/CMakeLists.txt | 25 ++++++++-- source/blender/editors/io/io_gpencil_export.c | 54 ++++++++++++---------- source/blender/editors/io/io_gpencil_import.c | 40 ++++++++-------- source/blender/editors/io/io_gpencil_utils.c | 14 ++++-- source/blender/editors/io/io_obj.c | 46 +++++++++--------- source/blender/editors/io/io_ops.c | 14 ++++-- source/blender/editors/io/io_stl_ops.c | 24 ++++++---- source/blender/io/CMakeLists.txt | 20 ++++++-- source/blender/python/intern/CMakeLists.txt | 12 +++++ .../blender/python/intern/bpy_app_build_options.c | 21 +++++++++ 13 files changed, 199 insertions(+), 103 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 90baadcac8b..31608b0c1ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -300,6 +300,9 @@ option(WITH_USD "Enable Universal Scene Description (USD) Suppor # 3D format support # Disable opencollada when we don't have precompiled libs option(WITH_OPENCOLLADA "Enable OpenCollada Support (http://www.opencollada.org)" ON) +option(WITH_IO_WAVEFRONT_OBJ "Enable Wavefront-OBJ 3D file format support (*.obj)" ON) +option(WITH_IO_STL "Enable STL 3D file format support (*.stl)" ON) +option(WITH_IO_GPENCIL "Enable grease-pencil file format IO (*.svg, *.pdf)" ON) # Sound output option(WITH_SDL "Enable SDL for sound" ON) diff --git a/build_files/cmake/config/blender_lite.cmake b/build_files/cmake/config/blender_lite.cmake index 2f6057ee9c0..5ce344d39e8 100644 --- a/build_files/cmake/config/blender_lite.cmake +++ b/build_files/cmake/config/blender_lite.cmake @@ -37,6 +37,9 @@ set(WITH_IMAGE_TIFF OFF CACHE BOOL "" FORCE) set(WITH_IMAGE_WEBP OFF CACHE BOOL "" FORCE) set(WITH_INPUT_NDOF OFF CACHE BOOL "" FORCE) set(WITH_INTERNATIONAL OFF CACHE BOOL "" FORCE) +set(WITH_IO_STL OFF CACHE BOOL "" FORCE) +set(WITH_IO_WAVEFRONT_OBJ OFF CACHE BOOL "" FORCE) +set(WITH_IO_GPENCIL OFF CACHE BOOL "" FORCE) set(WITH_JACK OFF CACHE BOOL "" FORCE) set(WITH_LIBMV OFF CACHE BOOL "" FORCE) set(WITH_LLVM OFF CACHE BOOL "" FORCE) diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py index 2980ec9ace7..d8bd724f554 100644 --- a/release/scripts/startup/bl_ui/space_topbar.py +++ b/release/scripts/startup/bl_ui/space_topbar.py @@ -453,9 +453,13 @@ class TOPBAR_MT_file_import(Menu): self.layout.operator( "wm.usd_import", text="Universal Scene Description (.usd, .usdc, .usda)") - self.layout.operator("wm.gpencil_import_svg", text="SVG as Grease Pencil") - self.layout.operator("wm.obj_import", text="Wavefront (.obj) (experimental)") - self.layout.operator("wm.stl_import", text="STL (.stl) (experimental)") + if bpy.app.build_options.io_gpencil: + self.layout.operator("wm.gpencil_import_svg", text="SVG as Grease Pencil") + + if bpy.app.build_options.io_wavefront_obj: + self.layout.operator("wm.obj_import", text="Wavefront (.obj) (experimental)") + if bpy.app.build_options.io_stl: + self.layout.operator("wm.stl_import", text="STL (.stl) (experimental)") class TOPBAR_MT_file_export(Menu): @@ -472,14 +476,16 @@ class TOPBAR_MT_file_export(Menu): self.layout.operator( "wm.usd_export", text="Universal Scene Description (.usd, .usdc, .usda)") - # Pugixml lib dependency - if bpy.app.build_options.pugixml: - self.layout.operator("wm.gpencil_export_svg", text="Grease Pencil as SVG") - # Haru lib dependency - if bpy.app.build_options.haru: - self.layout.operator("wm.gpencil_export_pdf", text="Grease Pencil as PDF") + if bpy.app.build_options.io_gpencil: + # Pugixml lib dependency + if bpy.app.build_options.pugixml: + self.layout.operator("wm.gpencil_export_svg", text="Grease Pencil as SVG") + # Haru lib dependency + if bpy.app.build_options.haru: + self.layout.operator("wm.gpencil_export_pdf", text="Grease Pencil as PDF") - self.layout.operator("wm.obj_export", text="Wavefront (.obj) (experimental)") + if bpy.app.build_options.io_wavefront_obj: + self.layout.operator("wm.obj_export", text="Wavefront (.obj) (experimental)") class TOPBAR_MT_file_external_data(Menu): diff --git a/source/blender/editors/io/CMakeLists.txt b/source/blender/editors/io/CMakeLists.txt index 98438c3e959..a716c00d5d9 100644 --- a/source/blender/editors/io/CMakeLists.txt +++ b/source/blender/editors/io/CMakeLists.txt @@ -49,8 +49,6 @@ set(SRC set(LIB bf_blenkernel bf_blenlib - bf_wavefront_obj - bf_stl ) if(WITH_OPENCOLLADA) @@ -60,6 +58,27 @@ if(WITH_OPENCOLLADA) add_definitions(-DWITH_COLLADA) endif() +if(WITH_IO_WAVEFRONT_OBJ) + list(APPEND LIB + bf_wavefront_obj + ) + add_definitions(-DWITH_IO_WAVEFRONT_OBJ) +endif() + +if(WITH_IO_STL) + list(APPEND LIB + bf_stl + ) + add_definitions(-DWITH_IO_STL) +endif() + +if(WITH_IO_GPENCIL) + list(APPEND LIB + bf_gpencil + ) + add_definitions(-DWITH_IO_GPENCIL) +endif() + if(WITH_ALEMBIC) list(APPEND LIB bf_alembic @@ -82,6 +101,4 @@ if(WITH_HARU) add_definitions(-DWITH_HARU) endif() -list(APPEND LIB bf_gpencil) - blender_add_lib(bf_editor_io "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/editors/io/io_gpencil_export.c b/source/blender/editors/io/io_gpencil_export.c index 7ac05fcca3e..6e5ae9f3cba 100644 --- a/source/blender/editors/io/io_gpencil_export.c +++ b/source/blender/editors/io/io_gpencil_export.c @@ -5,36 +5,38 @@ * \ingroup editor/io */ -#include "BLI_path_util.h" -#include "BLI_string.h" +#ifdef WITH_IO_GPENCIL -#include "DNA_gpencil_types.h" -#include "DNA_space_types.h" +# include "BLI_path_util.h" +# include "BLI_string.h" -#include "BKE_gpencil.h" -#include "BKE_main.h" -#include "BKE_report.h" -#include "BKE_screen.h" +# include "DNA_gpencil_types.h" +# include "DNA_space_types.h" -#include "BLT_translation.h" +# include "BKE_gpencil.h" +# include "BKE_main.h" +# include "BKE_report.h" +# include "BKE_screen.h" -#include "RNA_access.h" -#include "RNA_define.h" +# include "BLT_translation.h" -#include "UI_interface.h" -#include "UI_resources.h" +# include "RNA_access.h" +# include "RNA_define.h" -#include "WM_api.h" -#include "WM_types.h" +# include "UI_interface.h" +# include "UI_resources.h" -#include "DEG_depsgraph.h" -#include "DEG_depsgraph_query.h" +# include "WM_api.h" +# include "WM_types.h" -#include "io_gpencil.h" +# include "DEG_depsgraph.h" +# include "DEG_depsgraph_query.h" -#include "gpencil_io.h" +# include "io_gpencil.h" -#if defined(WITH_PUGIXML) || defined(WITH_HARU) +# include "gpencil_io.h" + +# if defined(WITH_PUGIXML) || defined(WITH_HARU) /* Definition of enum elements to export. */ /* Common props for exporting. */ static void gpencil_export_common_props_definition(wmOperatorType *ot) @@ -87,10 +89,10 @@ static void set_export_filepath(bContext *C, wmOperator *op, const char *extensi RNA_string_set(op->ptr, "filepath", filepath); } } -#endif +# endif /* <-------- SVG single frame export. --------> */ -#ifdef WITH_PUGIXML +# ifdef WITH_PUGIXML static bool wm_gpencil_export_svg_common_check(bContext *UNUSED(C), wmOperator *op) { char filepath[FILE_MAX]; @@ -241,10 +243,10 @@ void WM_OT_gpencil_export_svg(wmOperatorType *ot) "Clip Camera", "Clip drawings to camera size when export in camera view"); } -#endif +# endif /* <-------- PDF single frame export. --------> */ -#ifdef WITH_HARU +# ifdef WITH_HARU static bool wm_gpencil_export_pdf_common_check(bContext *UNUSED(C), wmOperator *op) { @@ -406,4 +408,6 @@ void WM_OT_gpencil_export_pdf(wmOperatorType *ot) "Frames", "Which frames to include in the export"); } -#endif +# endif /* WITH_HARU */ + +#endif /* WITH_IO_GPENCIL */ diff --git a/source/blender/editors/io/io_gpencil_import.c b/source/blender/editors/io/io_gpencil_import.c index 8bed32ad6c3..45f5441616f 100644 --- a/source/blender/editors/io/io_gpencil_import.c +++ b/source/blender/editors/io/io_gpencil_import.c @@ -5,34 +5,36 @@ * \ingroup editor/io */ -#include "BLI_path_util.h" +#ifdef WITH_IO_GPENCIL -#include "DNA_gpencil_types.h" -#include "DNA_space_types.h" +# include "BLI_path_util.h" -#include "BKE_context.h" -#include "BKE_gpencil.h" -#include "BKE_report.h" +# include "DNA_gpencil_types.h" +# include "DNA_space_types.h" -#include "BLT_translation.h" +# include "BKE_context.h" +# include "BKE_gpencil.h" +# include "BKE_report.h" -#include "RNA_access.h" -#include "RNA_define.h" +# include "BLT_translation.h" -#include "UI_interface.h" -#include "UI_resources.h" +# include "RNA_access.h" +# include "RNA_define.h" -#include "WM_api.h" -#include "WM_types.h" +# include "UI_interface.h" +# include "UI_resources.h" -#include "DEG_depsgraph.h" -#include "DEG_depsgraph_query.h" +# include "WM_api.h" +# include "WM_types.h" -#include "ED_gpencil.h" +# include "DEG_depsgraph.h" +# include "DEG_depsgraph_query.h" -#include "io_gpencil.h" +# include "ED_gpencil.h" -#include "gpencil_io.h" +# include "io_gpencil.h" + +# include "gpencil_io.h" /* <-------- SVG single frame import. --------> */ static bool wm_gpencil_import_svg_common_check(bContext *UNUSED(C), wmOperator *op) @@ -174,3 +176,5 @@ void WM_OT_gpencil_import_svg(wmOperatorType *ot) 0.001f, 100.0f); } + +#endif /* WITH_IO_GPENCIL */ diff --git a/source/blender/editors/io/io_gpencil_utils.c b/source/blender/editors/io/io_gpencil_utils.c index fa5fcd79b96..9a88daef1a1 100644 --- a/source/blender/editors/io/io_gpencil_utils.c +++ b/source/blender/editors/io/io_gpencil_utils.c @@ -5,14 +5,16 @@ * \ingroup editor/io */ -#include "DNA_space_types.h" +#ifdef WITH_IO_GPENCIL -#include "BKE_context.h" -#include "BKE_screen.h" +# include "DNA_space_types.h" -#include "WM_api.h" +# include "BKE_context.h" +# include "BKE_screen.h" -#include "io_gpencil.h" +# include "WM_api.h" + +# include "io_gpencil.h" ARegion *get_invoke_region(bContext *C) { @@ -46,3 +48,5 @@ View3D *get_invoke_view3d(bContext *C) return NULL; } + +#endif /* WITH_IO_GPENCIL */ diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c index 05bccce7948..a8eed136df3 100644 --- a/source/blender/editors/io/io_obj.c +++ b/source/blender/editors/io/io_obj.c @@ -4,37 +4,39 @@ * \ingroup editor/io */ -#include "DNA_space_types.h" +#ifdef WITH_IO_WAVEFRONT_OBJ -#include "BKE_context.h" -#include "BKE_main.h" -#include "BKE_report.h" +# include "DNA_space_types.h" -#include "BLI_path_util.h" -#include "BLI_string.h" -#include "BLI_utildefines.h" +# include "BKE_context.h" +# include "BKE_main.h" +# include "BKE_report.h" -#include "BLT_translation.h" +# include "BLI_path_util.h" +# include "BLI_string.h" +# include "BLI_utildefines.h" -#include "ED_outliner.h" +# include "BLT_translation.h" -#include "MEM_guardedalloc.h" +# include "ED_outliner.h" -#include "RNA_access.h" -#include "RNA_define.h" +# include "MEM_guardedalloc.h" -#include "UI_interface.h" -#include "UI_resources.h" +# include "RNA_access.h" +# include "RNA_define.h" -#include "WM_api.h" -#include "WM_types.h" +# include "UI_interface.h" +# include "UI_resources.h" -#include "DEG_depsgraph.h" +# include "WM_api.h" +# include "WM_types.h" -#include "IO_orientation.h" -#include "IO_path_util_types.h" -#include "IO_wavefront_obj.h" -#include "io_obj.h" +# include "DEG_depsgraph.h" + +# include "IO_orientation.h" +# include "IO_path_util_types.h" +# include "IO_wavefront_obj.h" +# include "io_obj.h" static const EnumPropertyItem io_obj_export_evaluation_mode[] = { {DAG_EVAL_RENDER, "DAG_EVAL_RENDER", 0, "Render", "Export objects as they appear in render"}, @@ -472,3 +474,5 @@ void WM_OT_obj_import(struct wmOperatorType *ot) prop = RNA_def_string(ot->srna, "filter_glob", "*.obj;*.mtl", 0, "Extension Filter", ""); RNA_def_property_flag(prop, PROP_HIDDEN); } + +#endif /* WITH_IO_WAVEFRONT_OBJ */ diff --git a/source/blender/editors/io/io_ops.c b/source/blender/editors/io/io_ops.c index 098186a75e3..0340d0598d5 100644 --- a/source/blender/editors/io/io_ops.c +++ b/source/blender/editors/io/io_ops.c @@ -42,14 +42,14 @@ void ED_operatortypes_io(void) WM_operatortype_append(WM_OT_usd_export); #endif +#ifdef WITH_IO_GPENCIL WM_operatortype_append(WM_OT_gpencil_import_svg); - -#ifdef WITH_PUGIXML +# ifdef WITH_PUGIXML WM_operatortype_append(WM_OT_gpencil_export_svg); -#endif - -#ifdef WITH_HARU +# endif +# ifdef WITH_HARU WM_operatortype_append(WM_OT_gpencil_export_pdf); +# endif #endif WM_operatortype_append(CACHEFILE_OT_open); @@ -59,8 +59,12 @@ void ED_operatortypes_io(void) WM_operatortype_append(CACHEFILE_OT_layer_remove); WM_operatortype_append(CACHEFILE_OT_layer_move); +#ifdef WITH_IO_WAVEFRONT_OBJ WM_operatortype_append(WM_OT_obj_export); WM_operatortype_append(WM_OT_obj_import); +#endif +#ifdef WITH_IO_STL WM_operatortype_append(WM_OT_stl_import); +#endif } diff --git a/source/blender/editors/io/io_stl_ops.c b/source/blender/editors/io/io_stl_ops.c index d5993bc4f37..7db32cd6f18 100644 --- a/source/blender/editors/io/io_stl_ops.c +++ b/source/blender/editors/io/io_stl_ops.c @@ -4,21 +4,23 @@ * \ingroup editor/io */ -#include "BKE_context.h" -#include "BKE_report.h" +#ifdef WITH_IO_STL -#include "WM_api.h" -#include "WM_types.h" +# include "BKE_context.h" +# include "BKE_report.h" -#include "DNA_space_types.h" +# include "WM_api.h" +# include "WM_types.h" -#include "ED_outliner.h" +# include "DNA_space_types.h" -#include "RNA_access.h" -#include "RNA_define.h" +# include "ED_outliner.h" -#include "IO_stl.h" -#include "io_stl_ops.h" +# include "RNA_access.h" +# include "RNA_define.h" + +# include "IO_stl.h" +# include "io_stl_ops.h" static int wm_stl_import_invoke(bContext *C, wmOperator *op, const wmEvent *event) { @@ -127,3 +129,5 @@ void WM_OT_stl_import(struct wmOperatorType *ot) prop = RNA_def_string(ot->srna, "filter_glob", "*.stl", 0, "Extension Filter", ""); RNA_def_property_flag(prop, PROP_HIDDEN); } + +#endif /* WITH_IO_STL */ diff --git a/source/blender/io/CMakeLists.txt b/source/blender/io/CMakeLists.txt index a376ee99d77..8b20b50a181 100644 --- a/source/blender/io/CMakeLists.txt +++ b/source/blender/io/CMakeLists.txt @@ -1,9 +1,21 @@ # SPDX-License-Identifier: GPL-2.0-or-later # Copyright 2020 Blender Foundation. All rights reserved. -add_subdirectory(common) -add_subdirectory(wavefront_obj) -add_subdirectory(stl) +if(WITH_IO_WAVEFRONT_OBJ OR WITH_IO_STL OR WITH_IO_GPENCIL OR WITH_ALEMBIC OR WITH_USD) + add_subdirectory(common) +endif() + +if(WITH_IO_WAVEFRONT_OBJ) + add_subdirectory(wavefront_obj) +endif() + +if(WITH_IO_STL) + add_subdirectory(stl) +endif() + +if(WITH_IO_GPENCIL) + add_subdirectory(gpencil) +endif() if(WITH_ALEMBIC) add_subdirectory(alembic) @@ -20,5 +32,3 @@ endif() if(WITH_USD) add_subdirectory(usd) endif() - -add_subdirectory(gpencil) diff --git a/source/blender/python/intern/CMakeLists.txt b/source/blender/python/intern/CMakeLists.txt index 8179daa8e03..71138134370 100644 --- a/source/blender/python/intern/CMakeLists.txt +++ b/source/blender/python/intern/CMakeLists.txt @@ -310,6 +310,18 @@ if(WITH_OPENCOLLADA) add_definitions(-DWITH_COLLADA) endif() +if(WITH_IO_WAVEFRONT_OBJ) + add_definitions(-DWITH_IO_WAVEFRONT_OBJ) +endif() + +if(WITH_IO_STL) + add_definitions(-DWITH_IO_STL) +endif() + +if(WITH_IO_GPENCIL) + add_definitions(-DWITH_IO_GPENCIL) +endif() + if(WITH_ALEMBIC) add_definitions(-DWITH_ALEMBIC) endif() diff --git a/source/blender/python/intern/bpy_app_build_options.c b/source/blender/python/intern/bpy_app_build_options.c index beb78753406..fe5111c37f2 100644 --- a/source/blender/python/intern/bpy_app_build_options.c +++ b/source/blender/python/intern/bpy_app_build_options.c @@ -43,6 +43,9 @@ static PyStructSequence_Field app_builtopts_info_fields[] = { {"mod_oceansim", NULL}, {"mod_remesh", NULL}, {"collada", NULL}, + {"io_wavefront_obj", NULL}, + {"io_stl", NULL}, + {"io_gpencil", NULL}, {"opencolorio", NULL}, {"openmp", NULL}, {"openvdb", NULL}, @@ -251,6 +254,24 @@ static PyObject *make_builtopts_info(void) SetObjIncref(Py_False); #endif +#ifdef WITH_IO_WAVEFRONT_OBJ + SetObjIncref(Py_True); +#else + SetObjIncref(Py_False); +#endif + +#ifdef WITH_IO_STL + SetObjIncref(Py_True); +#else + SetObjIncref(Py_False); +#endif + +#ifdef WITH_IO_GPENCIL + SetObjIncref(Py_True); +#else + SetObjIncref(Py_False); +#endif + #ifdef WITH_OCIO SetObjIncref(Py_True); #else -- cgit v1.2.3