Use CMake to configure static C stdlib on Windows

Previously warnings were generated because we were passing /MTd-like
arguments twice, due to us and CMake 3.15+ adding these arguments:
https://cmake.org/cmake/help/v3.25/policy/CMP0091.html.

This requires CMake 3.15 on Windows.

This fixes #5940.
This commit is contained in:
heinrich5991 2022-10-18 14:53:37 +02:00
parent e05e47b200
commit 845c67afad

View file

@ -800,10 +800,11 @@ if(NOT(GTEST_FOUND) AND DOWNLOAD_GTEST)
if(MSVC) if(MSVC)
foreach(target gtest gmock) foreach(target gtest gmock)
set_property(TARGET ${target} PROPERTY MSVC_RUNTIME_LIBRARY MultiThreaded$<${DBG}:Debug>)
# `/w` disables all warnings. This is needed because `gtest` enables # `/w` disables all warnings. This is needed because `gtest` enables
# `/WX` (equivalent of `-Werror`) for some reason, breaking builds # `/WX` (equivalent of `-Werror`) for some reason, breaking builds
# when MSVS adds new warnings. # when MSVS adds new warnings.
target_compile_options(${target} PRIVATE $<$<NOT:${DBG}>:/MT> $<${DBG}:/MTd> /w) target_compile_options(${target} PRIVATE /w)
endforeach() endforeach()
endif() endif()
@ -2996,7 +2997,7 @@ set(TARGETS ${TARGETS_OWN} ${TARGETS_DEP})
foreach(target ${TARGETS}) foreach(target ${TARGETS})
if(MSVC) if(MSVC)
target_compile_options(${target} PRIVATE $<$<NOT:${DBG}>:/MT> $<${DBG}:/MTd>) # Use static CRT set_property(TARGET ${target} PROPERTY MSVC_RUNTIME_LIBRARY MultiThreaded$<${DBG}:Debug>) # Use static CRT
target_compile_options(${target} PRIVATE /MP) # Use multiple cores target_compile_options(${target} PRIVATE /MP) # Use multiple cores
target_compile_options(${target} PRIVATE /EHsc) # Only catch C++ exceptions with catch. target_compile_options(${target} PRIVATE /EHsc) # Only catch C++ exceptions with catch.
target_compile_options(${target} PRIVATE /GS) # Protect the stack pointer. target_compile_options(${target} PRIVATE /GS) # Protect the stack pointer.