As per this stackoverflow answer, it looks like subproject options may be global to the project itself. If that’s the case, then it is possible that a project with a number of subprojects may have option collisions.
If the above is indeed an issue, then may I suggest two additions to the add_subdirectory
command.
The first is to be able to specify multi-value default options in the add_subdirectory
command, for example as follows:
add_subdirectory(thirdparty/libsndfile
DEFAULT_OPTIONS
ENABLE_EXTERNAL_LIBS=OFF
ENABLE_MPEG=OFF
BUILD_TESTING=OFF
BUILD_PROGRAMS=OFF
BUILD_EXAMPLES=OFF
ENABLE_CPACK=OFF
ENABLE_BOW_DOCS=OFF
ENABLE_PACKAGE_CONFIG=OFF
INSTALL_PKGCONFIG_MODULE=OFF
)
The second suggestion is to add a single-value namespace option in add_subdirectory
, so extending the above example:
add_subdirectory(thirdparty/libsndfile
NAMESPACE SF
DEFAULT_OPTIONS
ENABLE_EXTERNAL_LIBS=OFF
ENABLE_MPEG=OFF
BUILD_TESTING=OFF
BUILD_PROGRAMS=OFF
BUILD_EXAMPLES=OFF
ENABLE_CPACK=OFF
ENABLE_BOW_DOCS=OFF
ENABLE_PACKAGE_CONFIG=OFF
INSTALL_PKGCONFIG_MODULE=OFF
)
If the above is implemented, then one could possibly specify an option at the configuration stage as follows: cmake .. -DSF::BUILD_TESTING=ON