Remove custom MSVC CRT management

Use CMake's built-in CMAKE_MSVC_RUNTIME_LIBRARY instead.
This requires CMake 3.15), so bump cmake_minimum_required accordingly.
This commit is contained in:
Fletcher Dunn
2026-05-03 21:00:32 -07:00
parent 254d12320e
commit fd9100873b
2 changed files with 3 additions and 62 deletions
+3 -9
View File
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.15)
# If vcpkg present as submodule, bring in the toolchain # If vcpkg present as submodule, bring in the toolchain
if( EXISTS ${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake ) if( EXISTS ${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake )
@@ -33,7 +33,6 @@ if(SANITIZE_ADDRESS OR SANITIZE_THREAD OR SANITIZE_MEMORY OR SANITIZE_UNDEFINED)
set(SANITIZE ON) set(SANITIZE ON)
endif() endif()
include(FlagsMSVC)
add_definitions( -DVALVE_CRYPTO_ENABLE_25519 ) add_definitions( -DVALVE_CRYPTO_ENABLE_25519 )
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_definitions( add_definitions(
@@ -51,11 +50,6 @@ option(LTO "Enable Link-Time Optimization" OFF)
option(ENABLE_ICE "Enable support for NAT-punched P2P connections using ICE protocol. Build native ICE client" ON) option(ENABLE_ICE "Enable support for NAT-punched P2P connections using ICE protocol. Build native ICE client" ON)
option(USE_STEAMWEBRTC "Build Google's WebRTC library to get ICE support for P2P" OFF) option(USE_STEAMWEBRTC "Build Google's WebRTC library to get ICE support for P2P" OFF)
option(Protobuf_USE_STATIC_LIBS "Link with protobuf statically" OFF) option(Protobuf_USE_STATIC_LIBS "Link with protobuf statically" OFF)
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
option(MSVC_CRT_STATIC "Link the MSVC CRT statically" OFF)
configure_msvc_runtime()
print_default_msvc_flags()
endif()
# #
# Primary crypto library (for AES, SHA256, etc) # Primary crypto library (for AES, SHA256, etc)
@@ -99,8 +93,8 @@ endif()
if (USE_CRYPTO STREQUAL "OpenSSL") if (USE_CRYPTO STREQUAL "OpenSSL")
# Match the OpenSSL runtime to our setting. # Match the OpenSSL runtime to our setting.
# Note that once found the library paths are cached and will not change if the option is changed. # Note that once found the library paths are cached and will not change if the option is changed.
if (MSVC) if (MSVC AND CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "^MultiThreaded($|Debug$)")
set(OPENSSL_MSVC_STATIC_RT ${MSVC_CRT_STATIC}) set(OPENSSL_MSVC_STATIC_RT TRUE)
endif() endif()
find_package(OpenSSL REQUIRED) find_package(OpenSSL REQUIRED)
-53
View File
@@ -1,53 +0,0 @@
macro(configure_msvc_runtime)
if(MSVC)
# Set compiler options.
set(variables
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO
)
if(MSVC_CRT_STATIC)
message(STATUS "MSVC -> forcing use of statically-linked runtime.")
foreach(variable ${variables})
if(${variable} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}")
endif()
endforeach()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
else()
message(STATUS "MSVC -> forcing use of dynamically-linked runtime.")
foreach(variable ${variables})
if(${variable} MATCHES "/MT")
string(REGEX REPLACE "/MT" "/MD" ${variable} "${${variable}}")
endif()
endforeach()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
endif()
endif()
endmacro()
macro(print_default_msvc_flags)
if(MSVC)
set(variables
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO
)
message(STATUS "Initial build flags:")
foreach(variable ${variables})
message(STATUS " '${variable}': ${${variable}}")
endforeach()
message(STATUS "")
endif()
endmacro()