Skip to content

Commit eb85220

Browse files
aaron-braycopybara-github
authored andcommitted
PR #1699: Add option to build with MSVC static runtime
Imported from GitHub PR #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 4fbe3ae into b86d574 Merging this change closes #1699 COPYBARA_INTEGRATE_REVIEW=#1699 from aaron-bray:msvc_runtime_library 4fbe3ae PiperOrigin-RevId: 652581337 Change-Id: I64b24127cda68b681a1cd327052150508df2c4a0
1 parent 65ede0a commit eb85220

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

CMakeLists.txt

+9
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ list(APPEND CMAKE_MODULE_PATH
6161
${CMAKE_CURRENT_LIST_DIR}/absl/copts
6262
)
6363

64+
option(ABSL_MSVC_STATIC_RUNTIME
65+
"Link static runtime libraries"
66+
OFF)
67+
if(ABSL_MSVC_STATIC_RUNTIME)
68+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
69+
else()
70+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
71+
endif()
72+
6473
include(CMakePackageConfigHelpers)
6574
include(GNUInstallDirs)
6675
include(AbseilDll)

0 commit comments

Comments
 (0)