aboutsummaryrefslogtreecommitdiffhomepage
path: root/cmake
diff options
context:
space:
mode:
authorGravatar Jan Tattermusch <jtattermusch@google.com>2015-08-08 19:56:52 -0700
committerGravatar Jan Tattermusch <jtattermusch@google.com>2015-08-08 19:56:52 -0700
commit1858ac9b42c167ab6d89b929c075872d740eb0b5 (patch)
tree65b17bd91565dae76debde5c1a408721d2064c7d /cmake
parente58cdbd2146bc8e2e2f5bf4bc8a7576f82535ae6 (diff)
make VS build link runtime statically
Diffstat (limited to 'cmake')
-rw-r--r--cmake/CMakeLists.txt12
1 files changed, 12 insertions, 0 deletions
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index d36292df..2bfe4436 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -45,6 +45,18 @@ if (MSVC)
add_definitions(-DPROTOBUF_USE_DLLS)
endif (BUILD_SHARED_LIBS)
add_definitions(/wd4244 /wd4267 /wd4018 /wd4355 /wd4800 /wd4251 /wd4996 /wd4146 /wd4305)
+
+ # Link runtime library statically so that MSVCR*.DLL is not required at runtime.
+ # https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
+ # This is achieved by replacing msvc option /MD with /MT and /MDd with /MTd
+ # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
+ foreach(flag_var
+ CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
+ CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
+ if(${flag_var} MATCHES "/MD")
+ string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
+ endif(${flag_var} MATCHES "/MD")
+ endforeach(flag_var)
endif (MSVC)
if (MSVC)