说简单点,CMake 就是为我们生成 makefile 文件的,你是否在为撰写makefile而头疼呢,那就试试CMake吧,我也是一边学习,一边做一些笔记,难免会有一些理解错误的地方,还望各位看客及时指出,Thanks.
2:从“Hello world”开始
- [onezeroone@ ex-1]$ pwd
-
/home/onezeroone/work/backup/cmake/ex-1
-
[onezeroone@ ex-1]$ ls
- hello.c
- #include <stdio.h>
-
int
-
main(void)
-
{
-
printf("Hello world\n");
-
-
return 0;
- }
- [onezeroone@ ex-1]$ ls
-
CMakeLists.txt hello.c
-
[onezeroone@ ex-1]$ cat CMakeLists.txt
-
PROJECT(HELLO)
- ADD_EXECUTABLE(hello hello.c)
PROJECT语法:
PROJECT(projectname [CXX] [C] [JAVA])
用于指定工程名字,[]为可选内容,默认表示支持所有语言。
ADD_EXECUTABLE(hello hello.c)
定义工程生产的可执行文件名为hello, 源文件为hello.c
4:执行cmake .
- [onezeroone@ ex-1]$ cmake .
-
-- The C compiler identification is GNU
-
-- The CXX compiler identification is GNU
-
-- Check for working C compiler: /usr/bin/gcc
-
-- Check for working C compiler: /usr/bin/gcc -- works
-
-- Detecting C compiler ABI info
-
-- Detecting C compiler ABI info - done
-
-- Check for working CXX compiler: /usr/bin/c++
-
-- Check for working CXX compiler: /usr/bin/c++ -- works
-
-- Detecting CXX compiler ABI info
-
-- Detecting CXX compiler ABI info - done
-
-- Configuring done
-
-- Generating done
- -- Build files have been written to: /home/onezeroone/work/backup/cmake/ex-1
- [onezeroone@ ex-1]$ ls
- CMakeCache.txt CMakeFiles cmake_install.cmake CMakeLists.txt hello.c Makefile
5.make
- [onezeroone@ ex-1]$ make
-
Scanning dependencies of target hello
-
[100%] Building C object CMakeFiles/hello.dir/hello.c.o
-
Linking C executable hello
- [100%] Built target hello
- [onezeroone@ ex-1]$ ls
-
CMakeCache.txt CMakeFiles cmake_install.cmake CMakeLists.txt hello hello.c Makefile
-
[onezeroone@ ex-1]$ ./hello
- Hello world