allow linking against the static msvc runtime library (#133)

allow linking against the static msvc runtime library
pull/151/head
Konstantinos Sofokleous 7 years ago committed by Brad House
parent 2a9e231396
commit b4f1ff7b51
  1. 21
      CMakeLists.txt

@ -36,6 +36,27 @@ OPTION (CARES_SHARED "Build as a shared library"
OPTION (CARES_INSTALL "Create installation targets (chain builders may want to disable this)" ON)
OPTION (CARES_STATIC_PIC "Build the static library as PIC (position independent)" OFF)
# allow linking against the static runtime library in msvc
IF (MSVC)
OPTION (CARES_MSVC_STATIC_RUNTIME "Link against the static runtime library" OFF)
IF (CARES_MSVC_STATIC_RUNTIME)
# CMAKE_CONFIGURATION_TYPES is empty on non-IDE generators (Ninja, NMake)
# and that's why we also use CMAKE_BUILD_TYPE to cover for those generators.
# For IDE generators, CMAKE_BUILD_TYPE is usually empty
FOREACH (config_type ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE})
STRING (TOUPPER ${config_type} upper_config_type)
SET (flag_var "CMAKE_C_FLAGS_${upper_config_type}")
IF (${flag_var} MATCHES "/MD")
STRING (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
ENDIF ()
ENDFOREACH ()
# clean up
SET (upper_config_type)
SET (config_type)
SET (flag_var)
ENDIF ()
ENDIF ()
# Keep build organized.
SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)

Loading…
Cancel
Save