Using -DCMAKE_CXX_FLAGS inhibits MSVC built-in defines
# Expected Behavior The built-in `WIN32` value appears in vcxproj `PreprocessorDefinitions` entries regardless of whether `-DCMAKE_CXX_FLAGS` was specified. # Actual Behavior When running CMake using a Visual Studio Generator (tested using "Visual Studio 17 2022") and specifying `-DCMAKE_CXX_FLAGS` on the commandline, the generated `.vcxproj` file loses built-in `PreprocessorDefinitions` entries, notably missing `WIN32`. When used with a project also using the rc compiler, notably the `RcCompile` section in the vcxproj retains the built-in defines (as expected since LANG specific flags are provided, I only mention it since it makes for a useful side-by-side comparison. Conversely, if running without `-DCMAKE_CXX_FLAGS` then the generated `.vcxproj` file does include the full built-in `PreprocessorDefinitions` entries, including `WIN32`. Oddly, if one instead sets the `CXXFLAGS` environment variable (indirectly initializing `CMAKE_CXX_FLAGS`) then the full built-in definitions are included. Whether WIN32 should or shouldn't be provided by CMake or assumed by a project is a ship which has likely sailed long ago (likely mimicking new project creation from within Visual Studio?). However, this issue is that since it is provided as a built-in definition, specifying additional flags via `CMAKE_CXX_FLAGS` should not inhibit the addition. Indirectly specifying via the `CXXFLAGS` environment variable is only a partial workaround since it doesn't permit changing `CMAKE_CXX_FLAGS` in a pre-existing build area. This was tested to occur with 3.16, 3.22, and 3.23.
issue