Skip to content

Commit 19ff123

Browse files
authored
cleanup: require CMake >= 3.15 with MSVC (#6190)
1 parent 566283d commit 19ff123

2 files changed

Lines changed: 17 additions & 28 deletions

File tree

CMakeLists.txt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ if (NOT ("${GOOGLE_CLOUD_CPP_CXX_STANDARD}" STREQUAL ""))
4545
"GOOGLE_CLOUD_CPP_CXX_STANDARD is retired, use CMAKE_CXX_STANDARD")
4646
endif ()
4747

48-
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
49-
include(SelectMSVCRuntime)
50-
5148
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
5249

5350
# gcc-4.8 is the first release that claims C++11 support.
@@ -68,8 +65,20 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
6865
" either lack C++11 support or have bugs that prevent us from"
6966
" using them.")
7067
endif ()
68+
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
69+
70+
if (CMAKE_VERSION VERSION_LESS 3.15)
71+
message(
72+
FATAL_ERROR
73+
"MSVC builds require CMake >= 3.15."
74+
" Previous versions of CMake lack a standard mechanism to"
75+
" select the runtime C++ library.")
76+
endif ()
7177
endif ()
7278

79+
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
80+
include(SelectMSVCRuntime)
81+
7382
option(GOOGLE_CLOUD_CPP_ENABLE_MACOS_OPENSSL_CHECK
7483
"If enabled, check that the user has defined OPENSSL_ROOT_DIR on macOS"
7584
ON)

cmake/SelectMSVCRuntime.cmake

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,10 @@
2929
#
3030

3131
if (MSVC)
32-
# TODO(#5852) - if we require CMake >= 3.15 we can remove this conditional
33-
# and the hacks below.
34-
if (NOT (CMAKE_VERSION VERSION_LESS 3.15))
35-
if (VCPKG_TARGET_TRIPLET MATCHES "-static$")
36-
set(CMAKE_MSVC_RUNTIME_LIBRARY
37-
"MultiThreaded$<$<CONFIG:Debug>:Debug>")
38-
else ()
39-
set(CMAKE_MSVC_RUNTIME_LIBRARY
40-
"MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
41-
endif ()
42-
elseif (VCPKG_TARGET_TRIPLET MATCHES "-static$")
43-
message(
44-
WARNING
45-
[===[
46-
CMake is too old to use CMAKE_MSVC_RUNTIME_LIBRARY.
47-
Attempting to set CMAKE_CXX_FLAGS* to get consistent CRT versions.
48-
]===])
49-
foreach (flag_var
50-
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
51-
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
52-
if (${flag_var} MATCHES "/MD")
53-
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
54-
endif ()
55-
endforeach (flag_var)
56-
unset(flag_var)
32+
if (VCPKG_TARGET_TRIPLET MATCHES "-static$")
33+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
34+
else ()
35+
set(CMAKE_MSVC_RUNTIME_LIBRARY
36+
"MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
5737
endif ()
5838
endif ()

0 commit comments

Comments
 (0)