当前位置: 移动技术网 > IT编程>开发语言>C/C++ > 一个简单的cmake例子

一个简单的cmake例子

2019年03月20日  | 移动技术网IT编程  | 我要评论

娱乐114,重生之竹马vs竹马,天命神童国语版

一个简单的cmake例子cmakelists.txt,生成动态库文件,可以指定发布目录。
尚不支持:
  1、交叉编译环境配置
  2、添加依赖库
 
 1 #在当前目录新建一个build目录,然后cd build;cmake ..
 2 #这样的好处是,可以将cmake生成的内容,和源码文件分离
 3  
 4 #定义好版本需求
 5 cmake_minimum_required (version 2.6)
 6 #工程名字
 7 project (libtree)
 8 #编译结果发布路径
 9 set ( cmake_install_prefix ./_install)
10  
11 ## the version number.
12 set (tutorial_version_major 1)
13 set (tutorial_version_minor 0)
14  
15 #设置源码文件,分别是avl.c rb.c splay.c
16 set (libhello_src avl.c rb.c splay.c)
17  
18 #动态库
19 add_library (tree shared ${libhello_src})
20 #静态库
21 add_library (tree_static static ${libhello_src})
22  
23 set_target_properties (tree_static properties output_name "tree")
24 get_target_property (output_value tree_static output_name)
25 message (status "this is the tree_static output_name: " ${output_value})
26  
27 # cmake在构建一个新的target时,会尝试清理掉其他使用这个名字的库,
28 # 因此,在构建libtree.a时,就会清理掉libtree.so.
29 # 为了回避这个问题,比如再次使用set_target_properties定义 clean_direct_output属性。
30 set_target_properties (tree_static properties clean_direct_output 1)
31 set_target_properties (tree properties clean_direct_output 1)
32  
33 # 按照规则,动态库是应该包含一个版本号的,
34 # version指代动态库版本,soversion指代api版本。
35 set_target_properties (tree properties version ${tutorial_version_major}.${tutorial_version_minor} soversion 1)
36  38 #在本例中我们将tree的共享库安装到<prefix>/lib目录;
39 # 将libtree.h安装<prefix>/include/tree目录。
40  
41 install (targets tree tree_static library destination lib archive destination lib)
42 install (files libtree.h destination include/tree)

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网