1. sdsf(single direction single file)

  1.1  The directory tree

/*
./template
|
+--- build
|
+---main.cpp
|
+---CMakeLists.txt
*/

  1.2 Sources code

 //  main.cpp

 #include <iostream>
using namespace std; int main(int argc, char **argv) {
std::cout << "Hello, world!" << std::endl;
return ;
} //CMakeLists.txt cmake_minimum_required(VERSION 2.6) //------The minimum version required---//
project(template) //------The project information-----// add_executable(template main.cpp) //-----Build Target------// install(TARGETS template RUNTIME DESTINATION bin)

  1.3 Compile All

 cd build
cmake ..
make

2. Single direct Multi- files

2.1 The directory tree

/*
./template
|
+--- build/
|
+---main.cpp
|
+---a.cpp
|
+---CMakeLists.txt
*/

  2.2 Sources Code

  //  main.cpp

#include <iostream>
#include "a.h"
using namespace std; int main(int argc, char **argv) { display();
std::cout << "Hello, world!" << std::endl;
return ;
} // a.cpp #include "a.h"
using namespace std; void display(void)
{
cout << "I'm in a.cpp"<< endl; } // a.h #ifndef A_H_
#define A_H_ #include <iostream>
void display(void);
#endif //CMakeLists.txt cmake_minimum_required(VERSION 2.6) //------The minimum version required---//
project(template) //------The project information-----// add_executable(template main.cpp a.cpp) //-----Build Target------// install(TARGETS template RUNTIME DESTINATION bin)

only add a.cpp in add_executable ,and there is a accepted way----used command  aux_source_directory

// CMakeLists

cmake_minimum_required(VERSION 2.6)
project(template)
aux_source_directory(./ allfiles) // The current dir
add_executable(template ${allfiles}) install(TARGETS template RUNTIME DESTINATION bin)

3. Multi dir Multi files

  3.1 dir tree

/*
./template
|
+--- build/
|
+---src/
|
+---b.cpp
|
+---CMakeLists
|
+---main.cpp
|
+---a.cpp a.h
|
+----b.h
|
+---CMakeLists.txt
*/

  3.2 Sources Code

// main.cpp

#include <iostream>
#include "a.h"
#include "b.h" using namespace std; int main(int argc, char **argv) { display();
DisplayInFileb();
std::cout << "Hello, world!" << std::endl;
return ;
} //a.cpp #include "a.h"
using namespace std; void display(void)
{
cout << "I'm in a.cpp"<< endl; } // b.cpp #include "b.h"
using namespace std;
void DisplayInFileb(void)
{
cout << "I'm in file b" << endl;
} // CMakeLists in src
aux_source_directory(./ AllfilesInSrc)
add_library(SrcFile ${AllfilesInSrc}) //CMakeLists in template
cmake_minimum_required(VERSION 2.6)
project(template)
aux_source_directory(./ allfiles)
add_subdirectory(src)
add_executable(template ${allfiles})
target_link_libraries(template SrcFile) install(TARGETS template RUNTIME DESTINATION bin)

  3.3 compile all

 cd build
cmake ..
make ./template I'm in a.cpp
I'm in file b
Hello, world!

Cmake 01的更多相关文章

  1. 一起学习CMake – 01

    一起学习CMake – 01 本节介绍CMake里最常用的三个命令,分别是cmake_minimum_required; project; add_executable等. CMake是个好东西,在使 ...

  2. 一起学习CMake – 02

    本节介绍如何用CMake来设置软件的版本号 在<一起学习CMake - 01>中我们看到了如何用CMakeLists.txt来构建一个最简单的工程,这一节里我们一起来看看如何用CMake对 ...

  3. [转] CMake

    转载地址:https://www.cnblogs.com/lidabo/p/7359422.html cmake 简介 CMake是一个跨平台的安装(编译)工具,可以用简单的语句来描述所有平台的安装( ...

  4. cmake使用方法详解

    cmake 简介 CMake是一个跨平台的安装(编译)工具,可以用简单的语句来描述所有平台的安装(编译过程).他能够输出各种各样的makefile或者project文件,能测试编译器所支持的C++特性 ...

  5. 在 linux 下使用 CMake 构建应用程序

    学习cmake http://xwz.me/wiki/doku.php?id=cmake 碰到的一些问题: 1.You have changed variables that require your ...

  6. CMake使用hellocmake&&make的使用

    2016-12-11   20:38:32 已经知道cmake这个东西很长的时间了,一直没有试验过,知道它是一个编译工具,在opencv和Linux下都有makefile的内容.感觉现在对源码的编译有 ...

  7. 在 linux 下使用 CMake 构建应用程序【转】

    本文转载自:https://www.ibm.com/developerworks/cn/linux/l-cn-cmake/index.html CMake 简介 CMake 是一个跨平台的自动化建构系 ...

  8. cmake入门:01 构建一个简单的可执行程序

    一.目录结构 CMakeLists.txt:cmake 工程入口文件,包含当前目录下的工程组织信息.cmake 指令根据此文件生成相应的 MakeFile 文件. Hello.c: 源代码文件 bui ...

  9. CMake使用教程

    转自 RichardXG 原文 CMake使用教程 CMake是一个比make更高级的编译配置工具,它可以根据不同平台.不同的编译器,生成相应的Makefile或者vcproj项目. 通过编写CMak ...

随机推荐

  1. 微信小程序填坑之旅

    一.解决scroll-view的滚动条问题 1.出现场景css. 有些场景下scroll-view是不需要滚动条的,比如顶部导航栏的横向滑动.而在单页的css样式中加入特定代码不能影响到全局的样式 2 ...

  2. iOS如何实时查看App运行日志

    Linux下管理挂载IOS设备——libimobiledevicehttps://www.jianshu.com/p/6423610d3293https://blog.csdn.net/fengzei ...

  3. 3.centos7 常用防火墙命令(转)

    1.firewalld的基本使用 启动: systemctl start firewalld 关闭: systemctl stop firewalld 查看状态: systemctl status f ...

  4. my03_使用空数据库搭建Mysql主从复制

    无数据的主从复制,就搭建一套主从结构的空库,这个是最简单的,先说说这种主从的搭建思路,有利于理解Mysql主从复制1. 安装两套mysql单实例数据库,一个作为主库.一个作为从库:注意要设置两个数据库 ...

  5. HBase学习(一)

    HBase是建立在Hadoop文件系统之上的分布式面向列的数据库.它是一个开源项目,是横向扩展的. HBase是一个数据模型,类似于谷歌的大表设计,可以提供快速随机访问海量结构化数据.它利用了Hado ...

  6. Java基础09-循环结构

    1.while循环(循环次数不确定的情况通常用这个) 特点:先判断,再执行 public class Test{ public static void main(String[] args){ int ...

  7. 性能测试工具LoadRunner10-LR之Virtual User Generator 错误处理函数

    VuGen提供了错误处理函数lr_continue_on_error,用来在脚本中实时修改Vuser的出错设置.lr_continue_on_error函数语法结构如下: void lr_contin ...

  8. (转)linux passwd批量修改用户密码

    linux passwd批量修改用户密码  原文:http://blog.csdn.net/xuwuhao/article/details/46618913 对系统定期修改密码是一个很重要的安全常识, ...

  9. HBuilder更换部分

    1.HBuilder工作空间的更换 HBuilder的默认工作空间的修改并不像其他ide一样,在设置里进行更改,而是在工具中进行设置. 1.单击菜单栏“工具”,选择“变更默认代码存放目录” 2.进行修 ...

  10. js删除数组里指定的元素

    js删除数组里指定的元素 首先可以给JS的数组对象定义一个函数,用于查找指定的元素在数组中的位置,即索引,代码为: Array.prototype.indexOf = function(val) { ...