Override option in CMake subproject

江枫思渺然 提交于 2019-11-30 11:26:57
ronkot

See the similar question with a good answer.

Answer in short:

SET(SOME_EXPAT_OPTION OFF CACHE BOOL "Use some expat option")
Drew Noakes

If the sub-project uses option (not set) for its configuration settings, then you can specify values using option before adding the subdirectory:

option(LIB_OPTION1 "" OFF)
option(LIB_OPTION2 "" ON)
add_subdirectory(${CMAKE_SOURCE_DIRECTORY}/lib)

You can define the options with the desired settings (ON or OFF) before calling ADD_SUBDIRECTORY. This will then take precedence over the OPTION commands in expat's CMakeLists.txt since the last parameter to OPTION is only a default value (which is neglected if that settings already exists).

The SET-command has the 'PARENT_SCOPE' option:

If PARENT_SCOPE is present, the variable will be set in the scope above the current
scope. Each new directory or function creates a new scope. This command will set the 
value of a variable into the parent directory or calling function (whichever is 
applicable to the case at hand). PARENT_SCOPE cannot be combined with CACHE.

(see: http://www.cmake.org/cmake/help/v2.8.10/cmake.html#command:set )

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!