I am trying to use
target_precompile_headers() with a UWP / WindowsStore project. When I do this I get a compilation error:
XamlTypeInfo.Impl.g.cpp Generated Files\XamlTypeInfo.Impl.g.cpp(9,10): fatal error C1083: Cannot open precompiled header file: 'Windows10Universal.dir\Optimized\Windows10Universal.pch': No such file or directory
XamlTypeInfo.Impl.g.cpp file is generated. It’s not listed in my
CMakeLists.txt, but even if it were I think it wouldn’t matter, because the file isn’t even listed in the vcxproj or the .filters. This is apparently just some magical file that only MSBuild knows about, meaning we have no control over its command line arguments. This is a problem because it means that CMake can’t append /Fp to its command line to specify the name of the PCH, and instead – presumably since PCH is enabled at the project level – MSVC just adds a /Fp for us, but uses the name of the project.
If I right click my vcxproj and go to Precompiled Headers, I see this:
I’ve also confirmed that if I edit that and change it to
$(IntDir)cmake_pch.pch then the build succeeds.
This corresponds to adding the following snippet of Xml to generated vcxproj in the
<ItemDefinitionGroup> corresponding to the top-level build configuration (e.g. Debug, Release, etc)
Which I think that the generator is in a position to be able to do. But AFAIK there is no other way other than setting this as one of the MSBuild properties of the top-level project. Can anyone confirm whether this is indeed a bug in CMake, or whether there is some solution I’m missing?