Files
CMake/Tests/RunCMake/MSVCDebugInformationFormat/CMP0141-common.cmake
Glen Chung 0e96a20478 MSVC: Add abstraction for debug information format
Replace our hard-coded default for `/Zi` with a first-class abstraction
to select the debug information format an enumeration of logical
names.  We've long hesitated to do this because the idea of "debug
information format" touches on related concepts on several platforms.
Avoid that scope creep by simply defining an abstraction that applies
only when targeting the MSVC ABI on Windows.

Removing the old default flag requires a policy because existing
projects may rely on string processing to edit them and choose a
runtime library under the old behavior.  Add policy CMP0141 to
provide compatibility.

Fixes: #10189
2022-09-14 09:12:47 -04:00

32 lines
1.1 KiB
CMake

enable_language(CXX)
cmake_policy(GET CMP0141 cmp0141)
if(cmp0141 STREQUAL "NEW")
if(NOT CMAKE_MSVC_DEBUG_INFORMATION_FORMAT_DEFAULT)
message(SEND_ERROR "CMAKE_MSVC_DEBUG_INFORMATION_FORMAT_DEFAULT not set under NEW behavior")
endif()
else()
if(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT_DEFAULT)
message(SEND_ERROR "CMAKE_MSVC_DEBUG_INFORMATION_FORMAT_DEFAULT is set under OLD behavior")
endif()
endif()
if(cmp0141 STREQUAL "NEW")
if(CMAKE_CXX_FLAGS_DEBUG MATCHES "[/-]Zi( |$)")
message(SEND_ERROR "CMAKE_CXX_FLAGS_DEBUG has -Zi flags under NEW behavior.")
endif()
if(CMAKE_CXX_FLAGS_RELWITHDEBINFO MATCHES "[/-]Zi( |$)")
message(SEND_ERROR "CMAKE_CXX_FLAGS_RELWITHDEBINFO has -Zi flags under NEW behavior.")
endif()
else()
if(NOT (CMAKE_CXX_FLAGS_DEBUG MATCHES "[/-]Zi( |$)"))
message(SEND_ERROR "CMAKE_CXX_FLAGS_DEBUG does not have -Zi flags under OLD behavior.")
endif()
if(NOT (CMAKE_CXX_FLAGS_RELWITHDEBINFO MATCHES "[/-]Zi( |$)"))
message(SEND_ERROR "CMAKE_CXX_FLAGS_RELWITHDEBINFO does not have -Zi flags under OLD behavior.")
endif()
endif()
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT BogusValue)
add_library(foo empty.cxx)