我正在尝试重用CMakeLists.txt
我不想更改其来源的第三方项目(确切地说是expat )。我已将项目添加为顶层的子项目,使用add_subdirectory
.
这可行,但现在我想option
在顶层设置一些子项目的值CMakeLists.txt
。我该怎么做呢?
如果子项目使用option
(not set
) 作为其配置设置,那么您可以option
在添加子目录之前使用指定值:
option(LIB_OPTION1 "" OFF)
option(LIB_OPTION2 "" ON)
add_subdirectory(${CMAKE_SOURCE_DIRECTORY}/lib)
在调用之前,您可以使用所需的设置(ON 或 OFF)定义选项ADD_SUBDIRECTORY
。这将优先OPTION
于 expat 中的命令,CMakeLists.txt
因为最后一个参数 toOPTION
只是一个默认值(如果该设置已经存在,则忽略该值)。
SET 命令具有“PARENT_SCOPE”选项:
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.
(见:http ://www.cmake.org/cmake/help/v2.8.10/cmake.html#command:set )