博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Cmake 01
阅读量:7016 次
发布时间:2019-06-28

本文共 2948 字,大约阅读时间需要 9 分钟。

1. sdsf(single direction single file)

  1.1  The directory tree

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

  1.2 Sources code

//  main.cpp  #include 
using namespace std; int main(int argc, char **argv) { std::cout << "Hello, world!" << std::endl; return 0; } //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

1 cd build2 cmake .. 3 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 
#include "a.h"using namespace std;int main(int argc, char **argv) { display(); std::cout << "Hello, world!" << std::endl; return 0;}// 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
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 

// CMakeListscmake_minimum_required(VERSION 2.6)project(template)aux_source_directory(./  allfiles)   // The current diradd_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 
#include "a.h"#include "b.h"using namespace std;int main(int argc, char **argv) { display(); DisplayInFileb(); std::cout << "Hello, world!" << std::endl; return 0;}//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 srcaux_source_directory(./ AllfilesInSrc)add_library(SrcFile ${AllfilesInSrc})//CMakeLists in templatecmake_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

1 cd build2 cmake ..3 make4 5 ./template6 7 I'm in a.cpp8 I'm in file b9 Hello, world!

 

转载于:https://www.cnblogs.com/BlogOfEr/p/10149434.html

你可能感兴趣的文章
[原创]隐藏用户名出现在Windows XP欢迎画面
查看>>
[SDOI2010]星际竞速——费用流
查看>>
C#开发串口总结,并提炼串口辅助类到公用类库中
查看>>
【个人笔记】《知了堂》MySQL中的数据类型
查看>>
php注入和上传图片验证
查看>>
20119-1-13作业
查看>>
c# 第29节 类
查看>>
「教程」Android手机如何通过USB使用电脑宽带上网(测试手机:Moto XT800)
查看>>
Servlet表单处理
查看>>
第二周笔记
查看>>
WordPress在线安装插件
查看>>
overflow:scroll 滚动条不显示
查看>>
C语言函数指针和回调函数
查看>>
hdu 1058 Humble Numbers (DP)
查看>>
hdu 3307 Description has only two Sentences (欧拉函数+快速幂)
查看>>
align-items和align-content的区别
查看>>
POJ 2255 Tree Recovery【二叉树重建】
查看>>
别盯着杯子
查看>>
Divide Two Integers
查看>>
MPlayer-2016 最新版本
查看>>