From ae4885ed8b408700033cf812ec20f6e9e95645c8 Mon Sep 17 00:00:00 2001 From: FeignClaims Date: Thu, 12 Sep 2024 17:21:18 +0800 Subject: [PATCH 1/4] test: test installation of conan packages --- tests/myproj/CMakeLists.txt | 19 ++++++------------- tests/myproj/conanfile.txt | 3 +++ tests/myproj/src/main/main.cpp | 27 +++++++++++++++++++++++---- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/tests/myproj/CMakeLists.txt b/tests/myproj/CMakeLists.txt index 5fb5a780..db2e14fa 100644 --- a/tests/myproj/CMakeLists.txt +++ b/tests/myproj/CMakeLists.txt @@ -90,21 +90,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 +167,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/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 From f4b321991f2fd4c8397f4ef951f09567b910d1a7 Mon Sep 17 00:00:00 2001 From: FeignClaims Date: Thu, 12 Sep 2024 16:48:05 +0800 Subject: [PATCH 2/4] feat: automatically install runtimes for conan --- src/PackageProject.cmake | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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( From 20f4c5c95f7bae215fb448a745c795005c4a3534 Mon Sep 17 00:00:00 2001 From: FeignClaims Date: Thu, 19 Sep 2024 00:44:09 +0800 Subject: [PATCH 3/4] fix: add `libm` to cspell --- cspell.config.yaml | 1 + 1 file changed, 1 insertion(+) 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 From 18c9e2ab1d0b02d9469bd6eb163ee6550fe74f70 Mon Sep 17 00:00:00 2001 From: FeignClaims Date: Thu, 12 Sep 2024 17:21:37 +0800 Subject: [PATCH 4/4] test: run the main executable after installation --- tests/install/Taskfile.yml | 4 ++++ tests/myproj/CMakeLists.txt | 2 ++ tests/myproj/cmake/rpath.cmake | 14 ++++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 tests/myproj/cmake/rpath.cmake 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 db2e14fa..413898b4 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 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