Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(MSVC): Don't enforce /Zi if POLICY CMP0141 is available #264

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines -90 to +101
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this break the default sanitizer experience? We want the sanitizer to work by default in MSVC.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, from version 3.25 CMake sets MSVC_DEBUG_INFORMATION_FORMAT to $<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>, (see: https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_DEBUG_INFORMATION_FORMAT.html) it might break for Release/MinSizeRel builds as no debug info is generated by default.
We could set MSVC_DEBUG_INFORMATION_FORMAT to ProgramDatabase unconditionally, users can still override it in their own targets, but if they have explicitly set CMAKE_MSVC_DEBUG_INFORMATION_FORMAT to a compatible value we should not override it.

Copy link
Owner

@aminya aminya Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just want to make sure we don't have a regression in the default experience, i.e., the address sanitizer should work by default. So as long as that's the case, this change should be OK.

)
target_link_options(${_project_name} INTERFACE /INCREMENTAL:NO)
endif()
Expand Down
Loading