diff options
author | Jan Tattermusch <jtattermusch@google.com> | 2017-02-02 20:44:22 +0100 |
---|---|---|
committer | Jan Tattermusch <jtattermusch@google.com> | 2017-02-02 23:51:09 +0100 |
commit | 514079179df9d59f2fb497e1caf5a4e11b50225d (patch) | |
tree | 45201efc0cfe26544691a1639c1f178b10a37642 | |
parent | 48cfe47a6d1ef26030d7e2bb80e33be9fc76f569 (diff) |
cmake: support static runtime linking
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | cmake/msvc_static_runtime.cmake | 14 | ||||
-rw-r--r-- | templates/CMakeLists.txt.template | 1 |
3 files changed, 16 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index ed7a76ebf4..9b0446a1e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,6 +90,7 @@ endif() set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) if (MSVC) + include(cmake/msvc_static_runtime.cmake) add_definitions(-D_WIN32_WINNT=0x600 -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS) # needed to compile protobuf add_definitions(/wd4065 /wd4506) diff --git a/cmake/msvc_static_runtime.cmake b/cmake/msvc_static_runtime.cmake new file mode 100644 index 0000000000..5a31ab3d24 --- /dev/null +++ b/cmake/msvc_static_runtime.cmake @@ -0,0 +1,14 @@ +option(gRPC_MSVC_STATIC_RUNTIME "Link with static msvc runtime libraries" OFF) + +if(gRPC_MSVC_STATIC_RUNTIME) + # switch from dynamic to static linking of msvcrt + 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() + diff --git a/templates/CMakeLists.txt.template b/templates/CMakeLists.txt.template index 57ecb93eb8..4aa3dbfd1c 100644 --- a/templates/CMakeLists.txt.template +++ b/templates/CMakeLists.txt.template @@ -134,6 +134,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) if (MSVC) + include(cmake/msvc_static_runtime.cmake) add_definitions(-D_WIN32_WINNT=0x600 -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS) # needed to compile protobuf add_definitions(/wd4065 /wd4506) |