Cmake 01
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的更多相关文章
- 一起学习CMake – 01
一起学习CMake – 01 本节介绍CMake里最常用的三个命令,分别是cmake_minimum_required; project; add_executable等. CMake是个好东西,在使 ...
- 一起学习CMake – 02
本节介绍如何用CMake来设置软件的版本号 在<一起学习CMake - 01>中我们看到了如何用CMakeLists.txt来构建一个最简单的工程,这一节里我们一起来看看如何用CMake对 ...
- [转] CMake
转载地址:https://www.cnblogs.com/lidabo/p/7359422.html cmake 简介 CMake是一个跨平台的安装(编译)工具,可以用简单的语句来描述所有平台的安装( ...
- cmake使用方法详解
cmake 简介 CMake是一个跨平台的安装(编译)工具,可以用简单的语句来描述所有平台的安装(编译过程).他能够输出各种各样的makefile或者project文件,能测试编译器所支持的C++特性 ...
- 在 linux 下使用 CMake 构建应用程序
学习cmake http://xwz.me/wiki/doku.php?id=cmake 碰到的一些问题: 1.You have changed variables that require your ...
- CMake使用hellocmake&&make的使用
2016-12-11 20:38:32 已经知道cmake这个东西很长的时间了,一直没有试验过,知道它是一个编译工具,在opencv和Linux下都有makefile的内容.感觉现在对源码的编译有 ...
- 在 linux 下使用 CMake 构建应用程序【转】
本文转载自:https://www.ibm.com/developerworks/cn/linux/l-cn-cmake/index.html CMake 简介 CMake 是一个跨平台的自动化建构系 ...
- cmake入门:01 构建一个简单的可执行程序
一.目录结构 CMakeLists.txt:cmake 工程入口文件,包含当前目录下的工程组织信息.cmake 指令根据此文件生成相应的 MakeFile 文件. Hello.c: 源代码文件 bui ...
- CMake使用教程
转自 RichardXG 原文 CMake使用教程 CMake是一个比make更高级的编译配置工具,它可以根据不同平台.不同的编译器,生成相应的Makefile或者vcproj项目. 通过编写CMak ...
随机推荐
- ZPL JS 调用共享打印机
<script type="text/javascript"> function printZpl(zpl) {var printWindow = window.ope ...
- 读书笔记 - 《黑旗 ISIS的崛起》
不愧是普利策奖的书籍,读起来让人欲罢不能,花了大约四个晚上把此书一气读完.这本书讲述的是“伊斯兰国”ISIS及其前身组织历史,也就是阿布·穆萨卡·扎卡维及其追随者的故事.虽然不是小说,但故事的精彩以及 ...
- 报错:The valid characters are defined in RFC 7230 and RFC 3986
访问 spring boot controller时,报错:The valid characters are defined in RFC 7230 and RFC 3986 1.特殊符号 @Spri ...
- The 'gridview' module MUST be setup in your Yii configuration file.
解决方法:common的config的main.php中添加 'gridview' => ['class' => 'kartik\grid\Module'], 在vender的compos ...
- Silverlight TreeView 带 checkbox和图片
前段时间做Silverlight TreeView 控件,但是要带checkbox和图片,在网上到处找相关的例子,效果图如下 xaml代码 <UserControl x:Class=" ...
- checkbox多选、全选js效果
//全选checkbox function allCheck() { //全选input var all = $("input[name='all']"); //全部的input ...
- 性能测试工具LoadRunner18-LR之Controller 集合点
含义 当通过controller虚拟多个用户执行该脚本时.用户的启动或运行步骤不一定是同步的.集合点是在脚本的某处设置一个标记.当有虚拟用户运行到这个标记时,停下等待,直到所有用户都达到这个标记时,再 ...
- java控制某个字段当天递增
①思路 1.获取当前时间年月日 如:2018-01-15 00:00:00 2018-01-15 24:00:00 2.查询表中对应日期字段是否在当天时间段内 3.若是在,则从0开始递增 4.若是不在 ...
- (一)Hybrid app混合开发模式
hybrid app是什么? 这里我们先看一下词条上的定义 Hybrid App:Hybrid App is a mobile application that is coded in both br ...
- vue-router配置
首先在App.vue中 1.使用router-link组件来导航,通过‘to'属性指定链接,<router-link> 默认会被渲染成一个 `<a>` 标签 <route ...