使用CMake的一个可执行文件的多个源目录 [英] Multiple source directories for one executable with CMake

查看:572
本文介绍了使用CMake的一个可执行文件的多个源目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要将源代码组织在一些子目录中,但是可以创建一个可执行文件,而无需为每个子目录构建一个库。 CMake能做到这一点吗?例如:



ADD_EXECUTABLE(foo a / main.cpp a / other.cpp b / another.cpp)



这是简单吗?

解决方案

这里是我的简单示例



cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
项目(foo CXX)
递归地获取所有* .cpp文件
文件(GLOB_RECURSE SRC_FILES $ {PROJECT_SOURCE_DIR} / *。cpp)
add_executable(foo $ {SRC_FILES})


I want my source organised in a number of subdirectories but be able to create a single executable without having to build a library for each subdirectory. Can CMake do this? Something like:

ADD_EXECUTABLE(foo a/main.cpp a/other.cpp b/another.cpp)

Is it that simple? With the / working as a directory separator regardless of platform?

解决方案

Here the my simple example

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(foo CXX)
# get all *.cpp files recursively
file(GLOB_RECURSE SRC_FILES ${PROJECT_SOURCE_DIR}/*.cpp)
add_executable(foo ${SRC_FILES})

这篇关于使用CMake的一个可执行文件的多个源目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆