我目前有一个非常大的文件结构,我想移植到cMake,但不幸的是,我很难找到类似于我目前工作的文件结构的例子。
(_C/h指任何文件名)
Project
Target
<*.s19/*.elf goes here>
Component1
src
file.c
file.h
____.c
____.h
cfg
____.c
____.h
out
<*.o goes here>
tmp
<*.d goes here>
Component2
src
file.c
file.h
____.c
____.h
cfg
____.c
____.h
out
<*.o goes here>
tmp
<*.d goes here>
Component3
src
file.c
file.h
____.c
____.h
cfg
____.c
____.h
out
<*.o goes here>
tmp
<*.d goes here>此外,我如何告诉它在某个组件中查找包含,例如,我希望组件1中的文件只查找Component2中的#include。另外,我如何告诉它只在特定的文件列表中编译,例如在src中,我可能只希望它在file1.c中编译,而不是在file2.c中编译。
发布于 2014-02-12 04:17:30
如何在不同组件中使用不同的包含目录(借助@ruslo和@steveire):
target_include_directories作为Component2:
Cmake_minimum_required(2.8.11版)add_executable(Component2 ${Component2_SOURCES}) target_link_libraries(Component2 Component1)关于要编译的文件的确切列表。坦率地说,我认为这方面没有任何问题。只需在add_executable或add_library指令中显式地指定它们:
add_binary(Component1Binary test1.c test2.c test5.c)但我要指出的是,传统上CMake对编译后的工件使用稍微不同的布局。它要么将编译好的工件放在源目录中,要么创建一个完全分离的目录,然后将所有已编译的工件放在其中,完全再现您的项目结构。看一看:
MyProject/
CMakeLists.txt <- the top-level CMakeLists.txt. It may simply `add_subdirectory()`s (for each of its `Components`) and configure project-wide settings
Component1/
CMakeLists.txt <- this is intented to build artifact(s) for Component1
src1-1.c
src1-1.h
...
Component2/
CMakeLists.txt <- this is intented to build artifact(s) for Component2
src2-1.c
src2-1.h
...现在,您可以在文件系统中的任何地方(通常在build.release中的某个位置)创建一个具有任意名称的空目录(例如,MyProject ),然后对该目录进行cd并调用cmake,如下所示:
cmake [cmake flags like -DCMAKE_BUILD_TYPE=Release and others] path/to/the/MyProject然后,CMake在这个目录中创建所有必需的Makefile-s和其他构建构件,您可以调用make (或者如果您选择使用ninja而不是make),并且所有构建工件都驻留在该目录中,复制MyProject的原始结构。
build.release/
Component1/
src1-1.o
...
Component1.a
Component2/
src2-1.o
...
Component2Exe等
关于$<BUILD_INTERFACE:...>的更多内容是文档、CMakeLists.txt文件中的目录?等。这个特性相对较新,我仍然不确定我做的一切都是绝对正确的(测试示例确实编译了)。
https://stackoverflow.com/questions/21715028
复制相似问题