多目录工程的CmakeLists.txt编写(自动添加多目录下的文件)

http://www.cnblogs.com/chengxuyuancc/p/5347646.html

实现类似于vs中工程的CMakeLists.txt的编写。功能为main.cpp调用hello.cpp 的hello()函数,world.cpp的world()函数。使用自动添加多目录下的文件

1.工程目录如下

2.主函数main.cpp

#include <stdio.h>
#include "hello.h"
#include "world.h"
int main()
{
hello();
world();
return 0;
}

3.顶层CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project(helloworld) # Add the source in project root directory
aux_source_directory(. DIRSRCS)
# Add header file include directories
include_directories(./ ./hello ./world)
# Add block directories
add_subdirectory(hello)
add_subdirectory(world)
# Target
add_executable(helloworld ${DIRSRCS})
target_link_libraries(helloworld hello world)

4.hello文件夹

CMakeLists.txt

aux_source_directory(. DIR_HELLO_SRCS)
add_library(hello ${DIR_HELLO_SRCS})

hello.cpp

#include "hello.h"
void hello()
{
printf("hello\n");
}

hello.h

#ifndef HELLO_H
#define HELLO_H
#include <stdio.h>
void hello();
#endif

5.world文件夹

CMakeLists.txt

aux_source_directory(. DIR_WORLD_SRCS)
add_library(world ${DIR_WORLD_SRCS})

world.cpp

#include "world.h"
void world()
{
printf("world\n");
}

world.h

#ifndef WORLD_H
#define WORLD_H
#include <stdio.h>
void world();
#endif

Cmake实现样例的更多相关文章

  1. cmake使用演示样例与整理总结

    本文代码托管于github  cmake_demo cmake中一些提前定义变量 PROJECT_SOURCE_DIR project的根文件夹 PROJECT_BINARY_DIR 执行cmake命 ...

  2. 在Ubuntu下构建Bullet以及执行Bullet的样例程序

    在Ubuntu下构建Bullet以及执行Bullet的样例程序 1.找到Bullet的下载页,地址是:https://code.google.com/p/bullet/downloads/list 2 ...

  3. Libcurl的编译_HTTP/HTTPSclient源代码演示样例

    HTTP/HTTPSclient源代码演示样例 环境:  zlib-1.2.8  openssl-1.0.1g  curl-7.36 Author:  Kagula LastUpdateDate: 2 ...

  4. 使用CEF(二)— 基于VS2019编写一个简单CEF样例

    使用CEF(二)- 基于VS2019编写一个简单CEF样例 在这一节中,本人将会在Windows下使用VS2019创建一个空白的C++Windows Desktop Application项目,逐步进 ...

  5. C++的性能C#的产能?! - .Net Native 系列《三》:.NET Native部署测试方案及样例

    之前一文<c++的性能, c#的产能?!鱼和熊掌可以兼得,.NET NATIVE初窥> 获得很多朋友支持和鼓励,也更让我坚定做这项技术的推广者,希望能让更多的朋友了解这项技术,于是先从官方 ...

  6. MarkDown+LaTex 数学内容编辑样例收集

    $\color{green}{MarkDown+LaTex 数学内容编辑样例收集}$ 1.大小标题的居中,大小,颜色 [例1] $\color{Blue}{一元二次方程根的分布}$ $\color{R ...

  7. 33个超级有用必须要收藏的PHP代码样例

    作为一个正常的程序员,会好几种语言是十分正常的,相信大部分程序员也都会编写几句PHP程序,如果是WEB程序员,PHP一定是必备的,即使你没用开发过大型软件项目,也一定多少了解它的语法. 在PHP的流行 ...

  8. 关于peersim样例配置文件的超详细解读(新手勿喷)

    相信很多兄弟一开始接触peersim,对配置文件还是有点不适应,我看了好久的样例的配置文件,一层层去找对应的文件的方法,终于好像悟懂了一点,记下来以后回顾. 贴上代码,一点点分析. 首先要说下所谓的配 ...

  9. hdu 1003 MAX SUM 简单的dp,测试样例之间输出空行

    测试样例之间输出空行,if(t>0) cout<<endl; 这样出最后一组测试样例之外,其它么每组测试样例之后都会输出一个空行. dp[i]表示以a[i]结尾的最大值,则:dp[i ...

随机推荐

  1. nginx+lua+redis 处理APK包替换

    nginx + lua +redis 安装与使用入门: http://huoding.com/2012/08/31/156 nginx httpEchoModule : http://wiki.ngi ...

  2. python gevent使用例子

    python gevent使用例子 from gevent.pool import Pool POOL_SIZE = 100 def process(func, param1_list, param2 ...

  3. vue - vue-loader.conf

    'use strict' // 工具=> build/util.js const utils = require('./utils') // 配置=> build/config/index ...

  4. java开发中的一些概念名词

    1. JavaBeans JavaBean是符合某种规范的Java组件,也就是Java类.它必须满足如下规范: 1)必须有一个零参数的默认构造函数 2)必须有get和set方法,类的字段必须通过get ...

  5. Angular 监听路由变化事件

    摘要: $stateChangeStart- 当模板开始解析之前触发 $rootScope.$on('$stateChangeStart', function(event, toState, toPa ...

  6. 关于comet

    Comet是彗星的意思,这一技术之所以借用这个名字,是因为这里的每一次请求都有一个长长的“尾巴”.这个长尾巴就是我们感兴趣的长连接. 因为长连接的实现,Comet可以不需要安装浏览器插件就可以向客户端 ...

  7. ionic build android log

    RubertdeMacBook-Pro:~ Rubert$ ionic build android Current working directory is not a Cordova-based p ...

  8. 【Python 数据分析】jieba文本挖掘

    jieba是一个强大的分词库,完美支持中文分词 安装jieba 使用命令安装 pip install jieba 出现上图表示安装成功了 jieba分词模式 全模式 全模式:试图将句子精确地切开,适合 ...

  9. 自己Cookie写的自动登录功能 包含BASE64 和MD5的使用

    sql表 username  password字段 User类 有 id username password等字段 Service有一函数 @Override public User findUser ...

  10. js中加入数据缓存

    因为我们的系统设计 所有的数据查询全部是采用参数化json 后台解析后进行数据返回 由于使用统一的数据查询入口 所有可以很方便的为数据设置缓存 var ModelDataCache = new Arr ...