summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Aaron Bray <aaron.bray@kitware.com>2024-07-15 13:24:46 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2024-07-15 13:25:22 -0700
commiteb852207758a773965301d0ae717e4235fc5301a (patch)
treee782a0f721daa39de2b2a5e115e7de369b589fd3
parent65ede0a387bb3aab32634e9e840b8b4955bc1e1c (diff)
PR #1699: Add option to build with MSVC static runtime
Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1699 The correct CMake policy is set, but there is no option to switch the msvc runtime when configuring the project. Since MSVC is a multiconfiguration build tool, we need to set this CMake variable internal to the project to ensure that all of the supported build configurations get properly set (i.e. `Release` builds use `/MT` or `/MD` and `Debug` builds use `/MTd` or `/MDd`). I tried to explictly set these flags (i.e. -DCMAKE_CXX_FLAGS_XXX) when configuring the project, but these flags were being overwritten due to [explicitly setting compiler flags](https://github.com/abseil/abseil-cpp/blob/master/CMake/AbseilHelpers.cmake#L285). Merge 4fbe3ae4695621c85fd328d4977e0392a614dac4 into b86d574c5a8ca3344d02c312a63cebb49deeacfc Merging this change closes #1699 COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1699 from aaron-bray:msvc_runtime_library 4fbe3ae4695621c85fd328d4977e0392a614dac4 PiperOrigin-RevId: 652581337 Change-Id: I64b24127cda68b681a1cd327052150508df2c4a0
-rw-r--r--CMakeLists.txt9
1 files changed, 9 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3184383b..9d3e4f33 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -61,6 +61,15 @@ list(APPEND CMAKE_MODULE_PATH
${CMAKE_CURRENT_LIST_DIR}/absl/copts
)
+option(ABSL_MSVC_STATIC_RUNTIME
+ "Link static runtime libraries"
+ OFF)
+if(ABSL_MSVC_STATIC_RUNTIME)
+ set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
+else()
+ set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
+endif()
+
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
include(AbseilDll)