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 conan #281

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ words:
- libc
- libcuda
- libg
- libm
- libstdc
- LPSTR
- LPWSTR
Expand Down
19 changes: 19 additions & 0 deletions src/PackageProject.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,25 @@ function(package_project)
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${_PackageProject_NAME}" COMPONENT dev
${FILE_SET_ARGS}
)
set(runtime_dirs)
if(CONAN_RUNTIME_LIB_DIRS)
list(APPEND runtime_dirs ${CONAN_RUNTIME_LIB_DIRS})
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
21 changes: 8 additions & 13 deletions tests/myproj/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,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
<Eigen/Dense>
<fmt/core.h>
Expand Down Expand Up @@ -90,21 +92,14 @@ project_options(
add_executable(main ./src/main/main.cpp)
target_link_libraries(main PRIVATE myproj_project_options myproj_project_warnings)

target_find_dependencies(
main
target_find_dependencies(main
PUBLIC
PACKAGE
fmt
CONFIG
PACKAGE
Eigen3
CONFIG
PACKAGE
docopt
CONFIG
PACKAGE fmt CONFIG
PACKAGE Eigen3 CONFIG
PACKAGE docopt CONFIG
)

target_link_system_libraries(main PRIVATE fmt::fmt Eigen3::Eigen)
target_link_system_libraries(main PRIVATE fmt::fmt Eigen3::Eigen docopt)

add_subdirectory(libs)

Expand Down Expand Up @@ -174,7 +169,7 @@ package_project(
myproj_project_options
myproj_project_warnings
PUBLIC_INCLUDES
${lib2_INCLUDE_DIR22}
${lib2_INCLUDE_DIR2}
)

package_project(NAME myproj_main TARGETS main)
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()
3 changes: 3 additions & 0 deletions tests/myproj/conanfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
[requires]
docopt.cpp/0.6.3

[options]
docopt.cpp/*:shared=True

[generators]
CMakeDeps
27 changes: 23 additions & 4 deletions tests/myproj/src/main/main.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,48 @@
// test external pac
#include <docopt/docopt.h>
#include <Eigen/Dense>
#include <fmt/core.h>
#include <fmt/ostream.h>
#include <fmt/ranges.h>

// test std libraries
#include <iostream>

Check warning on line 9 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-22.04, gcc, true)

included header iostream is not used directly [misc-include-cleaner]

Check warning on line 9 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-22.04, llvm, true)

included header iostream is not used directly [misc-include-cleaner]

Check warning on line 9 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (windows-2022, gcc, true)

included header iostream is not used directly [misc-include-cleaner]
#include <map>
#include <string>
#include <string_view>

Check warning on line 12 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-22.04, gcc, true)

included header string_view is not used directly [misc-include-cleaner]

Check warning on line 12 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-22.04, llvm, true)

included header string_view is not used directly [misc-include-cleaner]

Check warning on line 12 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (windows-2022, gcc, true)

included header string_view is not used directly [misc-include-cleaner]

// test c libraries
#include <cassert>
#include <cctype>
#include <cstddef>

Check warning on line 17 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (windows-2022, gcc, true)

included header cstddef is not used directly [misc-include-cleaner]
#include <cstdint>
#include <cstring>

int main() {
fmt::print("Hello from fmt{}", "!");
static std::string const usage{

Check warning on line 21 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-13, gcc, true)

initialization of 'usage' with static storage duration may throw an exception that cannot be caught [cert-err58-cpp]

Check warning on line 21 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-13, llvm, true)

initialization of 'usage' with static storage duration may throw an exception that cannot be caught [cert-err58-cpp]
R"(main.

Usage:
main
main (-h | --help)
main --version

Options:
-h --help Show this screen.
--version Show version.
)"};

int main(int argc, char const* argv[]) {
std::map<std::string, docopt::value> args{docopt::docopt(usage, {argv + 1, argv + argc}, /*help=*/true, "main 1.0")};

Check warning on line 35 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-13, gcc, true)

variable 'args' of type 'std::map<std::string, docopt::value>' (aka 'map<basic_string<char, char_traits<char>, allocator<char>>, docopt::value>') can be declared 'const' [misc-const-correctness]

Check warning on line 35 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-13, llvm, true)

variable 'args' of type 'std::map<std::string, docopt::value>' (aka 'map<basic_string<char, char_traits<char>, allocator<char>>, docopt::value>') can be declared 'const' [misc-const-correctness]
for (auto const& arg : args) {
fmt::println("{}: {}", arg.first, fmt::streamed(arg.second));
}

Eigen::VectorXd eigen_vec = Eigen::Vector3d(1, 2, 3);
fmt::print("[{}]", fmt::join(eigen_vec, ", "));
fmt::println("[{}]", fmt::join(eigen_vec, ", "));

#if !defined(__MINGW32__) && !defined(__MSYS__)// TODO fails
Eigen::VectorXd eigen_vec2 = Eigen::VectorXd::LinSpaced(10, 0, 1);

Check warning on line 44 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-13, gcc, true)

10 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]

Check warning on line 44 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-13, llvm, true)

10 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]
fmt::print("[{}]", fmt::join(eigen_vec2, ", "));
fmt::println("[{}]", fmt::join(eigen_vec2, ", "));
#endif

// trigger address sanitizer
Expand All @@ -31,5 +50,5 @@
// *p = 1;

// trigger compiler warnings, clang-tidy, and cppcheck
int a;

Check warning on line 53 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-13, gcc, true)

unused variable 'a' [clang-diagnostic-unused-variable]

Check warning on line 53 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-13, gcc, true)

variable 'a' is not initialized [cppcoreguidelines-init-variables]

Check warning on line 53 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-13, gcc, true)

variable name 'a' is too short, expected at least 3 characters [readability-identifier-length]

Check warning on line 53 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-13, gcc, true)

Unused variable: a [unusedVariable]

Check warning on line 53 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-13, gcc, true)

unused variable 'a' [-Wunused-variable]

Check warning on line 53 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-13, llvm, true)

unused variable 'a' [clang-diagnostic-unused-variable]

Check warning on line 53 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-13, llvm, true)

variable 'a' is not initialized [cppcoreguidelines-init-variables]

Check warning on line 53 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-13, llvm, true)

variable name 'a' is too short, expected at least 3 characters [readability-identifier-length]

Check warning on line 53 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-13, llvm, true)

Unused variable: a [unusedVariable]

Check warning on line 53 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-13, llvm, true)

unused variable 'a' [-Wunused-variable]
}
Loading