I have several targets that want to use the same set of precompiled headers. In theory this should be easy, according to the docs:
target_precompile_headers(target1 PUBLIC header1.h header2.h header3.h header4.h)
target_precompile_headers(target2 REUSE_FROM t1)
The problem is this introduces target1 as a dependency on target2. This will rebuild target1 every time the precompiled headers need to be rebuilt when I am trying to build target2.
I attempted feeding the list of headers as a newline-delimited string, i.e. something like this:
list(APPEND PRECOMPILED_HEADERS_L header1.h header2.h header3.h header4.h)
string(REPLACE ";" "\n" PRECOMPILED_HEADERS "${PRECOMPILED_HEADERS_L}")
target_precompile_headers(target1 PUBLIC ${PRECOMPILED_HEADERS})
target_precompile_headers(target2 PUBLIC ${PRECOMPILED_HEADERS})
What ends up happening is you have a single #include in the generated cmake_pch.hxx which copies the newlines and all into that single include. Of course I could just change "\n" to "\n#include" which does appear to work, but that is likely to break in the future.
How do I properly reuse the same set of headers in multiple targets without introducing a dependency?