diff --git a/cspell.config.yaml b/cspell.config.yaml index 9ff57172..f289b037 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -75,6 +75,7 @@ words: - libc - libcuda - libg + - libm - libstdc - LPSTR - LPWSTR diff --git a/src/PackageProject.cmake b/src/PackageProject.cmake index 5b44e34e..392ee4e2 100644 --- a/src/PackageProject.cmake +++ b/src/PackageProject.cmake @@ -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( 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..4c4470f5 100644 --- a/tests/myproj/CMakeLists.txt +++ b/tests/myproj/CMakeLists.txt @@ -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 @@ -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) @@ -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) 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/conanfile.txt b/tests/myproj/conanfile.txt index 1a3bf031..4305f5bc 100644 --- a/tests/myproj/conanfile.txt +++ b/tests/myproj/conanfile.txt @@ -3,5 +3,8 @@ [requires] docopt.cpp/0.6.3 +[options] +docopt.cpp/*:shared=True + [generators] CMakeDeps diff --git a/tests/myproj/src/main/main.cpp b/tests/myproj/src/main/main.cpp index 65c8ad70..866ed13c 100644 --- a/tests/myproj/src/main/main.cpp +++ b/tests/myproj/src/main/main.cpp @@ -1,10 +1,13 @@ // test external pac +#include #include #include +#include #include // test std libraries #include +#include #include #include @@ -15,15 +18,31 @@ #include #include -int main() { - fmt::print("Hello from fmt{}", "!"); +static std::string const usage{ +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 args{docopt::docopt(usage, {argv + 1, argv + argc}, /*help=*/true, "main 1.0")}; + 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); - fmt::print("[{}]", fmt::join(eigen_vec2, ", ")); + fmt::println("[{}]", fmt::join(eigen_vec2, ", ")); #endif // trigger address sanitizer