cmake: support static runtime (MSVC)

Fixes: #737
(cherry picked from commit 246f44041e0782f728fa5ff2d39113005a1ab02d)
This commit is contained in:
Azat Khuzhin 2018-12-17 21:31:54 +03:00
parent 61fb055a43
commit c8b3ec1711
No known key found for this signature in database
GPG Key ID: B86086848EF8686D

View File

@ -221,6 +221,34 @@ else()
message(FATAL_ERROR "${EVENT_LIBRARY_TYPE} is not supported")
endif()
if (${MSVC})
set(msvc_static_runtime OFF)
if ("${EVENT_LIBRARY_TYPE}" STREQUAL "STATIC")
set(msvc_static_runtime ON)
endif()
# For more info:
# - https://docs.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library?view=vs-2017
# - https://gitlab.kitware.com/cmake/community/wikis/FAQ#how-can-i-build-my-msvc-application-with-a-static-runtime
option(EVENT__MSVC_STATIC_RUNTIME
"Link static runtime libraries"
${msvc_static_runtime})
if (EVENT__MSVC_STATIC_RUNTIME)
foreach (flag_var
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELWITHDEBINFO
)
if (${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif()
endforeach()
endif()
endif()
# GNUC specific options.
if (${GNUC})
option(EVENT__DISABLE_GCC_WARNINGS "Disable verbose warnings with GCC" OFF)