欢迎光临散文网 会员登陆 & 注册

cmake2

2023-03-21 19:52 作者:米诺斯人  | 我要投稿

【install安装】

# Library

# Note: may not work on windows

install (TARGETS cmake_examples_inst

    LIBRARY DESTINATION lib)

安装xxxlib到/usr/local/lib


# Header files

install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/

    DESTINATION include)


# Config

install (FILES cmake-examples.conf

    DESTINATION etc)


as above. intsall(安装类型 安装的目标 DEXTINATION 安装位置 )    安装位置默认是/usr/local/xxx

————————————————————

【complie flags编译选项】

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DEX2 -xxx")

编译的时候相当于 gcc -DEX2 -xxx;CMAKE_CXX_FLAGS是个cmake默认的环境变量,默认empty;可以加-Werror -Wall 严谨模式。【这是较为古老的方式


target_compile_definitions(cmake_examples_compile_flags

    PRIVATE EX3

)

自动添加宏macro EX3;即在每个相关文件#define EX3;等同于gcc src.c -DEX3


target_compile_options(hello_lib PUBLIC -Werror -Wall)

自动添加编译选项 -Werror -Wall;等同于gcc src.c -Werror -Wall,把warning视作error


————————————————————————

【build type 构建版本类型(如debug、release)】

手动发布正式版本

cmake .. -DCMAKE_BUILD_TYPE=Release

当然不手动更好:(化简版)

if(NOT CMAKE_BUILD_TYPE)

    set(CMAKE_BUILD_TYPE Release)

endif()

如果你的cmake脚本没有碰过CMAKE_BUILD_TYPE那么默认设置为Release版本。

否则默认是Debug版本。即自动gcc -g

贴一下没化简的原版:if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) message("Setting build type to 'RelWithDebInfo' as none was specified.") set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE)



一些重要的版本控制环境变量】:

  • Release - Adds the -O3 -DNDEBUG flags to the compiler

  • Debug - Adds the -g flag

  • MinSizeRel - Adds -Os -DNDEBUG

  • RelWithDebInfo - Adds -O2 -g -DNDEBUG flags



cmake2的评论 (共 条)

分享到微博请遵守国家法律