CMake 基本项目设置

发布于 2024-10-09 02:22:10 字数 587 浏览 0 评论 0原文

我是 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
  1. 我需要使用 cmake include_directories() 命令吗?如果是这样,我需要将其放入哪个 CMakeLists.txt 文件中? (我已经尝试了很多变体)
  2. 我需要不同的 cmake 命令吗?
  3. 如果我将其放在最顶层的 CMakeLists.txt 中,是否应该处理 A 项目或 B 项目的 .cpp 文件中 #include 的所有出现?
  4. 这是 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
  1. 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)
  2. Do I need a different cmake command?
  3. 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?
  4. Is this a typical setup for a c++ project? Does it seem logical?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天邊彩虹 2024-10-16 02:22:10

您的顶级 CMakeLists.txt 文件不需要,除非所有项目都以某种方式直接相互关联或具有其他无法解决的依赖关系。 不相关的项目不应相互包含,它们不需要父列表文件。

  1. 如果 A 和 B 是独立项目,则 ./A/CMakeLists.txt./B/CMakeLists.txt 应包含至少这一行:

    include_directories(../include)
    

    否则,如果 A 和 B 是较大单个项目的部分,则适合将这些行放入顶级 CMakeLists.txt 文件中:< /p>

    <前><代码>include_directories(包含)
    添加子目录(A)
    添加子目录(B)

  2. 仅适用于单独的项目。一次调用 cmake 将创建一个构建树。您只需要一个项目到构建树即可。

  3. 不会。只有当顶级列表文件包含 add_subdirectory 指令时,它才会影响其他列表文件。
  4. 不,这是非典型的。

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.

  1. If A and B are separate projects, ./A/CMakeLists.txt and ./B/CMakeLists.txt should contain at least this line:

    include_directories(../include)
    

    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:

    include_directories(include)
    add_subdirectory(A)
    add_subdirectory(B)
    
  2. Only for separate projects. One invocation of cmake will create one build tree. One project to a build tree is all you need.

  3. No. Only if the top-level lists file contains an add_subdirectory directive will it affect the other list files.
  4. No, this is atypical.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文