From 70d5bb8c7b8e0767892326398f3bdec0e2f0c27b Mon Sep 17 00:00:00 2001 From: Alberto Taiuti Date: Sat, 12 Nov 2016 01:29:46 +0000 Subject: [PATCH] Make assimp build cherry-picked importers in CMake Modify assimp's cmake to exclude the build of all the importers by default; the user has then to manually select the ones needed by setting the relative option. From the explanation as written in the CMakeLists itself: --- This option allows to select whether to build all the importers and then manually select which ones not to build (old behaviour), or if to exclude all importers from build and manually select the ones to actually build. By default, exclude all importers and manually select which ones to use. To have all importers excluded, simply do not set this option in the parent CmakeLists. Then, set the option for the importer(s) needed in the parent CMakeLists, e.g.: OPTION(ASSIMP_BUILD_OBJ_IMPORTER "" TRUE) To have assimp build all the importers, set the option to true, then manually exclude which importers you don't need, e.g.: OPTION(ASSIMP_BUILD_OBJ_IMPORTER "" FALSE) NOTE: In order to use this method of exclusion, the tools build must be disabled; their code references certain importers/exporters which would be excluded. If you need the tools, either manually add the importers/exporters the code references (you will see linkage errors), or just enable the build of all the importers as explained above. --- As mentioned there, set the main CMakeLists not to build the tools and the tests by default, since they use certain exporters and importers which, with this method, are not necessarily used/built. --- CMakeLists.txt | 4 +-- code/CMakeLists.txt | 71 ++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 58 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a08aa39..a8936b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,7 +66,7 @@ OPTION( ASSIMP_BUILD_ZLIB ) option( ASSIMP_BUILD_ASSIMP_TOOLS "If the supplementary tools for Assimp are built in addition to the library." - ON + OFF ) option ( ASSIMP_BUILD_SAMPLES "If the official samples are built as well (needs Glut)." @@ -74,7 +74,7 @@ option ( ASSIMP_BUILD_SAMPLES ) OPTION ( ASSIMP_BUILD_TESTS "If the test suite for Assimp is built in addition to the library." - ON + OFF ) IF(MSVC) set (CMAKE_PREFIX_PATH "D:\\libs\\devil") diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index ac7002a..178c768 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -184,21 +184,62 @@ IF ( ASSIMP_BUILD_NONFREE_C4D_IMPORTER ) SOURCE_GROUP( C4D FILES ${C4D_SRCS}) ENDIF ( ASSIMP_BUILD_NONFREE_C4D_IMPORTER ) -# macro to add the CMake Option ADD_ASSIMP_IMPORTER_ which enables compile of loader -# this way selective loaders can be compiled (reduces filesize + compile time) -MACRO(ADD_ASSIMP_IMPORTER name) - OPTION(ASSIMP_BUILD_${name}_IMPORTER "build the ${name} importer" TRUE) - IF(ASSIMP_BUILD_${name}_IMPORTER) - LIST(APPEND ASSIMP_LOADER_SRCS ${ARGN}) - SET(ASSIMP_IMPORTERS_ENABLED "${ASSIMP_IMPORTERS_ENABLED} ${name}") - SET(${name}_SRCS ${ARGN}) - SOURCE_GROUP(${name} FILES ${ARGN}) - ELSE() - SET(${name}_SRC "") - SET(ASSIMP_IMPORTERS_DISABLED "${ASSIMP_IMPORTERS_DISABLED} ${name}") - add_definitions(-DASSIMP_BUILD_NO_${name}_IMPORTER) - ENDIF() -ENDMACRO() +# This option allows to select whether to build all the importers and then +# manually select which ones not to build (old behaviour), or if to +# exclude all importers from build and manually select the ones to actually +# build. +# By default, exclude all importers and manually select which ones to use. +# +# To have all importers excluded, simply do not set this option in the parent +# CmakeLists. Then, set the option for the importer(s) needed in the parent +# CMakeLists, e.g.: +# OPTION(ASSIMP_BUILD_OBJ_IMPORTER "" TRUE) +# +# To have assimp build all the importers, set the option to true, then manually +# exclude which importers you don't need, e.g.: +# OPTION(ASSIMP_BUILD_OBJ_IMPORTER "" FALSE) +# +# NOTE: In order to use this method of exclusion, the tools build must be disabled; +# their code references certain importers/exporters which would be excluded. +# If you need the tools, either manually add the importers/exporters the code +# references (you will see linkage errors), or just enable the build of all the +# importers as explained above. +OPTION(ASSIMP_BUILD_ALL_AND_EXCLUDE "Build all importers and select which ones + to not build" FALSE) +IF(ASSIMP_BUILD_ALL_AND_EXCLUDE) + # macro to add the CMake Option ADD_ASSIMP_IMPORTER_ which enables compile of loader + # this way selective loaders can be compiled (reduces filesize + compile time) + MACRO(ADD_ASSIMP_IMPORTER name) + OPTION(ASSIMP_BUILD_${name}_IMPORTER "build the ${name} importer" TRUE) + IF(ASSIMP_BUILD_${name}_IMPORTER) + LIST(APPEND ASSIMP_LOADER_SRCS ${ARGN}) + SET(ASSIMP_IMPORTERS_ENABLED "${ASSIMP_IMPORTERS_ENABLED} ${name}") + SET(${name}_SRCS ${ARGN}) + SOURCE_GROUP(${name} FILES ${ARGN}) + ELSE() + SET(${name}_SRC "") + SET(ASSIMP_IMPORTERS_DISABLED "${ASSIMP_IMPORTERS_DISABLED} ${name}") + add_definitions(-DASSIMP_BUILD_NO_${name}_IMPORTER) + ENDIF() + ENDMACRO() +ELSE(ASSIMP_BUILD_ALL_AND_EXCLUDE) + MACRO(ADD_ASSIMP_IMPORTER name) + OPTION(ASSIMP_BUILD_${name}_IMPORTER "build the ${name} importer" FALSE) + MESSAGE(STATUS "Setting false for ${name}") + IF(ASSIMP_BUILD_${name}_IMPORTER) + LIST(APPEND ASSIMP_LOADER_SRCS ${ARGN}) + SET(ASSIMP_IMPORTERS_ENABLED "${ASSIMP_IMPORTERS_ENABLED} ${name}") + SET(${name}_SRCS ${ARGN}) + SOURCE_GROUP(${name} FILES ${ARGN}) + MESSAGE(STATUS "Setting true for ${name}") + ELSE() + SET(${name}_SRC "") + SET(ASSIMP_IMPORTERS_DISABLED "${ASSIMP_IMPORTERS_DISABLED} ${name}") + add_definitions(-DASSIMP_BUILD_NO_${name}_IMPORTER) + MESSAGE(STATUS "Setting false for ${name}") + ENDIF() + ENDMACRO() +ENDIF(ASSIMP_BUILD_ALL_AND_EXCLUDE) SET(ASSIMP_LOADER_SRCS "") SET(ASSIMP_IMPORTERS_ENABLED "") # list of enabled importers -- 2.7.4