Commit f4cdf90d authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

MDEV-17279 Windows : link C runtime dynamically

Changed the build to use /MD flag so that DDL version of C runtime is used.

To make sure MariaDB is always runnable on target system, include
redistributable CRT libraries into installer.

For MSI package, use Microsoft's merge modules.
For ZIP  use "applocal" approach,i.e place redistributable dlls
into the bin directory of the package(via InstallRequiredSystemLibraries
cmake module) The space overhead of libraries in negligible, ~ 3MB unpacked.

There are 2 cases, where we still link C runtime statically

- Upgrade wizard, it uses MFC, and we link statically to avoid
redistribute also whole MFC (for this single application, does not
make much sense).

- MSI installer's custom action dll wixca.dll.Here, we need static link
so that MSI won't fail on a target system that does not have VC++2015
runtime already installed.
parent c57bbb25
...@@ -96,7 +96,8 @@ IF(MSVC) ...@@ -96,7 +96,8 @@ IF(MSVC)
# 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 /MT CACHE STRING
SET(MSVC_CRT_TYPE /MD 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)
...@@ -106,9 +107,7 @@ IF(MSVC) ...@@ -106,9 +107,7 @@ IF(MSVC)
IF(MSVC_CRT_TYPE MATCHES "/MD") IF(MSVC_CRT_TYPE MATCHES "/MD")
# Dynamic runtime (DLLs), need to install CRT libraries. # Dynamic runtime (DLLs), need to install CRT libraries.
SET(CMAKE_INSTALL_MFC_LIBRARIES TRUE)# upgrade wizard
SET(CMAKE_INSTALL_SYSTEM_RUNTIME_COMPONENT VCCRT) SET(CMAKE_INSTALL_SYSTEM_RUNTIME_COMPONENT VCCRT)
SET(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS TRUE)
SET(CMAKE_INSTALL_UCRT_LIBRARIES TRUE) SET(CMAKE_INSTALL_UCRT_LIBRARIES TRUE)
IF(MSVC_CRT_TYPE STREQUAL "/MDd") IF(MSVC_CRT_TYPE STREQUAL "/MDd")
SET (CMAKE_INSTALL_DEBUG_LIBRARIES_ONLY TRUE) SET (CMAKE_INSTALL_DEBUG_LIBRARIES_ONLY TRUE)
...@@ -278,3 +277,17 @@ ENDIF() ...@@ -278,3 +277,17 @@ ENDIF()
SET(FN_NO_CASE_SENSE 1) SET(FN_NO_CASE_SENSE 1)
SET(USE_SYMDIR 1) SET(USE_SYMDIR 1)
# Force static C runtime for targets in current directory
# (useful to get rid of MFC dll's dependency, or in installer)
MACRO(FORCE_STATIC_CRT)
FOREACH(flag
CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG_INIT
CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG_INIT
CMAKE_C_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_MINSIZEREL
)
STRING(REGEX REPLACE "/MD[d]?" "/MT" "${flag}" "${${flag}}" )
ENDFOREACH()
ENDMACRO()
...@@ -120,6 +120,12 @@ ELSE() ...@@ -120,6 +120,12 @@ ELSE()
SET(GIT_TAG "1.2.11") SET(GIT_TAG "1.2.11")
ENDIF() ENDIF()
IF(MSVC_CRT_TYPE MATCHES "/MD")
SET(FORCE_SHARED_CRT ON)
ELSE()
SET(FORCE_SHARED_CRT OFF)
ENDIF()
SET(AWS_SDK_PATCH_COMMAND ) SET(AWS_SDK_PATCH_COMMAND )
ExternalProject_Add( ExternalProject_Add(
aws_sdk_cpp aws_sdk_cpp
...@@ -131,7 +137,7 @@ ELSE() ...@@ -131,7 +137,7 @@ ELSE()
CMAKE_ARGS CMAKE_ARGS
-DBUILD_ONLY=kms -DBUILD_ONLY=kms
-DBUILD_SHARED_LIBS=OFF -DBUILD_SHARED_LIBS=OFF
-DFORCE_SHARED_CRT=OFF -DFORCE_SHARED_CRT=${FORCE_SHARED_CRT}
-DENABLE_TESTING=OFF -DENABLE_TESTING=OFF
"-DCMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG} ${PIC_FLAG}" "-DCMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG} ${PIC_FLAG}"
"-DCMAKE_CXX_FLAGS_RELWITHDEBINFO=${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${PIC_FLAG}" "-DCMAKE_CXX_FLAGS_RELWITHDEBINFO=${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${PIC_FLAG}"
......
...@@ -178,6 +178,39 @@ IF(CMAKE_GENERATOR MATCHES "Visual Studio") ...@@ -178,6 +178,39 @@ IF(CMAKE_GENERATOR MATCHES "Visual Studio")
SET(CONFIG_PARAM "-DCMAKE_INSTALL_CONFIG_NAME=${CMAKE_CFG_INTDIR}") SET(CONFIG_PARAM "-DCMAKE_INSTALL_CONFIG_NAME=${CMAKE_CFG_INTDIR}")
ENDIF() ENDIF()
IF(MSVC_CRT_TYPE MATCHES "/MD")
# Find out CRT merge module path, we're going to use it in installer
# The path and name depends on VS version
IF(MSVC_VERSION LESS 1900)
# VS2015
SET(VCREDIST_MSM_FILENAME Microsoft_VC140_CRT_${WIX_ARCH_SUFFIX}.msm)
SET(ProgramFilesX86 "ProgramFiles(x86)")
FIND_FILE(${VCREDIST_MSM_FILENAME}
NO_DEFAULT_PATH
PATHS
"$ENV{${ProgramFilesX86}}/Common Files/Merge Modules"
"$ENV{ProgramFiles}/Common Files/Merge Modules"
)
ELSEIF(MSVC_VERSION LESS 2000)
# VS2017
SET(VCREDIST_MSM_FILENAME Microsoft_VC141_CRT_${WIX_ARCH_SUFFIX}.msm)
FILE(GLOB MSM_LIST "C:/Program Files*/Microsoft Visual Studio/2017/*/VC/Redist/MSVC/*/MergeModules/${VCREDIST_MSM_FILENAME}")
LIST(LENGTH MSM_LIST LEN)
IF(LEN GREATER 0)
LIST(GET MSM_LIST 0 VCRedist_MSM)
ENDIF()
ELSE()
# Post-VS2017. Needs to be ported when new VS is out
MESSAGE(WARNING
"Name of redistributable merge module not known for this version of MSVC")
ENDIF()
IF (NOT VCRedist_MSM)
MESSAGE(WARNING "Can't find merge module ${VCREDIST_MSM_FILENAME}")
ELSE()
FILE(TO_NATIVE_PATH ${VCRedist_MSM} VCRedist_MSM)
# MESSAGE("VCRedist_MSM=${VCRedist_MSM}")
ENDIF()
ENDIF()
ADD_CUSTOM_TARGET( ADD_CUSTOM_TARGET(
MSI MSI
...@@ -209,44 +242,12 @@ ADD_CUSTOM_TARGET( ...@@ -209,44 +242,12 @@ ADD_CUSTOM_TARGET(
-DVERSION="${VERSION}" -DVERSION="${VERSION}"
-DWITH_THIRD_PARTY="${WITH_THIRD_PARTY}" -DWITH_THIRD_PARTY="${WITH_THIRD_PARTY}"
-DWIXCA_LOCATION="$<TARGET_FILE:wixca>" -DWIXCA_LOCATION="$<TARGET_FILE:wixca>"
-DMSVC_CRT_TYPE="${MSVC_CRT_TYPE}"
-DVCRedist_MSM="${VCRedist_MSM}"
-P ${CMAKE_CURRENT_SOURCE_DIR}/create_msi.cmake -P ${CMAKE_CURRENT_SOURCE_DIR}/create_msi.cmake
) )
ADD_DEPENDENCIES(MSI wixca) ADD_DEPENDENCIES(MSI wixca)
ADD_CUSTOM_TARGET(
MSI_ESSENTIALS
COMMAND ${CMAKE_COMMAND} ${CONFIG_PARAM} -DESSENTIALS=1
-DCANDLE_EXECUTABLE="${CANDLE_EXECUTABLE}"
-DCMAKE_CFG_INTDIR="${CMAKE_CFG_INTDIR}"
-DCMAKE_FULL_VER="${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}"
-DCMAKE_SIZEOF_VOID_P=${CMAKE_SIZEOF_VOID_P}
-DCOPYING_RTF="${COPYING_RTF}"
-DCPACK_WIX_CONFIG="${CPACK_WIX_CONFIG}"
-DCPACK_WIX_INCLUDE="${CPACK_WIX_INCLUDE}"
-DCPACK_WIX_PACKAGE_BASE_NAME="${CPACK_WIX_PACKAGE_BASE_NAME}"
-DCPACK_WIX_PACKAGE_NAME="${CPACK_WIX_PACKAGE_NAME}"
-DCPACK_WIX_UPGRADE_CODE="${CPACK_WIX_UPGRADE_CODE}"
-DEXTRA_WIX_PREPROCESSOR_FLAGS="${EXTRA_WIX_PREPROCESSOR_FLAGS}"
-DLIGHT_EXECUTABLE="${LIGHT_EXECUTABLE}"
-DMAJOR_VERSION="${MAJOR_VERSION}"
-DMANUFACTURER="${MANUFACTURER}"
-DMINOR_VERSION="${MINOR_VERSION}"
-DPATCH_VERSION="${PATCH_VERSION}"
-DSIGNCODE="${SIGNCODE}"
-DSIGNTOOL_EXECUTABLE="${SIGNTOOL_EXECUTABLE}"
-DSIGNTOOL_PARAMETERS="${SIGNTOOL_PARAMETERS}"
-DSRCDIR="${CMAKE_CURRENT_SOURCE_DIR}"
-DTHIRD_PARTY_DOWNLOAD_LOCATION="${THIRD_PARTY_DOWNLOAD_LOCATION}"
-DTHIRD_PARTY_FEATURE_CONDITION="${THIRD_PARTY_FEATURE_CONDITION}"
-DTINY_VERSION="${TINY_VERSION}"
-DTOP_BINDIR="${CMAKE_BINARY_DIR}"
-DVERSION="${VERSION}"
-DWITH_THIRD_PARTY="${WITH_THIRD_PARTY}"
-DWIXCA_LOCATION="$<TARGET_FILE:wixca>"
-P ${CMAKE_CURRENT_SOURCE_DIR}/create_msi.cmake
)
ADD_DEPENDENCIES(MSI_ESSENTIALS wixca)
IF(CMAKE_GENERATOR MATCHES "Visual Studio") IF(CMAKE_GENERATOR MATCHES "Visual Studio")
SET(CPACK_CONFIG_PARAM -C $(Configuration)) SET(CPACK_CONFIG_PARAM -C $(Configuration))
......
...@@ -9,7 +9,7 @@ IF(ESSENTIALS) ...@@ -9,7 +9,7 @@ IF(ESSENTIALS)
ENDIF() ENDIF()
ELSE() ELSE()
SET(CPACK_COMPONENTS_USED SET(CPACK_COMPONENTS_USED
"Server;Client;Development;SharedLibraries;Documentation;Readme;Common;VCCRT;connect-engine;ClientPlugins;gssapi-server;gssapi-client;aws-key-management;rocksdb-engine;backup") "Server;Client;Development;SharedLibraries;Documentation;Readme;Common;connect-engine;ClientPlugins;gssapi-server;gssapi-client;aws-key-management;rocksdb-engine;backup")
ENDIF() ENDIF()
SET( WIX_FEATURE_MySQLServer_EXTRA_FEATURES "DBInstance;SharedClientServerComponents") SET( WIX_FEATURE_MySQLServer_EXTRA_FEATURES "DBInstance;SharedClientServerComponents")
......
...@@ -18,7 +18,8 @@ SET(WIXCA_SOURCES CustomAction.cpp CustomAction.def) ...@@ -18,7 +18,8 @@ SET(WIXCA_SOURCES CustomAction.cpp CustomAction.def)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/sql) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/sql)
# Custom action should not depend on C runtime, since we do not know if CRT is installed.
FORCE_STATIC_CRT()
ADD_VERSION_INFO(wixca SHARED WIXCA_SOURCES) ADD_VERSION_INFO(wixca SHARED WIXCA_SOURCES)
ADD_LIBRARY(wixca SHARED EXCLUDE_FROM_ALL ${WIXCA_SOURCES}) ADD_LIBRARY(wixca SHARED EXCLUDE_FROM_ALL ${WIXCA_SOURCES} ${CMAKE_SOURCE_DIR}/sql/winservice.c)
TARGET_LINK_LIBRARIES(wixca ${WIX_WCAUTIL_LIBRARY} ${WIX_DUTIL_LIBRARY} TARGET_LINK_LIBRARIES(wixca ${WIX_WCAUTIL_LIBRARY} ${WIX_DUTIL_LIBRARY} msi version)
msi version winservice)
...@@ -59,6 +59,11 @@ IF(CMAKE_INSTALL_CONFIG_NAME) ...@@ -59,6 +59,11 @@ IF(CMAKE_INSTALL_CONFIG_NAME)
SET(CONFIG_PARAM "-DCMAKE_INSTALL_CONFIG_NAME=${CMAKE_INSTALL_CONFIG_NAME}") SET(CONFIG_PARAM "-DCMAKE_INSTALL_CONFIG_NAME=${CMAKE_INSTALL_CONFIG_NAME}")
ENDIF() ENDIF()
IF((MSVC_CRT_TYPE MATCHES "/MD") AND (NOT VCRedist_MSM))
# Something was wrong, we package VC runtime merge modules
# when compiled with dynamic C runtime.
MESSAGE(FATAL_ERROR "Redistributable merge module was not found")
ENDIF()
SET(COMPONENTS_ALL "${CPACK_COMPONENTS_ALL}") SET(COMPONENTS_ALL "${CPACK_COMPONENTS_ALL}")
FOREACH(comp ${COMPONENTS_ALL}) FOREACH(comp ${COMPONENTS_ALL})
...@@ -381,9 +386,13 @@ EXECUTE_PROCESS( ...@@ -381,9 +386,13 @@ EXECUTE_PROCESS(
${EXTRA_CANDLE_ARGS} ${EXTRA_CANDLE_ARGS}
) )
IF(VCRedist_MSM)
SET(SILENCE_VCREDIST_MSM_WARNINGS -sice:ICE82 -sice:ICE03)
ENDIF()
EXECUTE_PROCESS( EXECUTE_PROCESS(
COMMAND ${LIGHT_EXECUTABLE} -v -ext WixUIExtension -ext WixUtilExtension COMMAND ${LIGHT_EXECUTABLE} -v -ext WixUIExtension -ext WixUtilExtension
-ext WixFirewallExtension -sice:ICE61 -ext WixFirewallExtension -sice:ICE61 ${SILENCE_VCREDIST_MSM_WARNINGS}
mysql_server.wixobj extra.wixobj -out ${CPACK_PACKAGE_FILE_NAME}.msi mysql_server.wixobj extra.wixobj -out ${CPACK_PACKAGE_FILE_NAME}.msi
${EXTRA_LIGHT_ARGS} ${EXTRA_LIGHT_ARGS}
) )
......
...@@ -650,7 +650,17 @@ ...@@ -650,7 +650,17 @@
</Feature> </Feature>
<?endif ?> <?endif ?>
<?if "@VCRedist_MSM@" != "" ?>
<!-- VC runtime merge module -->
<DirectoryRef Id="TARGETDIR">
<Merge Id="VCRedist" SourceFile="@VCRedist_MSM@" DiskId="1" Language="0"/>
</DirectoryRef>
<Feature Id="VCRedist" Title="Visual C++ Runtime" AllowAdvertise="no" Display="hidden" Level="1">
<MergeRef Id="VCRedist"/>
</Feature>
<?endif?>
<!-- Custom action, call mysql_install_db --> <!-- Custom action, call mysql_install_db -->
<SetProperty Sequence='execute' Before='CreateDatabaseCommand' Id="SKIPNETWORKING" Value="--skip-networking" >SKIPNETWORKING</SetProperty> <SetProperty Sequence='execute' Before='CreateDatabaseCommand' Id="SKIPNETWORKING" Value="--skip-networking" >SKIPNETWORKING</SetProperty>
<SetProperty Sequence='execute' Before='CreateDatabaseCommand' Id="ALLOWREMOTEROOTACCESS" Value="--allow-remote-root-access">ALLOWREMOTEROOTACCESS</SetProperty> <SetProperty Sequence='execute' Before='CreateDatabaseCommand' Id="ALLOWREMOTEROOTACCESS" Value="--allow-remote-root-access">ALLOWREMOTEROOTACCESS</SetProperty>
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
Keywords='Installer' Keywords='Installer'
Description='MariaDB Server' Description='MariaDB Server'
Manufacturer='@MANUFACTURER@' Manufacturer='@MANUFACTURER@'
InstallerVersion='200' InstallerVersion='301'
Languages='1033' Languages='1033'
Compressed='yes' Compressed='yes'
SummaryCodepage='1252' SummaryCodepage='1252'
......
...@@ -23,21 +23,27 @@ IF(NOT MFC_FOUND) ...@@ -23,21 +23,27 @@ IF(NOT MFC_FOUND)
ENDIF() ENDIF()
RETURN() RETURN()
ENDIF() ENDIF()
IF(MSVC_CRT_TYPE MATCHES "/MD") IF(MSVC_CRT_TYPE MATCHES "/MD")
# MFC should be dynamically linked # FORCE static CRT and MFC for upgrade wizard,
SET(CMAKE_MFC_FLAG 2) # so we do not have to redistribute MFC.
FORCE_STATIC_CRT()
SET(UPGRADE_WIZARD_SOURCES ${CMAKE_SOURCE_DIR}/sql/winservice.c)
ELSE() ELSE()
# MFC should be statically linked SET(UPGRADE_WIZARD_LINK_LIBRARIES winservice)
SET(CMAKE_MFC_FLAG 1)
ENDIF() ENDIF()
# MFC should be statically linked
SET(CMAKE_MFC_FLAG 1)
# Enable exception handling (avoids warnings) # Enable exception handling (avoids warnings)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc -DNO_WARN_MBCS_MFC_DEPRECATION") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc -DNO_WARN_MBCS_MFC_DEPRECATION")
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/sql) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/sql)
MYSQL_ADD_EXECUTABLE(mysql_upgrade_wizard MYSQL_ADD_EXECUTABLE(mysql_upgrade_wizard
upgrade.cpp upgradeDlg.cpp upgrade.rc upgrade.cpp upgradeDlg.cpp upgrade.rc ${UPGRADE_WIZARD_SOURCES}
COMPONENT Server) COMPONENT Server)
TARGET_LINK_LIBRARIES(mysql_upgrade_wizard winservice) TARGET_LINK_LIBRARIES(mysql_upgrade_wizard ${UPGRADE_WIZARD_LINK_LIBRARIES})
# upgrade_wizard is Windows executable, set WIN32_EXECUTABLE so it does not # upgrade_wizard is Windows executable, set WIN32_EXECUTABLE so it does not
# create a console. # create a console.
SET_TARGET_PROPERTIES(mysql_upgrade_wizard PROPERTIES WIN32_EXECUTABLE 1) SET_TARGET_PROPERTIES(mysql_upgrade_wizard PROPERTIES WIN32_EXECUTABLE 1)
......
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