aminya / project_options

A general-purpose CMake library that provides functions that improve the CMake experience following the best practices.
https://aminya.github.io/project_options/
MIT License
332 stars 52 forks source link

Enabling Address Sanitizer overrides the debug format on MSVC #262

Open ddassie-texa opened 3 weeks ago

ddassie-texa commented 3 weeks ago

I'm trying to build a static library with embedded debug information on MSVC with Address Sanitizer enabled, and I'm seeing the following warning: cl : Command line warning D9025 : overriding '/Z7' with '/Zi' The reason this happens is this line, it sets the /Zi flag unconditionally: https://github.com/aminya/project_options/blob/46081b21083cccf6a3be6bc8b73d3f6b39eb4964/src/Sanitizers.cmake#L90

In my code I'm setting the debug information format like this:

set_target_properties(<target> PROPERTIES MSVC_DEBUG_INFORMATION_FORMAT Embedded)

Upvote & Fund

@aminya is using Polar.sh so you can upvote and help fund this issue. The funding is received once the issue is completed & confirmed by you.

Thank you in advance for helping prioritize & fund our backlog!


Fund with Polar

ddassie-texa commented 3 weeks ago

From the Microsoft documentation regarding Address Sanitizer compatibility:

However, it isn't compatible with [edit-and-continue](https://learn.microsoft.com/en-us/visualstudio/debugger/edit-and-continue-visual-cpp), [incremental linking](https://learn.microsoft.com/en-us/cpp/build/reference/incremental-link-incrementally?view=msvc-170), and [/RTC](https://learn.microsoft.com/en-us/cpp/build/reference/rtc-run-time-error-checks?view=msvc-170).

It may be possible to solve the issue by not setting /Zi and instead setting MSVC_DEBUG_INFORMATION_FORMAT to ProgramDatabase only if it was set to EditAndContinue but I'm not sure this can be done as it would have to be handled by generator expressions.