VisualStudio generator generates wrong debug information type
Hello,
with CMake 3.26.4 and the Visual Studio 17 2022 generator the following testcase emits the wrong debug configuration type in the Debug
config:
cmake_minimum_required(VERSION 3.26)
set(CMAKE_CONFIGURATION_TYPES "Release;Debug" CACHE INTERNAL "Supported configuration types")
project(testcase C)
function(update_flag variable new oldregex)
# Remove instances of `oldregex` including trailing whitespace
string(REGEX REPLACE "${oldregex} *" "" _temp "${${variable}}")
# Append the new flag
set(${variable} "${_temp} ${new}" PARENT_SCOPE)
endfunction()
update_flag(CMAKE_C_FLAGS_RELEASE "/Z7" "/Z[7iI]")
update_flag(CMAKE_C_FLAGS_DEBUG "/Z7" "/Z[7iI]")
add_library(${PROJECT_NAME} STATIC foo.c)
message(STATUS "CMAKE_C_FLAGS=${CMAKE_C_FLAGS}")
message(STATUS "CMAKE_C_FLAGS_DEBUG=${CMAKE_C_FLAGS_DEBUG}")
message(STATUS "CMAKE_C_FLAGS_RELEASE=${CMAKE_C_FLAGS_RELEASE}")
When configuring the /Z7
(aka OldStyle) flag gets set as expected:
-- CMAKE_C_FLAGS=/DWIN32 /D_WINDOWS
-- CMAKE_C_FLAGS_DEBUG=/Ob0 /Od /RTC1 /Z7
-- CMAKE_C_FLAGS_RELEASE=/O2 /Ob2 /DNDEBUG /Z7
But the generated testcase.vcxproj
looks as follows:
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
...
<DebugInformationFormat>OldStyle</DebugInformationFormat>
...
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
...
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
Could you please take a look why the /Z7
command line switch gets removed from the compiler command line and not translated into an XML element? I cannot find /Z7
in any other XML entity in the .vcxproj
file either.
Thanks, Gregor