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)

猜你喜欢

转载自www.cnblogs.com/njit-sam/p/12660176.html