I have a project with the following structure
root/
CMakeLists.txt
mylibrary.hpp
test/
CMakeLists.txt // included from root's CMakeLists
A.cpp //includes<mylibrary.hpp>
B.cpp // also
C.cpp // also
...
Z.cpp // also
I am conviced that the compilation (of the tests) can be speed up by precompiling (pch) mylibrary.hpp
How do I tell CMake to use precompiled header if it can?
Also, the project uses different compilers, gnu, clang, nvcc, intel, (different build configurations) so the generation of the precompiled headers may not be always available.
The CMake has all the test working otherwise.
I tried using target_precompile_headers
as in
target_precompile_headers(A PUBLIC ../mylibrary.hpp)
target_precompile_headers(B PUBLIC ../mylibrary.hpp)
...
But it is actaully slower because it generates a new instance of the precompiled header for each test. (PRITAVE
gives the same (slow) result, using INTERFACE
doesn't do anything different).