Skip to content

Commit 9bf0492

Browse files
committed
MDEV-36904 Improve runtime dependency packaging on Windows
Background: In MDEV-33474, we introduced runtime dependency packaging primarily to support libcurl and other potential third-party dependencies from vcpkg. Problem: The INSTALL(RUNTIME_DEPENDENCY_SET) command was failing at packaging step unless shared libraries from the same build were explicitly excluded via PRE_EXCLUDE_REGEXES. While initially only server.dll was excluded this way, this turned out insufficient for users compiling their own plugins Solution: Exclude all linked shared libraries from the same build via PRE_EXCLUDE_REGEXES. Move dependency detection and install to the end of CMake processing, after all add_library/add_executable calls, when all targets are known. Also made the INSTALL_RUNTIME_DEPENDENCIES variable independent of vcpkg detection, for simplicity.
1 parent 8c6cbb3 commit 9bf0492

File tree

2 files changed

+44
-19
lines changed

2 files changed

+44
-19
lines changed

CMakeLists.txt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,7 @@ ENDIF()
126126
FIND_PACKAGE(Git)
127127

128128
IF(WIN32 AND (CMAKE_VERSION VERSION_GREATER "3.21"))
129-
# Install runtime dependency by default, when using vcpkg
130-
IF(NOT DEFINED INSTALL_RUNTIME_DEPENDENCIES_DEFAULT)
131-
IF("${VCPKG_INSTALLED_DIR}")
132-
SET(INSTALL_RUNTIME_DEPENDENCIES_DEFAULT OFF)
133-
ELSE()
134-
SET(INSTALL_RUNTIME_DEPENDENCIES_DEFAULT ON)
135-
ENDIF()
136-
ENDIF()
137-
OPTION(INSTALL_RUNTIME_DEPENDENCIES "Install runtime dependencies" "${INSTALL_RUNTIME_DEPENDENCIES_DEFAULT}")
129+
OPTION(INSTALL_RUNTIME_DEPENDENCIES "Install runtime dependencies" ON)
138130
ENDIF()
139131

140132
# Following autotools tradition, add preprocessor definitions
@@ -596,6 +588,7 @@ ENDIF()
596588

597589
INCLUDE(build_depends)
598590

591+
INSTALL_RUNTIME_DEPS()
599592
INCLUDE(CPack)
600593

601594
IF(WIN32 AND SIGNCODE)

cmake/install_macros.cmake

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,26 +228,58 @@ FUNCTION(MYSQL_INSTALL_TARGETS)
228228
IF(SIGNCODE)
229229
SIGN_TARGET(${target} ${COMP})
230230
ENDIF()
231+
IF(INSTALL_RUNTIME_DEPENDENCIES)
232+
# Populate INSTALLED_TARGETS list (stored as global property)
233+
# The list is used in INSTALL_RUNTIME_DEPS
234+
GET_PROPERTY(installed_targets GLOBAL PROPERTY INSTALLED_TARGETS)
235+
IF(NOT installed_targets)
236+
SET(installed_targets)
237+
ENDIF()
238+
LIST(APPEND installed_targets "${target}")
239+
SET_PROPERTY(GLOBAL PROPERTY INSTALLED_TARGETS "${installed_targets}")
240+
SET(RUNTIME_DEPS RUNTIME_DEPENDENCY_SET ${target})
241+
ENDIF()
242+
INSTALL(TARGETS ${target} DESTINATION ${ARG_DESTINATION} ${COMP} ${RUNTIME_DEPS})
243+
INSTALL_DEBUG_SYMBOLS(${target} ${COMP} INSTALL_LOCATION ${ARG_DESTINATION})
231244
ENDFOREACH()
245+
ENDFUNCTION()
232246

233-
IF(WIN32 AND INSTALL_RUNTIME_DEPENDENCIES)
234-
STRING(JOIN "." runtime_deps_set_name ${TARGETS})
235-
SET(RUNTIME_DEPS RUNTIME_DEPENDENCY_SET "${runtime_deps_set_name}")
236-
ENDIF()
237247

238-
INSTALL(TARGETS ${TARGETS} DESTINATION ${ARG_DESTINATION} ${COMP} ${RUNTIME_DEPS})
239-
INSTALL_DEBUG_SYMBOLS(${TARGETS} ${COMP} INSTALL_LOCATION ${ARG_DESTINATION})
248+
# On Windows, installs runtime dependency for all targets
249+
FUNCTION(INSTALL_RUNTIME_DEPS)
250+
IF(NOT WIN32 OR NOT INSTALL_RUNTIME_DEPENDENCIES)
251+
RETURN()
252+
ENDIF()
253+
# Install all runtime dependencies
254+
255+
GET_PROPERTY(installed_targets GLOBAL PROPERTY INSTALLED_TARGETS)
256+
# Exclude all dependencies that are shared libraries from the
257+
# same build.
258+
FOREACH(tgt ${installed_targets})
259+
SET(exclude_libs)
260+
GET_TARGET_PROPERTY(link_libraries ${tgt} LINK_LIBRARIES)
261+
IF(link_libraries)
262+
FOREACH(lib ${link_libraries})
263+
IF(TARGET ${lib})
264+
GET_TARGET_PROPERTY(type ${lib} TYPE)
265+
IF(type MATCHES "SHARED")
266+
LIST(APPEND exclude_libs "$<TARGET_FILE_BASE_NAME:${lib}>\\.dll")
267+
ENDIF()
268+
ENDIF()
269+
ENDFOREACH()
270+
ENDIF()
240271

241-
IF(WIN32 AND INSTALL_RUNTIME_DEPENDENCIES)
242272
INSTALL(
243273
RUNTIME_DEPENDENCY_SET
244-
"${runtime_deps_set_name}"
274+
${tgt}
245275
COMPONENT RuntimeDeps
246276
DESTINATION ${INSTALL_BINDIR}
247277
PRE_EXCLUDE_REGEXES
248278
"api-ms-" # Windows stuff
249279
"ext-ms-"
250-
"server\\.dll" # main server DLL, installed separately
280+
"icuuc\\.dll" # Old Windows 10 (1809)
281+
"icuin\\.dll"
282+
${exclude_libs}
251283
"clang_rt" # ASAN libraries
252284
"vcruntime"
253285
POST_EXCLUDE_REGEXES
@@ -257,7 +289,7 @@ FUNCTION(MYSQL_INSTALL_TARGETS)
257289
${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/bin
258290
$<$<CONFIG:Debug>:${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug/bin>
259291
)
260-
ENDIF()
292+
ENDFOREACH()
261293
ENDFUNCTION()
262294

263295
# Optionally install mysqld/client/embedded from debug build run. outside of the current build dir

0 commit comments

Comments
 (0)