[feature suggestion] The target_precompile_headers instruction should be able to only affect a subset of source modules
Some precompiled headers cause a huge memory and time increase when supplied to the compiler.
Use case: in the mlpack project the header <mlpack.hpp>
does this, the code example is here.
When these 2 instructions are added to CMakeLists.txt:
target_precompile_headers(nn-trainer PUBLIC
${CMAKE_INSTALL_PREFIX}/include/mlpack.hpp
)
add_definitions(-DMLPACK_ENABLE_ANN_SERIALIZATION)
all C++ modules begin to consume many gigabytes more memory, and take a lot more time to compile.
The compiler is clang-14 on FreeBSD. This could be considered to be a bug in the compiler (that it loads .pch files before they are needed and it takes a lot of time), but cmake can also avoid this situation by limiting the scope of the target_precompile_headers instruction.
I suggest to add the SOURCES section to target_precompile_headers, so that it would look like this:
target_precompile_headers(<target>
<INTERFACE|PUBLIC|PRIVATE> [header1...]
[<INTERFACE|PUBLIC|PRIVATE> [header2...] ...]
[SOURCES [module1.cpp] ...]
)
Ideally, there could be multiple target_precompile_headers instructions affecting different sets of C/C++ modules.