博客地址:http://home.cnblogs.com/u/zengjianrong/

cmake资料汇总

CMake梳理依赖关系
梳理依赖关系的方法,通常是在cmake命令中追加参数graphviz,如cmake .. --graphviz=../target_deps_graphviz,用来生成每个目标的依赖dot文件,再结合dot命令,如dot -Tpng -o target.png ./target.dot生成类似下面的PNG图或者PDF文件,以梳理依赖关系,为裁剪库做准备和参考。
 
cmake扩展链接,包含find_package、ctest、cpack等:
https://github.com/wzpan/cmake-demo  中文demo 
https://github.com/ttroy50/cmake-examples  英文demo
https://github.com/Akagi201/learning-cmake  带了pdf文档
https://github.com/BrightXiaoHan/CMakeTutorial 带了cuda cmake用法,以及用C++编写python自定义类型的例子
https://github.com/chaneyzorn/CMake-tutorial
 
 
cmake_policy的作用:用于使能或关闭某个特性。当你发现同样的环境,两个cmake的表现不一致,那么需要留意双方的cmake_minimum_required的版本配置和cmake_polcy配置。
比如 使能了 CMP0074 后,find_* 支持在 *_ROOT 环境变量的路径下做查找。
常用的policy:
cmake_policy(SET CMP0028 NEW) # Double colon in target name means ALIAS or IMPORTED target.
cmake_policy(SET CMP0047 NEW) # Use QCC compiler id for the qcc drivers on QNX.
cmake_policy(SET CMP0048 NEW) # project() command manages VERSION variables.
cmake_policy(SET CMP0074 NEW) # CMP0074: find_package uses PackageName_ROOT variables.

 

 

ExternalProject_Add + add_dependencies:添加外部依赖repo,可参考:https://github.com/fraillt/cpp_serializers_benchmark
 
 

怎么才能同时生成 libhello-world.so 和 libhello-world.a 呢?

答案是:首先生成 libhello-world-static.a,然后使用 set_target_properties() 指令的 OUTPUT_NAME 参数,将 libhello-world-static.a 重命名为 libhello-world.a

    add_library(${ORIGINAL_STATIC_LIB_NAME} STATIC hello_world.c)
    set_target_properties(${ORIGINAL_STATIC_LIB_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME})

 

posted @ 2022-12-28 16:27  black_man  阅读(57)  评论(0编辑  收藏  举报