From 9ccd37ffe36b351f6079d728bf0135cac1bcdcdf Mon Sep 17 00:00:00 2001 From: FeignClaims Date: Wed, 18 Sep 2024 11:49:48 +0800 Subject: [PATCH] feat: automatically install runtimes for vcpkg --- cspell.config.yaml | 1 + src/PackageProject.cmake | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/cspell.config.yaml b/cspell.config.yaml index bddf39cb..d68c63f5 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -77,6 +77,7 @@ words: - libc - libcuda - libg + - libm - libstdc - LPSTR - LPWSTR diff --git a/src/PackageProject.cmake b/src/PackageProject.cmake index 5b44e34e..ad639c40 100644 --- a/src/PackageProject.cmake +++ b/src/PackageProject.cmake @@ -134,6 +134,7 @@ function(package_project) set(_PackageProject_NAMESPACE "${_PackageProject_NAME}::") set(_PackageProject_VARS_PREFIX ${_PackageProject_NAME}) set(_PackageProject_EXPORT ${_PackageProject_NAME}) + set(_PackageProject_SET "${_PackageProject}_deps_set") # default version to the project version if("${_PackageProject_VERSION}" STREQUAL "") @@ -249,12 +250,35 @@ function(package_project) install( TARGETS ${_targets_list} EXPORT ${_PackageProject_EXPORT} + RUNTIME_DEPENDENCY_SET ${_PackageProject_SET} LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT shlib ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT lib RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT bin PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${_PackageProject_NAME}" COMPONENT dev ${FILE_SET_ARGS} ) + set(runtime_dirs) + if(VCPKG_INSTALLED_DIR) + list(APPEND runtime_dirs + "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}$<$:/debug>/bin" + "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}$<$:/debug>/lib" + ) + endif() + if(runtime_dirs) + install(RUNTIME_DEPENDENCY_SET ${_PackageProject_SET} + PRE_EXCLUDE_REGEXES + [[api-ms-win-.*]] + [[ext-ms-.*]] + [[kernel32\.dll]] + [[(libc|libgcc_s|libgcc_s_seh|libm|libstdc\+\+|libc\+\+|libunwind)(-[0-9.]+)?\..*]] + POST_EXCLUDE_REGEXES + [[.*/system32/.*\.dll]] + [[^/lib.*]] + [[^/usr/lib.*]] + DIRECTORIES + ${runtime_dirs} + ) + endif() # download ForwardArguments FetchContent_Declare(