Skip to content

Commit

Permalink
fix: support for static builds with MSVC (googleapis#5856)
Browse files Browse the repository at this point in the history
My previous cleanup was incorrect. CMake protects usage of
`CMAKE_MSVC_RUNTIME_LIBRARY` with a policy, the variable (or rather the
`MSVC_RUNTIME_LIBRARY` property set by this variable) has no effect if the
`CMP0091` policy is set to `OLD`, as would be in our builds because we say
that version 3.5 is the behavior we want in `cmake_minimum_required()`.
  • Loading branch information
coryan authored Feb 16, 2021
1 parent cb61dda commit 8c0fdd6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ cmake_minimum_required(VERSION 3.5)

# Define the project name and where to report bugs.
set(PACKAGE_BUGREPORT "https://github.com/googleapis/google-cloud-cpp/issues")

# Enable support for SelectMSVCRuntime
if (NOT (CMAKE_VERSION VERSION_LESS 3.15))
cmake_policy(SET CMP0091 NEW)
endif ()
project(
google-cloud-cpp
VERSION 1.25.0
Expand All @@ -40,6 +45,9 @@ if (NOT ("${GOOGLE_CLOUD_CPP_CXX_STANDARD}" STREQUAL ""))
"GOOGLE_CLOUD_CPP_CXX_STANDARD is retired, use CMAKE_CXX_STANDARD")
endif ()

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include(SelectMSVCRuntime)

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")

# gcc-4.8 is the first release that claims C++11 support.
Expand Down Expand Up @@ -125,7 +133,6 @@ option(GOOGLE_CLOUD_CPP_USE_MASTER_FOR_REFDOC_LINKS
mark_as_advanced(GOOGLE_CLOUD_CPP_USE_MASTER_FOR_REFDOC_LINKS)

set(PROJECT_THIRD_PARTY_DIR "${PROJECT_SOURCE_DIR}/third_party")
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

include(CMakeDependentOption)

Expand Down
3 changes: 1 addition & 2 deletions cmake/SelectMSVCRuntime.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
if (MSVC)
# TODO(#5852) - if we require CMake >= 3.15 we can remove this conditional
# and the hacks below.
if ((${CMAKE_VERSION} VERSION_GREATER 3.15) OR (${CMAKE_VERSION}
VERSION_EQUAL 3.14))
if (NOT (CMAKE_VERSION VERSION_LESS 3.15))
if (VCPKG_TARGET_TRIPLET MATCHES "-static$")
set(CMAKE_MSVC_RUNTIME_LIBRARY
"MultiThreaded$<$<CONFIG:Debug>:Debug>")
Expand Down

0 comments on commit 8c0fdd6

Please sign in to comment.