CMake-单个源文件

单个源文件的比较简单,直接在源文件的同一目录下编写CMakeLists.txt,然后执行cmake ..,之后会得到Makefile文件,直接make就能得可执行文件。

main.c

1 #include<stdio.h>
2 
3 int main()
4 {
5     printf("hello world");
6     return 0;
7 }

CMakeLists.txt

 1 # Set the minimum version of CMake that can be used
 2 # To find the cmake version run
 3 # $ cmake --version
 4 cmake_minimum_required(VERSION 2.8.12)
 5 
 6 # Set the project name
 7 project (hello)
 8 
 9 # Add an executable
10 add_executable(hello_cmake main.c)

 

posted @ 2020-04-08 15:22  njit-sam  阅读(286)  评论(0编辑  收藏  举报