CMAKE_CXX_FLAGS applied at MSVC vcxproj level sets invalid flags for C sources
When we try a flag to change C++ template parameter packing, it ends up affecting *.c source files and thus causes the build to fail. Confirmed in CMakeCache.txt that values look as expected in CMAKE_{CXX,C}_FLAGS and their RELEASE/DEBUG variants, so it seems the problem is with the generator itself.
Oddly it works fine if a library/executable (vcxproj) is entirely C, but if a project contains both C and C++ source files it breaks down. Here's a simple CMakeLists.txt
to reproduce the problem:
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
project(example)
enable_language(C CXX)
set(CMAKE_CXX_FLAGS "/d1parsePackExpressions-")
set(CMAKE_C_FLAGS "")
add_library(CppOnly cppfile.cpp) # shows %(AdditionalOptions) /d1parsePackExpressions- in Project Properties, correct
add_library(COnly cfile.c) # shows blank Additional Options, correct
add_library(Mixed cppfile.cpp cfile.c) # 1>c1 : fatal error C1007: unrecognized flag '-parsePackExpressions-' in 'c1'
To test this you can make some empty source files by running touch cppfile.cpp cfile.c
then run CMake with a Visual Studio generator and build via the IDE. Both the CppOnly and COnly MSVC projects build correctly, but with the Mixed one it applies the /d1parsePackExpressions-
flag across both the C++ and C source files, leading to an error on the latter.
Expected behavior: The generator should set such parameters at the source file level, not the vcxproj level.