github: https://github.com/ZhouHanyu18/cmake
一、最简单的cmake实现demo0
1. 添加源文件main.cpp
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(int argc, char* argv[]) {
if (argc < 2) {
printf("please input %s number: \n", argv[0]);
return 1;
}
double input = atof(argv[1]);
double out = sqrt(input);
printf("%f sqrt is %f\n", input, out);
return 0;
}
2. 编写CMakeLists.txt
# cmake 最低版本要求
cmake_minimum_required (VERSION 2.8)
# 项目名称
project (Main)
# 指定生成目标
add_executable(main main/main.cpp)
3. 新建build目录文件,执行cmake .. && make
4. 运行./main 10
参考链接:https://blog.csdn.net/lwljava/article/details/38517193?utm_medium=distribute.pc_relevant.none-task-blog-OPENSEARCH-1&depth_1-utm_source=distribute.pc_relevant.none-task-blog-OPENSEARCH-1