【问题标题】:include_directory inheritance within CMake?CMake中的include_directory继承?
【发布时间】:2018-01-12 15:23:20
【问题描述】:

我在 CMake 中有 2 个项目 L 和 A,比如 L 是一个库,A 是一个依赖于 L 的应用程序。

文件夹层次结构如下:

  • 一个
    • CMakeLists.txt + headers + src
  • 大号
    • CMakeLists.txt + headers + src
    • subL
      • 头文件 + src 文件

现在,就包含目录而言,我知道我需要在 L/CMakeLists.txt/include_directories() 中指定 subL,以便 L 中的其他文件可以引用包含文件只需使用 #include "mySubLHeaderFile.h"#include

现在,如果我想在 A 项目的文件中引用 subL 的头文件,并且能够引用此 subL 文件只需使用 #include "mySubLHeaderFile.h"#include ,我注意到我需要重新指定 subLA/CMakeLists.txt/include_directories() 中。这是正常行为吗? include_directories() 不是继承自依赖项目吗?

------ 编辑 1 --------

请注意,我在 A 和 L 上方有一个顶级 CMakeLists.txt。

【问题讨论】:

  • 你有顶级 CMakeLists.txt,在 A 和 L 之上吗?
  • 我确实有一个顶级 CMakeLists.txt,超过 A 和 L。刚刚修改了帖子以反映这一点。
  • 我不确定这一点,但我认为您可以在该顶级文件中放置一个 include_directories,以便所有子文件夹都可以访问。
  • 你知道最佳实践吗?

标签: c++ cmake


【解决方案1】:

是的,这是 CMake 的 include_directories 命令的标准行为。如果您希望将属性传播给依赖项,请使用版本 3 中成为标准的 target_include_directories 命令。具体而言,客户端代码所需的具有标头的位置应位于 PUBLICINTERFACE 部分中。如果 SubL 还需要在其中包含标头,请使用 PUBLIC。查看整个target_* 命令系列,以将属性传播给依赖项。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-08
    相关资源
    最近更新 更多