多个库和一个可执行文件的 CMake 项目结构

时间:2021-02-12 09:08:10

标签: c++ cmake project-layout

对于具有子模块和使用这些模块的可执行文件的大型 cmake 项目,我不确定最佳方法。

解决方案 1:

foo/                # project root directory
- CMakeLists.txt
- build/
- executable/
-- CMakeLists.txt   # call to add_executable
-- include/
-- src/
-- test/
- modules/
-- core/
--- CMakeLists.txt  # call to add_library
--- include/
---- core/          # interface of core module
--- src/
--- test/
-- utils/
--- CMakeLists.txt  # call to add_library
--- include/
---- utils          # interface of utils module
--- src/
--- test/

为每个模块创建不同的目标允许在其他项目中轻松重用模块。

但是现在很难/丑陋地将一个模块与一个允许包含(例如 #include "foo/core/...")甚至整个项目接口(例如 #include "foo/foo.hpp"

)的项目相关联

解决方案 2:

foo/                # project root directory
- CMakeLists.txt
- build/
- executable/
-- CMakeLists.txt   # call to add_executable
-- include/
-- src/
-- test/
- modules/
-- CMakeLists.txt   # call to add_library
-- include/         # interface of the whole module
--- core/           # interface of core module
--- utils/          # interface of utils module
-- src/
--- core/
--- utils/
-- test/

通过这种方法,模块接口的问题得到了解决,但某些模块的重用变成了挑剔的复制粘贴工作。

您更喜欢哪种结构?

您是否使用完全不同的结构来管理更大的项目?

0 个答案:

没有答案
相关问题