Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: install runtimes for packages installed by vcpkg #279

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ words:
- aarch
- aminya
- Amnet
- androideabi
- anotherproj
- applellvm
- armeabi
- ARGN
- armv
- asan
Expand Down Expand Up @@ -75,6 +77,7 @@ words:
- libc
- libcuda
- libg
- libm
- libstdc
- LPSTR
- LPWSTR
Expand Down
24 changes: 24 additions & 0 deletions src/PackageProject.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 "")
Expand Down Expand Up @@ -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}$<$<CONFIG:Debug>:/debug>/bin"
"${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}$<$<CONFIG:Debug>:/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(
Expand Down
4 changes: 4 additions & 0 deletions tests/install/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions tests/myproj/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@ 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
)
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
<Eigen/Dense>
<fmt/core.h>
Expand Down
14 changes: 14 additions & 0 deletions tests/myproj/cmake/rpath.cmake
Original file line number Diff line number Diff line change
@@ -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()
6 changes: 6 additions & 0 deletions tests/myproj/vcpkg_triplets/arm-neon-android.cmake
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 6 additions & 0 deletions tests/myproj/vcpkg_triplets/arm64-android.cmake
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 6 additions & 0 deletions tests/myproj/vcpkg_triplets/arm64-osx.cmake
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 6 additions & 0 deletions tests/myproj/vcpkg_triplets/arm64-uwp.cmake
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions tests/myproj/vcpkg_triplets/arm64-windows.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set(VCPKG_TARGET_ARCHITECTURE arm64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)
6 changes: 6 additions & 0 deletions tests/myproj/vcpkg_triplets/x64-android.cmake
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions tests/myproj/vcpkg_triplets/x64-linux.cmake
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 6 additions & 0 deletions tests/myproj/vcpkg_triplets/x64-osx.cmake
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions tests/myproj/vcpkg_triplets/x64-uwp.cmake
Original file line number Diff line number Diff line change
@@ -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)

3 changes: 3 additions & 0 deletions tests/myproj/vcpkg_triplets/x64-windows-static.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE static)
set(VCPKG_LIBRARY_LINKAGE dynamic)
4 changes: 4 additions & 0 deletions tests/myproj/vcpkg_triplets/x64-windows.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)

4 changes: 4 additions & 0 deletions tests/myproj/vcpkg_triplets/x86-windows.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set(VCPKG_TARGET_ARCHITECTURE x86)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)

Loading