Commit b60aee58 authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

MDEV-17279 Windows : link C runtime dynamically

Improve previous patch so we do not depend on (tiny) compiler-version
dependent libraries, i.e vcruntime140.dll, and msvcp140.dll

The remaining dependency is Universal CRT, is part of Win10+ OS,
and should already be installed by Windows update on most downlevel
systems.
parent 93942dfe
...@@ -65,7 +65,9 @@ FUNCTION(ENABLE_ASAN) ...@@ -65,7 +65,9 @@ FUNCTION(ENABLE_ASAN)
ENDIF() ENDIF()
# currently, asan is broken with static CRT. # currently, asan is broken with static CRT.
IF(NOT(MSVC_CRT_TYPE STREQUAL "/MD")) IF(NOT(MSVC_CRT_TYPE STREQUAL "/MD"))
MESSAGE(FATAL_ERROR "-DWITH_ASAN cmake parameter also requires -DMSVC_CRT_TYPE=/MD") IF(NOT DYNAMIC_UCRT_LINK)
MESSAGE(FATAL_ERROR "-DWITH_ASAN cmake parameter also requires -DMSVC_CRT_TYPE=/MD OR DYNAMIC_UCRT_LINK=ON")
ENDIF()
ENDIF() ENDIF()
IF(CMAKE_SIZEOF_VOID_P EQUAL 4) IF(CMAKE_SIZEOF_VOID_P EQUAL 4)
MESSAGE(FATAL_ERROR "-DWITH_ASAN on Windows requires 64bit build") MESSAGE(FATAL_ERROR "-DWITH_ASAN on Windows requires 64bit build")
...@@ -90,14 +92,10 @@ ENDFUNCTION() ...@@ -90,14 +92,10 @@ ENDFUNCTION()
IF(MSVC) IF(MSVC)
IF(WITH_ASAN)
ENABLE_ASAN()
ENDIF()
# Disable mingw based pkg-config found in Strawberry perl # Disable mingw based pkg-config found in Strawberry perl
SET(PKG_CONFIG_EXECUTABLE 0 CACHE INTERNAL "") SET(PKG_CONFIG_EXECUTABLE 0 CACHE INTERNAL "")
SET(MSVC_CRT_TYPE /MD CACHE STRING SET(MSVC_CRT_TYPE /MT CACHE STRING
"Runtime library - specify runtime library for linking (/MT,/MTd,/MD,/MDd)" "Runtime library - specify runtime library for linking (/MT,/MTd,/MD,/MDd)"
) )
SET(VALID_CRT_TYPES /MTd /MDd /MD /MT) SET(VALID_CRT_TYPES /MTd /MDd /MD /MT)
...@@ -105,7 +103,10 @@ IF(MSVC) ...@@ -105,7 +103,10 @@ IF(MSVC)
MESSAGE(FATAL_ERROR "Invalid value ${MSVC_CRT_TYPE} for MSVC_CRT_TYPE, choose one of /MT,/MTd,/MD,/MDd ") MESSAGE(FATAL_ERROR "Invalid value ${MSVC_CRT_TYPE} for MSVC_CRT_TYPE, choose one of /MT,/MTd,/MD,/MDd ")
ENDIF() ENDIF()
IF(MSVC_CRT_TYPE MATCHES "/MD") OPTION(DYNAMIC_UCRT_LINK "Link Universal CRT dynamically, if MSVC_CRT_TYPE=/MT" ON)
SET(DYNAMIC_UCRT_LINKER_OPTION " /NODEFAULTLIB:libucrt.lib /DEFAULTLIB:ucrt.lib")
IF((MSVC_CRT_TYPE MATCHES "/MD") OR DYNAMIC_UCRT_LINK)
# Dynamic runtime (DLLs), need to install CRT libraries. # Dynamic runtime (DLLs), need to install CRT libraries.
SET(CMAKE_INSTALL_SYSTEM_RUNTIME_COMPONENT VCCRT) SET(CMAKE_INSTALL_SYSTEM_RUNTIME_COMPONENT VCCRT)
SET(CMAKE_INSTALL_UCRT_LIBRARIES TRUE) SET(CMAKE_INSTALL_UCRT_LIBRARIES TRUE)
...@@ -115,6 +116,10 @@ IF(MSVC) ...@@ -115,6 +116,10 @@ IF(MSVC)
INCLUDE(InstallRequiredSystemLibraries) INCLUDE(InstallRequiredSystemLibraries)
ENDIF() ENDIF()
IF(WITH_ASAN)
ENABLE_ASAN()
ENDIF()
# Enable debug info also in Release build, # Enable debug info also in Release build,
# and create PDB to be able to analyze crashes. # and create PDB to be able to analyze crashes.
FOREACH(type EXE SHARED MODULE) FOREACH(type EXE SHARED MODULE)
...@@ -170,6 +175,11 @@ IF(MSVC) ...@@ -170,6 +175,11 @@ IF(MSVC)
STRING(REGEX REPLACE "/INCREMENTAL:([^ ]+)" "/INCREMENTAL:NO" CMAKE_${type}_LINKER_FLAGS_DEBUG "${CMAKE_${type}_LINKER_FLAGS_DEBUG}") STRING(REGEX REPLACE "/INCREMENTAL:([^ ]+)" "/INCREMENTAL:NO" CMAKE_${type}_LINKER_FLAGS_DEBUG "${CMAKE_${type}_LINKER_FLAGS_DEBUG}")
STRING(REGEX REPLACE "/INCREMENTAL$" "/INCREMENTAL:NO" CMAKE_${type}_LINKER_FLAGS_DEBUG "${CMAKE_${type}_LINKER_FLAGS_DEBUG}") STRING(REGEX REPLACE "/INCREMENTAL$" "/INCREMENTAL:NO" CMAKE_${type}_LINKER_FLAGS_DEBUG "${CMAKE_${type}_LINKER_FLAGS_DEBUG}")
SET(CMAKE_${type}_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_${type}_LINKER_FLAGS_RELWITHDEBINFO} /OPT:REF /release") SET(CMAKE_${type}_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_${type}_LINKER_FLAGS_RELWITHDEBINFO} /OPT:REF /release")
IF(DYNAMIC_UCRT_LINK AND (MSVC_CRT_TYPE STREQUAL "/MT"))
FOREACH(config RELEASE RELWITHDEBINFO DEBUG MINSIZEREL)
STRING(APPEND CMAKE_${type}_LINKER_FLAGS_${config} ${DYNAMIC_UCRT_LINKER_OPTION})
ENDFOREACH()
ENDIF()
ENDFOREACH() ENDFOREACH()
...@@ -288,5 +298,6 @@ MACRO(FORCE_STATIC_CRT) ...@@ -288,5 +298,6 @@ MACRO(FORCE_STATIC_CRT)
CMAKE_C_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_C_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_MINSIZEREL
) )
STRING(REGEX REPLACE "/MD[d]?" "/MT" "${flag}" "${${flag}}" ) STRING(REGEX REPLACE "/MD[d]?" "/MT" "${flag}" "${${flag}}" )
STRING(REPLACE ${DYNAMIC_UCRT_LINKER_OPTION} "" "${flag}" "${${flag}}")
ENDFOREACH() ENDFOREACH()
ENDMACRO() ENDMACRO()
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