Commit d79e0379 authored by Konstantin Podsvirov's avatar Konstantin Podsvirov

Option for switching static runtime link policy with MSVC

parent 20b882d4
...@@ -8,6 +8,7 @@ project(protobuf C CXX) ...@@ -8,6 +8,7 @@ project(protobuf C CXX)
option(protobuf_VERBOSE "Enable for verbose output" OFF) option(protobuf_VERBOSE "Enable for verbose output" OFF)
option(BUILD_TESTING "Build tests" ON) option(BUILD_TESTING "Build tests" ON)
option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF) option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
option(protobuf_MSVC_STATIC_RUNTIME "Link static runtime libraries" ON)
if (MSVC) if (MSVC)
set(ZLIB_DEFAULT OFF) set(ZLIB_DEFAULT OFF)
else (MSVC) else (MSVC)
...@@ -92,13 +93,15 @@ if (MSVC) ...@@ -92,13 +93,15 @@ if (MSVC)
# https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx # https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
# This is achieved by replacing msvc option /MD with /MT and /MDd with /MTd # 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 # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
foreach(flag_var if (protobuf_MSVC_STATIC_RUNTIME)
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE foreach(flag_var
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
if(${flag_var} MATCHES "/MD") CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") if(${flag_var} MATCHES "/MD")
endif(${flag_var} MATCHES "/MD") string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endforeach(flag_var) endif(${flag_var} MATCHES "/MD")
endforeach(flag_var)
endif (protobuf_MSVC_STATIC_RUNTIME)
endif (BUILD_SHARED_LIBS) endif (BUILD_SHARED_LIBS)
add_definitions(/wd4244 /wd4267 /wd4018 /wd4355 /wd4800 /wd4251 /wd4996 /wd4146 /wd4305) add_definitions(/wd4244 /wd4267 /wd4018 /wd4355 /wd4800 /wd4251 /wd4996 /wd4146 /wd4305)
endif (MSVC) endif (MSVC)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment