Skip to content

Commit 398f901

Browse files
committed
fix(MSVC): Don't enforce /Zi if POLICY CMP0141 is available
With the current implementation if CMAKE_MSVC_DEBUG_INFORMATION_FORMAT is set, it won't be respected as the /Zi flag is always set in enable_sanitizers. If POLICY CMP0141 is available, don't set the /Zi flag, instead use MSVC_DEBUG_INFORMATION_FORMAT, if the user didn't set CMAKE_MSVC_DEBUG_INFORMATION_FORMAT or set it to EditAndContinue, than only in that case set it to ProgramDatabase.
1 parent 2f9199c commit 398f901

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/Index.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
1111
cmake_policy(SET CMP0138 NEW)
1212
endif()
1313

14+
if(POLICY CMP0141)
15+
# MSVC debug information format flags are selected by an abstraction.
16+
cmake_policy(SET CMP0141 NEW)
17+
endif()
18+
1419
# only useable here
1520
set(ProjectOptions_SRC_DIR "${CMAKE_CURRENT_LIST_DIR}")
1621

src/Sanitizers.cmake

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,19 @@ function(
8686
"Using MSVC sanitizers requires setting the MSVC environment before building the project. Please manually open the MSVC command prompt and rebuild the project."
8787
)
8888
endif()
89+
if(POLICY CMP0141)
90+
if("${CMAKE_MSVC_DEBUG_INFORMATION_FORMAT}" STREQUAL ""
91+
OR "${CMAKE_MSVC_DEBUG_INFORMATION_FORMAT}" STREQUAL "EditAndContinue"
92+
)
93+
set_target_properties(
94+
${_project_name} PROPERTIES MSVC_DEBUG_INFORMATION_FORMAT ProgramDatabase
95+
)
96+
endif()
97+
else()
98+
target_compile_options(${_project_name} INTERFACE /Zi)
99+
endif()
89100
target_compile_options(
90-
${_project_name} INTERFACE /fsanitize=${LIST_OF_SANITIZERS} /Zi /INCREMENTAL:NO
101+
${_project_name} INTERFACE /fsanitize=${LIST_OF_SANITIZERS} /INCREMENTAL:NO
91102
)
92103
target_link_options(${_project_name} INTERFACE /INCREMENTAL:NO)
93104
endif()

0 commit comments

Comments
 (0)