I am using CMake's target_precompile_headers
to generate a precompiled header from a PCH.hpp
file in a project I'm contributing to.
I need to ensure that the resultant generated source file has the exact same compilation and warning flags as the other source files in my project, to avoid -Winvalid-pch
issues.
At the moment, I am doing this:
target_precompile_headers(sfml-system PRIVATE "${CMAKE_SOURCE_DIR}/src/SFML/PCH.hpp")
set_property(SOURCE "${CMAKE_BINARY_DIR}/src/SFML/System/CMakeFiles/sfml-system.dir/cmake_pch.hxx.cxx"
APPEND_STRING PROPERTY COMPILE_FLAGS " ${WARNINGS}")
However, having to hardcode the path to the generated cmake_pch.hxx.cxx
file seems brittle, potentially non-portable, and a maintenance burden.
Is there any way I can retrieve the path to the cmake_pch.hxx.cxx
file without hardcoding it?