目录
环境
ubuntu18
cmake version 3.17.3
准备文件
新建一个文件夹demo1,新建两个文件:CMakeLists.txt、helloworld.c
parallels@Lincoln:~/workspace/cmakedemo/demo1$ pwd
/home/parallels/workspace/cmakedemo/demo1
parallels@Lincoln:~/workspace/cmakedemo/demo1$ tree
.
├── CMakeLists.txt
└── helloworld.c
helloworld.c文件源码如下:
#include <stdio.h>
int main() {
printf("hello world\n");
return 0;
}
CMakeLists.txt:cmake的配置文件
#设置cmake的最小版本要求
cmake_minimum_required(VERSION 3.10)
#设置工程名字为 ylk_hello
project(ylk_hello)
#使用helloworld.c生成可执行程序hello
add_executable(hello helloworld.c)
使用cmake
1、生成配置
cmake . 其中 . 表示在当前目录搜索CMakeLists.txt(上面创建的)
parallels@Lincoln:~/workspace/cmakedemo/demo1$ cmake .
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX co