The target_compile_options() command is probably what you are looking for. The tricky part here though is that you need to precede the option with -Xclang because it needs to be passed to the internal compiler, not given to the compiler front end like most options.
We need to use SHELL: to keep the two flags together and prevent any de-duplication with other -Xclang options that may also appear on the command line.
Thx, it compiles. But it also adds it to every compile command, what I understood from this PR then this option should be only added to the compile command for PCH, so compile command that contains -emit-pch option. We don’t need to add it to compile commands for *.cpp files.
I know that CMake uses this variable to set options for the PCH compile command: CMAKE_${lang}_COMPILE_OPTIONS_CREATE_PCH.
You can use this to commands to check if the `-fno-pch-timestamp` option is in effect.
CMAKE_CXX_COMPILE_OPTIONS_CREATE_PCH is not a publicly documented part of CMake’s API. It could change at any time without notice, including the way it gets used or formed internally. You would be using that at your own risk.
As far as I can tell, there doesn’t seem to be any harm in having -fno-pch-timestamp for all command lines. It doesn’t generate any warnings for non-PCH compiles, at least not that I’ve seen.