如何将项目特定变量传递到子目录?我想知道是否有"官方"方式这样做:
# (CMAKE_BUILD_TYPE is one of None, Debug, Release, RelWithDebInfo)
# ...
# set specific build type for 'my_library'
set( CMAKE_BUILD_TYPE_COPY "${CMAKE_BUILD_TYPE}" )
set( CMAKE_BUILD_TYPE "Release" )
add_subdirectory( "my_library" )
set( CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE_COPY} )
# continue with original build type
# ...
Run Code Online (Sandbox Code Playgroud)
库/子目录my_library应始终为buildt类型"Release",主项目和其他子目录应该是buildt,其类型由配置定义.我不能修改CMakeLists.txt的my_library.
在评论中回答修改后的问题(如何传递不同的值),所以除了CMAKE_BUILD_TYPE`之外的其他值:
这没有额外的机器.如果变量是项目特定的,则只需设置变量:
set(MYLIB_SOME_OPTION OFF)
add_subdirectory(mylib)
Run Code Online (Sandbox Code Playgroud)
如果它更通用,你需要还原它:
set(BUILD_SHARED_LIBS_SAVED "${BUILD_SHARED_LIBS}")
set(BUILD_SHARED_LIBS OFF)
add_subdirectory(mylib)
set(BUILD_SHARED_LIBS "${BUILD_SHARED_LIBS_SAVED}")
Run Code Online (Sandbox Code Playgroud)
或者你可以把它放到一个函数中,你不需要恢复你改变的变量,因为函数有一个范围.
| 归档时间: |
|
| 查看次数: |
4487 次 |
| 最近记录: |