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.
pull/1064/head
Alberto Taiuti 2016-11-12 01:29:46 +00:00
parent fdd01bda83
commit 70d5bb8c7b
2 changed files with 58 additions and 17 deletions

View File

@ -66,7 +66,7 @@ OPTION( ASSIMP_BUILD_ZLIB
) )
option( ASSIMP_BUILD_ASSIMP_TOOLS option( ASSIMP_BUILD_ASSIMP_TOOLS
"If the supplementary tools for Assimp are built in addition to the library." "If the supplementary tools for Assimp are built in addition to the library."
ON OFF
) )
option ( ASSIMP_BUILD_SAMPLES option ( ASSIMP_BUILD_SAMPLES
"If the official samples are built as well (needs Glut)." "If the official samples are built as well (needs Glut)."
@ -74,7 +74,7 @@ option ( ASSIMP_BUILD_SAMPLES
) )
OPTION ( ASSIMP_BUILD_TESTS OPTION ( ASSIMP_BUILD_TESTS
"If the test suite for Assimp is built in addition to the library." "If the test suite for Assimp is built in addition to the library."
ON OFF
) )
IF(MSVC) IF(MSVC)
set (CMAKE_PREFIX_PATH "D:\\libs\\devil") set (CMAKE_PREFIX_PATH "D:\\libs\\devil")

View File

@ -184,21 +184,62 @@ IF ( ASSIMP_BUILD_NONFREE_C4D_IMPORTER )
SOURCE_GROUP( C4D FILES ${C4D_SRCS}) SOURCE_GROUP( C4D FILES ${C4D_SRCS})
ENDIF ( ASSIMP_BUILD_NONFREE_C4D_IMPORTER ) ENDIF ( ASSIMP_BUILD_NONFREE_C4D_IMPORTER )
# macro to add the CMake Option ADD_ASSIMP_IMPORTER_<name> which enables compile of loader # This option allows to select whether to build all the importers and then
# this way selective loaders can be compiled (reduces filesize + compile time) # manually select which ones not to build (old behaviour), or if to
MACRO(ADD_ASSIMP_IMPORTER name) # exclude all importers from build and manually select the ones to actually
OPTION(ASSIMP_BUILD_${name}_IMPORTER "build the ${name} importer" TRUE) # build.
IF(ASSIMP_BUILD_${name}_IMPORTER) # By default, exclude all importers and manually select which ones to use.
LIST(APPEND ASSIMP_LOADER_SRCS ${ARGN}) #
SET(ASSIMP_IMPORTERS_ENABLED "${ASSIMP_IMPORTERS_ENABLED} ${name}") # To have all importers excluded, simply do not set this option in the parent
SET(${name}_SRCS ${ARGN}) # CmakeLists. Then, set the option for the importer(s) needed in the parent
SOURCE_GROUP(${name} FILES ${ARGN}) # CMakeLists, e.g.:
ELSE() # OPTION(ASSIMP_BUILD_OBJ_IMPORTER "" TRUE)
SET(${name}_SRC "") #
SET(ASSIMP_IMPORTERS_DISABLED "${ASSIMP_IMPORTERS_DISABLED} ${name}") # To have assimp build all the importers, set the option to true, then manually
add_definitions(-DASSIMP_BUILD_NO_${name}_IMPORTER) # exclude which importers you don't need, e.g.:
ENDIF() # OPTION(ASSIMP_BUILD_OBJ_IMPORTER "" FALSE)
ENDMACRO() #
# 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_<name> 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_LOADER_SRCS "")
SET(ASSIMP_IMPORTERS_ENABLED "") # list of enabled importers SET(ASSIMP_IMPORTERS_ENABLED "") # list of enabled importers