C++代码review问题<二>:CMakeLists编写的一些规范

  • add_definitions
    CMake文档描述

    Adds definitions to the compiler command line for targets in the current directory and below (whether added before or after this command is invoked)

    影响范围大( targets in the current directory and below ),会污染其他cmake文件。可以使用set_target_properties给编译目标添加编译选项
    比如增加编译选项-g, 编译出带符号的版本

    add_definitions("-Wall -g") // bad
    set_target_properties(log_example PROPERTIES COMPILE_FLAGS "-Wall -g") // good
    
  • 使用BUILD_SHARED_LIBS标记整个add_library属性
    CMake文档描述

    Global flag to cause add_library() to create shared libraries if on.

    If present and true, this will cause all libraries to be built shared unless the library was explicitly added as a static library. This variable is often added to projects as an option() so that each user of a project can decide if they want to build the project using shared or static libraries.

    若该目录下的生成库的属性统一,可以使用CMake全局FLAG

  • PRIVATE INTERFACE PUBLIC

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值