从网上下了一本书,官网上也是第一个推荐这本书,所以拿来学习cmake的编写规则。
百度网盘上有pdf
https://pan.baidu.com/s/1nviBFFb
第一章废话有点多,那就从第二章开始吧。
安装cmake二进制文件,官网下载
https://cmake.org/download/
百度网盘下载
https://pan.baidu.com/s/1mhIVsTy
readme中的安装三部曲,傻瓜式的安装
$ ./bootstrap && make && make install
可以最后要加sudo吧,因为默认是安装到/usr/local里面
下面进入正题,基本语法和使用规则
编译过程是通过CMakeLists.txt文件组织的,由一系列的命令组成,是以下的形式
command (args ...)
where command is the name of the command, and args is a white-space separated list of arguments.
(Arguments with embeded white-space should be double quoted)
Variables are referenced using a ${VAR} syntax.
变量使用${VAR}表示
Multi arguments can be grouped together into a list using the set command.
set (Foo a b c)
command(${Foo})
相当于 command(a b c)
只传递一个参数
command("${Foo}") 相当于 command("a b c")
System environment variables and Windows registry values can be access directly in CMake.
To access system environment variables the syntac $ENV{VAR} is used.
一个最简单的例子形式
project (Hello)
add_executable (Hello Hello.c)
图形操作界面是cmake-gui
直接下载
sudo apt-get install cmake-qt-gui
必须填写源码位置,和编译生成的位置,两者不相互影响,可以直接删除编译的位置。
运行cmake