diff --git a/cspell.config.yaml b/cspell.config.yaml index 9ff57172..d68c63f5 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -13,8 +13,10 @@ words: - aarch - aminya - Amnet + - androideabi - anotherproj - applellvm + - armeabi - ARGN - armv - asan @@ -75,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( diff --git a/tests/install/Taskfile.yml b/tests/install/Taskfile.yml index b23551ec..2657a319 100644 --- a/tests/install/Taskfile.yml +++ b/tests/install/Taskfile.yml @@ -20,6 +20,10 @@ tasks: cmds: - task: myproj:test.release - cmake --install ./build --config Release --prefix {{.CWD}}/install + - cmd: '{{.CWD}}/install/bin/main.exe' + platforms: [windows] + - cmd: '{{.CWD}}/install/bin/main' + platforms: [linux, darwin] default: cmds: diff --git a/tests/myproj/CMakeLists.txt b/tests/myproj/CMakeLists.txt index ec8b0040..56df3839 100644 --- a/tests/myproj/CMakeLists.txt +++ b/tests/myproj/CMakeLists.txt @@ -17,6 +17,10 @@ if(ENABLE_CROSS_COMPILING) enable_cross_compiler() endif() +# Override vcpkg triplets to install dynamic libraries instead of static libraries, +# so we can test the installation of vcpkg-installed dependencies afterwards +set(VCPKG_OVERLAY_TRIPLETS "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg_triplets") + run_vcpkg(VCPKG_URL "https://github.com/microsoft/vcpkg.git" VCPKG_REV "86a181505ac6460f98496a79abdee6a0f49905ec" ENABLE_VCPKG_UPDATE ) @@ -24,6 +28,8 @@ run_conan() project(myproj VERSION 0.2.0 LANGUAGES CXX C) +include(cmake/rpath.cmake) # Set rpath for installed programs, used in runtime installation test + set(PCH_HEADERS diff --git a/tests/myproj/cmake/rpath.cmake b/tests/myproj/cmake/rpath.cmake new file mode 100644 index 00000000..f6cf8a08 --- /dev/null +++ b/tests/myproj/cmake/rpath.cmake @@ -0,0 +1,14 @@ +# - A workaround to correctly resolve installed runtime dependencies on unix for now +# Include this module in the main CMakeLists.txt before adding targets to make use +include_guard() + +include(GNUInstallDirs) + +set(CMAKE_SKIP_INSTALL_RPATH OFF) + +if(APPLE) + set(CMAKE_MACOSX_RPATH ON) + list(APPEND CMAKE_INSTALL_RPATH @loader_path/../${CMAKE_INSTALL_LIBDIR}) +else() + list(APPEND CMAKE_INSTALL_RPATH $ORIGIN/../${CMAKE_INSTALL_LIBDIR}) +endif() \ No newline at end of file diff --git a/tests/myproj/vcpkg_triplets/arm-neon-android.cmake b/tests/myproj/vcpkg_triplets/arm-neon-android.cmake new file mode 100644 index 00000000..a3c7e01b --- /dev/null +++ b/tests/myproj/vcpkg_triplets/arm-neon-android.cmake @@ -0,0 +1,6 @@ +set(VCPKG_TARGET_ARCHITECTURE arm) +set(VCPKG_CRT_LINKAGE static) +set(VCPKG_LIBRARY_LINKAGE dynamic) +set(VCPKG_CMAKE_SYSTEM_NAME Android) +set(VCPKG_MAKE_BUILD_TRIPLET "--host=armv7a-linux-androideabi") +set(VCPKG_CMAKE_CONFIGURE_OPTIONS -DANDROID_ABI=armeabi-v7a -DANDROID_ARM_NEON=ON) diff --git a/tests/myproj/vcpkg_triplets/arm64-android.cmake b/tests/myproj/vcpkg_triplets/arm64-android.cmake new file mode 100644 index 00000000..5f470691 --- /dev/null +++ b/tests/myproj/vcpkg_triplets/arm64-android.cmake @@ -0,0 +1,6 @@ +set(VCPKG_TARGET_ARCHITECTURE arm64) +set(VCPKG_CRT_LINKAGE static) +set(VCPKG_LIBRARY_LINKAGE dynamic) +set(VCPKG_CMAKE_SYSTEM_NAME Android) +set(VCPKG_MAKE_BUILD_TRIPLET "--host=aarch64-linux-android") +set(VCPKG_CMAKE_CONFIGURE_OPTIONS -DANDROID_ABI=arm64-v8a) diff --git a/tests/myproj/vcpkg_triplets/arm64-osx.cmake b/tests/myproj/vcpkg_triplets/arm64-osx.cmake new file mode 100644 index 00000000..c9b1243c --- /dev/null +++ b/tests/myproj/vcpkg_triplets/arm64-osx.cmake @@ -0,0 +1,6 @@ +set(VCPKG_TARGET_ARCHITECTURE arm64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE dynamic) + +set(VCPKG_CMAKE_SYSTEM_NAME Darwin) +set(VCPKG_OSX_ARCHITECTURES arm64) diff --git a/tests/myproj/vcpkg_triplets/arm64-uwp.cmake b/tests/myproj/vcpkg_triplets/arm64-uwp.cmake new file mode 100644 index 00000000..b37c34e8 --- /dev/null +++ b/tests/myproj/vcpkg_triplets/arm64-uwp.cmake @@ -0,0 +1,6 @@ +set(VCPKG_TARGET_ARCHITECTURE arm64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE dynamic) + +set(VCPKG_CMAKE_SYSTEM_NAME WindowsStore) +set(VCPKG_CMAKE_SYSTEM_VERSION 10.0) diff --git a/tests/myproj/vcpkg_triplets/arm64-windows.cmake b/tests/myproj/vcpkg_triplets/arm64-windows.cmake new file mode 100644 index 00000000..500d65fc --- /dev/null +++ b/tests/myproj/vcpkg_triplets/arm64-windows.cmake @@ -0,0 +1,3 @@ +set(VCPKG_TARGET_ARCHITECTURE arm64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE dynamic) diff --git a/tests/myproj/vcpkg_triplets/x64-android.cmake b/tests/myproj/vcpkg_triplets/x64-android.cmake new file mode 100644 index 00000000..953845ee --- /dev/null +++ b/tests/myproj/vcpkg_triplets/x64-android.cmake @@ -0,0 +1,6 @@ +set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_CRT_LINKAGE static) +set(VCPKG_LIBRARY_LINKAGE dynamic) +set(VCPKG_CMAKE_SYSTEM_NAME Android) +set(VCPKG_MAKE_BUILD_TRIPLET "--host=x86_64-linux-android") +set(VCPKG_CMAKE_CONFIGURE_OPTIONS -DANDROID_ABI=x86_64) diff --git a/tests/myproj/vcpkg_triplets/x64-linux.cmake b/tests/myproj/vcpkg_triplets/x64-linux.cmake new file mode 100644 index 00000000..55bb50b3 --- /dev/null +++ b/tests/myproj/vcpkg_triplets/x64-linux.cmake @@ -0,0 +1,5 @@ +set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE dynamic) + +set(VCPKG_CMAKE_SYSTEM_NAME Linux) diff --git a/tests/myproj/vcpkg_triplets/x64-osx.cmake b/tests/myproj/vcpkg_triplets/x64-osx.cmake new file mode 100644 index 00000000..21fc2057 --- /dev/null +++ b/tests/myproj/vcpkg_triplets/x64-osx.cmake @@ -0,0 +1,6 @@ +set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE dynamic) + +set(VCPKG_CMAKE_SYSTEM_NAME Darwin) +set(VCPKG_OSX_ARCHITECTURES x86_64) diff --git a/tests/myproj/vcpkg_triplets/x64-uwp.cmake b/tests/myproj/vcpkg_triplets/x64-uwp.cmake new file mode 100644 index 00000000..902d8c23 --- /dev/null +++ b/tests/myproj/vcpkg_triplets/x64-uwp.cmake @@ -0,0 +1,7 @@ +set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE dynamic) + +set(VCPKG_CMAKE_SYSTEM_NAME WindowsStore) +set(VCPKG_CMAKE_SYSTEM_VERSION 10.0) + diff --git a/tests/myproj/vcpkg_triplets/x64-windows-static.cmake b/tests/myproj/vcpkg_triplets/x64-windows-static.cmake new file mode 100644 index 00000000..ac78cbb5 --- /dev/null +++ b/tests/myproj/vcpkg_triplets/x64-windows-static.cmake @@ -0,0 +1,3 @@ +set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_CRT_LINKAGE static) +set(VCPKG_LIBRARY_LINKAGE dynamic) diff --git a/tests/myproj/vcpkg_triplets/x64-windows.cmake b/tests/myproj/vcpkg_triplets/x64-windows.cmake new file mode 100644 index 00000000..d0be7297 --- /dev/null +++ b/tests/myproj/vcpkg_triplets/x64-windows.cmake @@ -0,0 +1,4 @@ +set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE dynamic) + diff --git a/tests/myproj/vcpkg_triplets/x86-windows.cmake b/tests/myproj/vcpkg_triplets/x86-windows.cmake new file mode 100644 index 00000000..93c43c3b --- /dev/null +++ b/tests/myproj/vcpkg_triplets/x86-windows.cmake @@ -0,0 +1,4 @@ +set(VCPKG_TARGET_ARCHITECTURE x86) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE dynamic) +