如何避免不必要的标题依赖

时间:2018-09-21 14:12:17

标签: cmake

我使用的是cmake版本3.11.0。 我有以下程序(在文件“ c.c”中),其中标头a.h和b.h是 空:

<!-- THIS IS IN home.php-->

<button>Click me</button>

<!-- THIS IS IN hero.php -->
<section id="videoHero" class="hero hero--video">
  <div class="hero__container--teaser">
    <!-- Where the iframe is stored-->
    <div id="player"></div>
  </div>
</section>

    

和CMakeLists.txt:

#include "a.h"
#if 0
#include "b.h"
#endif
int main()
{
  return 0;
}

我运行“ cmake”。配置它,然后“ make”。 一切都很好。 然后,我“触摸b.h”,然后再次运行“ make”- 进行重建!

我的意思是,标题b.h被排除在外,对其的任何更改都可以忽略。 为什么要依赖它? 这是设计使然吗? 有可能避免吗?

谢谢

2 个答案:

答案 0 :(得分:0)

这被称为 header依赖项扫描程序,它扫描源文件并提取#include-ed到其中的标头名称。

因为它是扫描程序,所以它不会尝试检查#ifdef和其他逻辑,这可能会导致实际上不使用标头。

您可以使用include_regular_expression命令在CMake中控制标头依赖性扫描程序。

例如,您可以通过以下方式禁用扫描仪

include_regular_expression("^$") # Regular expressions matches empty string only

(从技术上讲,这不会完全禁用扫描过程,但是会禁用源头依赖项的生成)。

答案 1 :(得分:0)

因此,我可以将“ b.h”重命名为“ b.v” 并添加

include_regular_expression("^.*[.](h|hpp|cpp|inl|inc)$")

和我的“ b.v”标题将被排除。 似乎没有办法排除某些模式? 唯一要记住的是,下次我确实需要“ b.v”时,强制手动进行完全重建 谢谢

相关问题