Repeated path for internal generated PCH files (single config generators only)
For single config generators only, when a target enables precompiled headers, the path into which the pch file is generated ends up being the following:
CMakeFiles/targetName.dir/CMakeFiles/targetName.dir
The repeated pattern looks like an error, but after some digging, it appears to be an unfortunate side effect of generating the cmake_pch.hxx.cxx
file in ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/targetName.dir
instead of in ${CMAKE_CURRENT_BINARY_DIR}
. Using Ninja for illustration, the code here assumes that CMakeFiles/targetName.dir
has to be prepended to the object name (I think the Makefile equivalent is here). The single-config PCH handling code here masks this by repeating the pattern as well.
The path repetition makes the path unnecessarily long, which may cause issues on some systems. I see a couple of ways to avoid this:
- Generate a target-specific file at
${CMAKE_CURRENT_BINARY_DIR}/<targetName>_pch.hxx.cxx
instead of the generically namedcmake_pch.hxx.cxx
in${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/targetName.dir
. Then all the usual assumptions about prepending/appending paths for object files will result in non-repetition. - Update the implementation of the single config generators to recognise this situation somehow and not repeat the path.
Of the two, the first option seems less invasive but makes the assumption that the generated file won't clash with anything. The second option has more risk, since it could affect more than just PCH code.