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 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.
  • Loading branch information
ddassie-texa committed Jun 18, 2024
1 parent 2f9199c commit 398f901
Show file tree
Hide file tree
Showing 2 changed files with 17 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 @@ -11,6 +11,11 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0138 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
13 changes: 12 additions & 1 deletion src/Sanitizers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,19 @@ 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 ""
OR "${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 398f901

Please sign in to comment.