Skip to content

Commit

Permalink
fix(MSVC): Don't enforce /Zi if POLICY CMP0141 is available
Browse files Browse the repository at this point in the history
With the current implementation if CMAKE_MSVC_DEBUG_INFORMATION_FORMAT is set,
it won't be respected as the /Zi flag set on enable_sanitizers will always
override it, just skip setting it if POLICY CMP0141 is available,
if the user has set CMAKE_MSVC_DEBUG_INFORMATION_FORMAT to EditAndContinue,
than only in that case override it.
  • Loading branch information
ddassie-texa committed Jun 17, 2024
1 parent 46081b2 commit 9d44192
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Index.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()

if(POLICY CMP0141)
# MSVC debug information format flags are selected by an abstraction.
cmake_policy(SET CMP0141 NEW)
endif()

# only useable here
set(ProjectOptions_SRC_DIR "${CMAKE_CURRENT_LIST_DIR}")

Expand Down
11 changes: 10 additions & 1 deletion src/Sanitizers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,17 @@ function(
"Using MSVC sanitizers requires setting the MSVC environment before building the project. Please manually open the MSVC command prompt and rebuild the project."
)
endif()
if(POLICY CMP0141)
if(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT STREQUAL "EditAndContinue")
set_target_properties(
${_project_name} PROPERTIES MSVC_DEBUG_INFORMATION_FORMAT ProgramDatabase
)
endif()
else()
target_compile_options(${_project_name} INTERFACE /Zi)
endif()
target_compile_options(
${_project_name} INTERFACE /fsanitize=${LIST_OF_SANITIZERS} /Zi /INCREMENTAL:NO
${_project_name} INTERFACE /fsanitize=${LIST_OF_SANITIZERS} /INCREMENTAL:NO
)
target_link_options(${_project_name} INTERFACE /INCREMENTAL:NO)
endif()
Expand Down

0 comments on commit 9d44192

Please sign in to comment.