自动make工具--CMake
2016-09-25 15:39
204 查看
http://www.cnblogs.com/lyq105/archive/2010/12/03/1895067.html
http://www.linuxidc.com/Linux/2015-10/124447.htm
CMake是一个跨平台的安装(编译)工具,可以用简单的语句来描述所有平台的安装(编译过程)。他能够输出各种各样的makefile或者project文件,能测试编译器所支持的C++特性,类似UNIX下的automake。只是 CMake 的组态档取名为 CmakeLists.txt。Cmake 并不直接建构出最终的软件,而是产生标准的建构档(如 Unix 的 Makefile 或 Windows Visual C++ 的 projects/workspaces),然后再依一般的建构方式使用。这使得熟悉某个集成开发环境(IDE)的开发者可以用标准的方式建构他的软件,这种可以使用各平台的原生建构系统的能力是 CMake 和 SCons 等其他类似系统的区别之处。
CMake 可以编译源代码、制作程式库、产生适配器(wrapper)、还可以用任意的顺序建构执行档。CMake 支持 in-place 建构(二进档和源代码在同一个目录树中)和 out-of-place 建构(二进档在别的目录里),因此可以很容易从同一个源代码目录树中建构出多个二进档。CMake 也支持静态与动态程式库的建构。
“CMake”这个名字是“cross platform make”的缩写。虽然名字中含有“make”,但是CMake和Unix上常见的“make”系统是分开的,而且更为高阶。
cmake应用
cmake使用除了应用程序外,就是编写CMakeLists.txt文档,以生成Makefile文件。
1. 每个目录下都需要文件CmakeLists.txt文件,CmakeLists.txt的编写需遵循cmake语法。
2. 最好在根目录下,创建build文件夹,让后进入build文件夹构建工程,这样构建工程的中间文件及最后文件都在build中,直接发布build文件即可。
3. 构建命令cd build; cmake ..; make;
注:cmake后的..是上层目录意思。
4. 生成可执行程序,运行即可。
一个最简单示例
//hello.c
#include <stdio.h>
int main()
{
printf("Hello World!\n");
return 0;
}
//CmakeLists.txt
PROJECT(HELLO)
SET(SRC_LIST hello.c)
ADD_EXECUTABLE(hello ${SRC_LIST})
流程:
~$pwd
/home/yuxi/test/cmake/build
~$ls
~$ls ..
build CMakeLists.txt hello.c
~$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/yuxi/test/cmake/build
~$ls
CMakeCache.txt CMakeFiles cmake_install.cmake Makefile
~$make
Scanning dependencies of target hello
[100%] Building C object CMakeFiles/hello.dir/hello.c.o
Linking C executable hello
[100%] Built target hello
~$ls
CMakeCache.txt CMakeFiles cmake_install.cmake hello Makefile
~$./hello
Hello World!
~$ls CMakeFiles/
CMakeCCompiler.cmake CMakeOutput.log Makefile2
cmake.check_cache CMakeSystem.cmake Makefile.cmake
CMakeCXXCompiler.cmake CMakeTmp progress.marks
CMakeDetermineCompilerABI_C.bin CompilerIdC TargetDirectories.txt
CMakeDetermineCompilerABI_CXX.bin CompilerIdCXX
CMakeDirectoryInformation.cmake hello.dir
http://www.linuxidc.com/Linux/2015-10/124447.htm
CMake是一个跨平台的安装(编译)工具,可以用简单的语句来描述所有平台的安装(编译过程)。他能够输出各种各样的makefile或者project文件,能测试编译器所支持的C++特性,类似UNIX下的automake。只是 CMake 的组态档取名为 CmakeLists.txt。Cmake 并不直接建构出最终的软件,而是产生标准的建构档(如 Unix 的 Makefile 或 Windows Visual C++ 的 projects/workspaces),然后再依一般的建构方式使用。这使得熟悉某个集成开发环境(IDE)的开发者可以用标准的方式建构他的软件,这种可以使用各平台的原生建构系统的能力是 CMake 和 SCons 等其他类似系统的区别之处。
CMake 可以编译源代码、制作程式库、产生适配器(wrapper)、还可以用任意的顺序建构执行档。CMake 支持 in-place 建构(二进档和源代码在同一个目录树中)和 out-of-place 建构(二进档在别的目录里),因此可以很容易从同一个源代码目录树中建构出多个二进档。CMake 也支持静态与动态程式库的建构。
“CMake”这个名字是“cross platform make”的缩写。虽然名字中含有“make”,但是CMake和Unix上常见的“make”系统是分开的,而且更为高阶。
cmake应用
cmake使用除了应用程序外,就是编写CMakeLists.txt文档,以生成Makefile文件。
1. 每个目录下都需要文件CmakeLists.txt文件,CmakeLists.txt的编写需遵循cmake语法。
2. 最好在根目录下,创建build文件夹,让后进入build文件夹构建工程,这样构建工程的中间文件及最后文件都在build中,直接发布build文件即可。
3. 构建命令cd build; cmake ..; make;
注:cmake后的..是上层目录意思。
4. 生成可执行程序,运行即可。
一个最简单示例
//hello.c
#include <stdio.h>
int main()
{
printf("Hello World!\n");
return 0;
}
//CmakeLists.txt
PROJECT(HELLO)
SET(SRC_LIST hello.c)
ADD_EXECUTABLE(hello ${SRC_LIST})
流程:
~$pwd
/home/yuxi/test/cmake/build
~$ls
~$ls ..
build CMakeLists.txt hello.c
~$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/yuxi/test/cmake/build
~$ls
CMakeCache.txt CMakeFiles cmake_install.cmake Makefile
~$make
Scanning dependencies of target hello
[100%] Building C object CMakeFiles/hello.dir/hello.c.o
Linking C executable hello
[100%] Built target hello
~$ls
CMakeCache.txt CMakeFiles cmake_install.cmake hello Makefile
~$./hello
Hello World!
~$ls CMakeFiles/
CMakeCCompiler.cmake CMakeOutput.log Makefile2
cmake.check_cache CMakeSystem.cmake Makefile.cmake
CMakeCXXCompiler.cmake CMakeTmp progress.marks
CMakeDetermineCompilerABI_C.bin CompilerIdC TargetDirectories.txt
CMakeDetermineCompilerABI_CXX.bin CompilerIdCXX
CMakeDirectoryInformation.cmake hello.dir
相关文章推荐
- 自动生成makefile的工具?GNU Automake;cmake;
- C/C++自动生成makefile工具 supermake
- 自动make工具--autotools
- (软件工具)转载:IDEA自动编译不用每次make
- 跨平台自动构建工具:xmake
- c++构建工具之shell,configure,make,cmake,scons,xmake简析总结
- linux下用CMake、make工具手动编译程序的步骤、方法
- 编译工具make、gmake、cmake、nmake和Dmake的区别
- Excel 小工具:列出所有的sheet,然后点击其中的一个,自动跳过去
- 自动编译工具及脚本编写
- 代码自动生成工具的补充
- 自动更换IP的辅助投票工具
- 自动设置IP小工具
- 可以把Access数据库自动转化成Sql的脚本编写工具
- Procedure Helper (Microsoft Sql Server Procedure 自动生成工具)
- 自动生成NHibernate配置文件工具的使用实例
- UpdateVersion:一个自动更新版本号的小工具[转]
- 关于自动投票工具软件的实现
- 自动生成JavaBean的轻量级小工具
- 开始写自动升级的工具