diff --git a/CMakeLists.txt b/CMakeLists.txt index ad1378f0..99240190 100644 --- a/CMakeLists.txt +++ b/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)