CMake 基本项目设置
我是 CMake 的新手,正在重新学习 C++,所以我希望这些是合适的问题。我在目录 /projects/A 中有一个项目,在 /projects/include/open-source-project-1 中有一些 A 项目所依赖的 .h 文件。
Sample Hierarchy: /projects /CMakeLists.txt /A /CMakeLists.txt /a.cpp /B /CMakeLists.txt /include /open-source-project-1 /includeMe.h /open-source-project-2
- 我需要使用 cmake include_directories() 命令吗?如果是这样,我需要将其放入哪个 CMakeLists.txt 文件中? (我已经尝试了很多变体)
- 我需要不同的 cmake 命令吗?
- 如果我将其放在最顶层的 CMakeLists.txt 中,是否应该处理 A 项目或 B 项目的 .cpp 文件中 #include 的所有出现?
- 这是 C++ 项目的典型设置吗?看起来符合逻辑吗?
I'm new to CMake and re-learning C++, so I hope these are appropriate questions. I have a project in directory /projects/A and some .h files in /projects/include/open-source-project-1 that the A project depends on.
Sample Hierarchy: /projects /CMakeLists.txt /A /CMakeLists.txt /a.cpp /B /CMakeLists.txt /include /open-source-project-1 /includeMe.h /open-source-project-2
- Do I need to use a cmake include_directories() command? If so, in what CMakeLists.txt file do I need to put it in? (I've tried many variations)
- Do I need a different cmake command?
- If I put that in the top most level CMakeLists.txt, should that take care of all occurences of #include in the .cpp files for the A project or B project?
- Is this a typical setup for a c++ project? Does it seem logical?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的顶级
CMakeLists.txt
文件不需要,除非所有项目都以某种方式直接相互关联或具有其他无法解决的依赖关系。 不相关的项目不应相互包含,也它们不需要父列表文件。如果 A 和 B 是独立项目,则
./A/CMakeLists.txt
和./B/CMakeLists.txt
应包含至少这一行:否则,如果 A 和 B 是较大单个项目的部分,则适合将这些行放入顶级
CMakeLists.txt
文件中:< /p><前><代码>include_directories(包含)
添加子目录(A)
添加子目录(B)
仅适用于单独的项目。一次调用
cmake
将创建一个构建树。您只需要一个项目到构建树即可。add_subdirectory
指令时,它才会影响其他列表文件。Your top-level
CMakeLists.txt
file is not needed unless all of the projects are directly inter-related somehow or have otherwise unresolvable dependencies. Unrelated projects should not include each other, nor do they need a parent list file.If A and B are separate projects,
./A/CMakeLists.txt
and./B/CMakeLists.txt
should contain at least this line:Otherwise, if A and B are parts of a larger single project, then it is appropriate to put these lines in the top-level
CMakeLists.txt
files:Only for separate projects. One invocation of
cmake
will create one build tree. One project to a build tree is all you need.add_subdirectory
directive will it affect the other list files.