从cmake build中删除特定文件 [英] Remove specific file from cmake build

查看:4530
本文介绍了从cmake build中删除特定文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,其中我基本上有两个主要的方法。一个用于测试,另一个用于运行代码。
通常你会创建子模块,但这不是一个选项。

I have a project in which i have essentially two main methods. One for testing and one for, well, running the code. Normally you would create submodules, but this is not an option.

file(GLOB sources "*.cpp")
file(GLOB headers "*.h")
add_executable(testing ${sources} ${headers})   
add_executable(main ${sources} ${headers})   

所以测试应该编译除main.cpp以外的所有源。
Main应该编译除testing.cpp以外的所有内容。

So testing should compile all sources except for main.cpp. Main should compile everything but testing.cpp.

推荐答案

正常的方式可能是从除main.cpp和testing.cpp之外的所有源代码创建一个库,然后链接这对每个可执行文件。但是,我想你的意思是当你说你不能创建子模块时,你不能这样做。

The normal way would probably be to create a library from all the sources except main.cpp and testing.cpp, then link this to each executable. However, I guess you mean you can't do that when you say you can't create submodules.

而是可以使用list(REMOVE_ITEM ...) 命令:

Instead, you can use the list(REMOVE_ITEM ...) command:

file(GLOB sources "*.cpp")
file(GLOB headers "*.h")
set(testing_sources ${sources})
list(REMOVE_ITEM testing_sources ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)
list(REMOVE_ITEM sources ${CMAKE_CURRENT_SOURCE_DIR}/testing.cpp)
add_executable(main ${sources} ${headers})
add_executable(testing ${testing_sources} ${headers})

这篇关于从cmake build中删除特定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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