[c++] Getting Started - CMake
CMake is an open-source cross platform build system, according to CMake's creator, Kitware.
But CMake is not actually a build system. What CMake provides is an easy way to build C/C++ projects accross platform. CMake generates a cofiguration for your existing compiler system, e.g. make. CMake focus on cross platform configuration, dependecies, testing, packing, installation.
CMake also includes tools for finding libraries, e.g. boost. That make it simpler to build project that have external dependencites and by using the tools rather than hard coding paths.
Included with CMake is CTest, a test deriver program. That make it easy to run a project's test program and/or scripts.
Once you have configured your project to be installed, you can also package your project using the included CPack utility. A varity of packages can be created including tar files, zip files or an installer.
Example 1
CMakeLists.txt
# cmake_minimum_requried(VERSION version [FATAL_ERROR])
cmake_minimum_required(VERSION 2.8 FATAL_ERROR) # project(name)
project("To Do List") # add_executable(target sources...)
add_executable(toDo main.cc ToDo.cc)
you may notice that header files are not listed. CMake handles dependencies automatically, so headers dont' need to be listed
main.cc
cmake_minimum_required should be used in all top level CMakeLists.txt. If you are not sure which version to use, then use the version of CMake you have installed
#include "ToDo.h"
int main(int argc, char** argv){
ToDo list;
return ;
}
ToDo.h
#ifndef TODO_H
#define TODO_H class ToDo{
public:
ToDo();
~ToDo();
}; #endif // TODO_H
ToDo.cc
#include "ToDo.h"
ToDo::ToDo() { }
ToDo::~ToDo() { }
CMake's documentation suggest that out-of-source build be done rather than in-source build, so that we can clear build by simply delete the build folder.
> cd <project root directory>
> mkdir build
> cd build
> cmake -G "Unix Makefiles" .. # cmake -G <generator name> <path to soruce>
> ls
CMakeCache.txt CMakeFiles Makefile cmake_install.cmake
> make
The path of <path to source> contains your top level CMakeLists.txt.
cmake command generates serveral files, which should not be edited by hands.
- Makefile is the most important one to us as we use it to build our projeect
- CMakeCache.txt is important to CMake as it stores a varity of information and settings for the project.
Run make to build our target executable, based on the generated Makefile. Makefile suppress standard output. We may output detail by using:
> make VERBOSE=
If you modified the files you had used before, you simply need to run make again. The Makefile generated by CMake will automatically run cmake again if you modified your CMakeListx.txt.
Reference:
CMake Tutorial – Chapter 1: Getting Started, JohnLamp.net
[c++] Getting Started - CMake的更多相关文章
- 使用cmake自动构建工程
公司引擎是用cmake根据目标平台来构建工程的,刚接触的时候深深体会到cmake的方便:如果目标平台是windows,它可以帮你自动构建出vs工程:如果是安卓,自动构建出eclipse工程,如果是IO ...
- CMake
使用CMake编译跨平台静态库 http://www.tuicool.com/articles/3uu2Yj cmake命令 安装.用法简介 https://fukun.org/archives/04 ...
- CMake学习笔记
C++开发者必备技能CMake 先简单介绍一下,CMake是一个跨平台的编译工具,它可以根据不用的平台,不同的编译环境,生成不同的MakeFile,从而控制编译的过程. 使用CMake的步骤: 1. ...
- VS 2013编译64位版本QT 4.8.6及使用cmake为依赖QT生成VS项目时Could NOT find Qt4
对于一些已经解决的问题,本博客不再讨论.只将本人遇到的问题做简单的说明. 一.VS 2013编译64位版本QT 4.8.6 QT项目官网中,对于QT4,其只提供了windows X86的版本,并且支持 ...
- cmake cannot find package
cmake 找不到package,如 find_package (OpenMesh REQUIRED) 出现错误 在项目的文件夹中找到 FindOpenMesh.cmake 文件,将其所在路径添加到 ...
- Cmake的交叉编译
http://www.cmake.org/Wiki/CMake_Cross_Compiling
- CMake命令/函数汇总(翻译自官方手册)
查看官方文档 cmake命令 选项 CMake变量 CMake命令汇总 / add_custom_command add_custom_target/add_definitions/add_depen ...
- 《CMake实践》笔记一:PROJECT/MESSAGE/ADD_EXECUTABLE
<CMake实践>笔记一:PROJECT/MESSAGE/ADD_EXECUTABLE <CMake实践>笔记二:INSTALL/CMAKE_INSTALL_PREFIX &l ...
- 《CMake实践》笔记二:INSTALL/CMAKE_INSTALL_PREFIX
<CMake实践>笔记一:PROJECT/MESSAGE/ADD_EXECUTABLE <CMake实践>笔记二:INSTALL/CMAKE_INSTALL_PREFIX &l ...
- 《CMake实践》笔记三:构建静态库(.a) 与 动态库(.so) 及 如何使用外部共享库和头文件
<CMake实践>笔记一:PROJECT/MESSAGE/ADD_EXECUTABLE <CMake实践>笔记二:INSTALL/CMAKE_INSTALL_PREFIX &l ...
随机推荐
- 个人免签收款接口 bufpay.com 支持限额设置
有产品希望收款分布到不同的手机,每个当手机达到某一限额以后就停止改手机的收款. bufpay.com 近期上线了收款限额设置功能,配置界面如下图: 每个手机微信或支付宝可以单独设置每日限额,如果该手机 ...
- LeetCode 中级 - 优势洗牌(870)
给定两个大小相等的数组 A 和 B,A 相对于 B 的优势可以用满足 A[i] > B[i] 的索引 i 的数目来描述. 返回 A 的任意排列,使其相对于 B 的优势最大化. 示例 2: 输入: ...
- 字符编码ascii、unicode、utf-‐8、gbk 的关系
ASIIC码: 计算机是美国人发明和最早使用的,他们为了解决计算机处理字符串的问题,就将数字字母和一些常用的符号做成了一套编码,这个编码就是ASIIC码.ASIIC码包括数字大小写字母和常用符号,一共 ...
- ueditor 富文本编辑器 Uncaught TypeError: Cannot set property 'innerHTML' of undefined问题
ueditor.addListener("ready", function () { ueditor.setContent(‘内容'); });
- 大数据学习--day07(冒泡排序、Arrays工具类、方法可变参数)
冒泡排序.Arrays工具类.方法可变参数 冒泡排序之前写过,略 Arrays工具类 二分法查询 public static int binarySearch(int[] a,int key) 头信息 ...
- SQL盲注
一.首先输入1和-1 查看输入正确和不正确两种情况 二.三种注入POC LOW等级 ... where user_id =$id 输入 真 and 假 = 假 (1)...where u ...
- categorical[np.arange(n), y] = 1 IndexError: index 2 is out of bounds for axis 1 with size 2
我的错误的代码是:train_labels = np_utils.to_categorical(train_labels,num_classes = 3) 错误的原因: IndexError: ind ...
- BAPC 2014 Preliminary
// 题目链接: https://nanti.jisuanke.com/t/282041 //动态规划,重复利用子问题的最优,来求解当前最优问题 #include <iostream> # ...
- SpaceVim 发布 v0.8.0
This project exists thanks to all the people who have contributed. The last release v0.7.0 is target ...
- PHP实现识别带emoji表情的字符串
function have_special_char($str) { $length = mb_strlen($str); $array = []; for ($i=0; $i<$length; ...