cmake option的使用

cmake 编译选项管理:
在工程的根目录,编写CMakeLists.txt, 另外创建一个独立的option.txt,专门管理编译选项,语法如下:

在CMakeLists.txt中加如下语句
include option.txt

在option.txt中添加以下语句

/*USE_MYMATH 为编译开关,中间的字符串为描述信息,ON/OFF 为默认选项*/
option (USE_MYMATH 
        "Use tutorial provided math implementation" ON) 
              
在编译之前,执行ccmake .就会弹出cmake GUI,进行配置所有的编译开关,配置结束后会生成一个CMakeCache.txt,配置后的编译选择保存在这个文件中。


/*看完整的make 信息*/
make VERBOSE=1


以下参考:http://www.cmake.org/cmake/help/cmake_tutorial.html

Now let us consider making the MathFunctions library optional. In this tutorial there really isn’t any reason to do so, but with larger libraries or libraries that rely on third party code you might want to. The first step is to add an option to the top level CMakeLists file.

# should we use our own math functions?
option (USE_MYMATH 
        "Use tutorial provided math implementation" ON) 

This will show up in the CMake GUI with a default value of ON that the user can change as desired. This setting will be stored in the cache so that the user does not need to keep setting it each time they run CMake on this project. The next change is to make the build and linking of the MathFunctions library conditional. To do this we change the end of the top level CMakeLists file to look like the following:

# add the MathFunctions library?
#
if (USE_MYMATH)
  include_directories ("${PROJECT_SOURCE_DIR}/MathFunctions")
  add_subdirectory (MathFunctions)
  set (EXTRA_LIBS ${EXTRA_LIBS} MathFunctions)
endif (USE_MYMATH)
 
# add the executable
add_executable (Tutorial tutorial.cxx)
target_link_libraries (Tutorial  ${EXTRA_LIBS})
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值