mechanism to set msbuild properties on source file's <ClCompile> node?
There doesn't seem to be a way to specify msbuild properties per-source like there is for global ones.
I have a test project for a header-only library with a corresponding test project that wants to "compile" a number of files with
-fsyntax-only, to test the template logic without actually producing an executable. I've structured this as an OBJECT library that nobody actually links in, which works well just using target_compile_options to add the relevant flags, except for the Visual Studio (.vcxproj) generator (it works fine with MSVC if using makefiles or ninja).
The problem is that, despite being an OBJECT library, CMake's .vcxproj generator still emits
<ConfigurationType>StaticLibrary</ConfigurationType>, thus msbuild tries to call lib.exe to assemble the .lib files. Due to using
-Zs, there aren't any object files for it to consume.
Microsoft.Cpp.targets does have a means to express that a compile doesn't yield anything that goes into the .lib archive, namely
<ClCompile Include="path/to/foo.h"> <LibCompiled>false</LibCompiled> </ClCompile>
See also: https://github.com/Microsoft/msbuild/issues/415 (which isn't me, just something relevant I turned up while searching).
But CMake doesn't seem to have any way to generate that property.
set_property(TARGET <target> PROPERTY VS_GLOBAL_<variable> <value>), but that can't set things inside , or on per-source options.
But that suggests one solution could be an analogous
set_property(SOURCE foo.c PROPERTY VS_CLCOMPILE_<variable> <value>), with any the options thus provided just added into
clOptions.AddFlag(<variable>,<Value>) during cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags.