cmake include header into every source file

前端 未结 2 1905
渐次进展
渐次进展 2020-12-06 05:52

I actually have a simple question, but couldn\'t find an answer. Maybe you can point me to a duplicate. So, the question is: is it possible to tell cmake to instruct a compi

2条回答
  •  青春惊慌失措
    2020-12-06 05:53

    as pointed out in the examples above, "force including" could be useful for pre-compiled headers.

    this is actually what cmake's target_precompile_headers does. https://cmake.org/cmake/help/git-stage/command/target_precompile_headers.html

    for this context-of-use:

    1. force including the header is actually a nice feature, since it allows you to use precompiled headers with MSVC, clang and gcc without changing your source.

    2. it is also a nice feature, because it allows you to switch on/off PCH with just a configuration change (e.g. in cmake). this allows you to test that your source builds also without the precompiled headers (e.g. for compilers/situations that don't support it). for instance clang-tidy gets confused about PCH (at least in combination with MSVC).

提交回复
热议问题