From 9f9872d164dfdbb1b1590d7e5eb05d00a9fd4db4 Mon Sep 17 00:00:00 2001 From: Arniiiii Date: Tue, 20 Aug 2024 05:16:45 +0000 Subject: [PATCH 01/10] make ARCH_INDEPENDENT libraries to have CMake configs installed to share --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c35c56..80d46e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,8 +113,10 @@ function(packageProject) endif() endif() + set(INSTALL_DIR_FOR_CMAKE_CONFIGS ${CMAKE_INSTALL_LIBDIR}) if(PROJECT_ARCH_INDEPENDENT) set(wbpvf_extra_args ARCH_INDEPENDENT) + set(INSTALL_DIR_FOR_CMAKE_CONFIGS ${CMAKE_INSTALL_DATADIR}) # share endif() write_basic_package_version_file( @@ -141,7 +143,7 @@ function(packageProject) ) set("${PROJECT_NAME}_INSTALL_CMAKEDIR" - "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}${PROJECT_VERSION_SUFFIX}" + "${INSTALL_DIR_FOR_CMAKE_CONFIGS}/cmake/${PROJECT_NAME}${PROJECT_VERSION_SUFFIX}" CACHE PATH "CMake package config location relative to the install prefix" ) From 84b59e591a659f4ab61aedf6f9903a5cfda105c3 Mon Sep 17 00:00:00 2001 From: Arniiiii Date: Wed, 21 Aug 2024 02:56:46 +0000 Subject: [PATCH 02/10] add test added test for header only, though it works only in github workflow added some folders to gitignore made github workflow to install not on a system but in a folder `install_dir` formatted some CMakeLists.txt with `cmake-format` --- .github/workflows/test.yml | 7 +++-- .gitignore | 5 +++- CMakeLists.txt | 7 +++-- test/CMakeLists.txt | 5 +++- test/header_only/CMakeLists.txt | 28 ++++++++++++++++++++ test/header_only/include/header_only/adder.h | 5 ++++ test/main.cpp | 8 ++++++ 7 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 test/header_only/CMakeLists.txt create mode 100644 test/header_only/include/header_only/adder.h diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 435a9ed..4bbe1fc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,11 +34,14 @@ jobs: cmake -S test -B build/local cmake --build build/local cmake --build build/local --target test - sudo -E cmake --build build/local --target install + cmake --install build/local --prefix ./install_dir - name: test installed build run: | - cmake -S test -B build/installed -D TEST_INSTALLED_VERSION=1 + sudo apt install fzf ripgrep + fzf --walker-root=./install_dir -f "lib /cmake/ /dependencyConfig.cmake" | rg lib | rg cmake | rg Config.cmake + fzf --walker-root=./install_dir -f header_onlyConfig.cmake | rg share/cmake + cmake -S test -B build/installed -DCMAKE_INSTALL_PREFIX=./install_dir -D TEST_INSTALLED_VERSION=1 cmake --build build/installed cmake --build build/installed --target test diff --git a/.gitignore b/.gitignore index 019dd34..e2a28eb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ /build /out -/.vs \ No newline at end of file +/.vs +.cache/ +compile_commands.json +install_dir/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 80d46e2..fc90ebc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,10 +113,13 @@ function(packageProject) endif() endif() - set(INSTALL_DIR_FOR_CMAKE_CONFIGS ${CMAKE_INSTALL_LIBDIR}) if(PROJECT_ARCH_INDEPENDENT) set(wbpvf_extra_args ARCH_INDEPENDENT) - set(INSTALL_DIR_FOR_CMAKE_CONFIGS ${CMAKE_INSTALL_DATADIR}) # share + # install to architecture independent (share) directory + set(INSTALL_DIR_FOR_CMAKE_CONFIGS ${CMAKE_INSTALL_DATADIR}) + else() + # if x32 or multilib->x32 , install to (lib) directory. if x64, install to (lib64) directory + set(INSTALL_DIR_FOR_CMAKE_CONFIGS ${CMAKE_INSTALL_LIBDIR}) endif() write_basic_package_version_file( diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8e406e7..9aee427 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -10,6 +10,7 @@ project( if(TEST_INSTALLED_VERSION) find_package(dependency 1.2 REQUIRED) + find_package(header_only 1.0 REQUIRED) find_package(namespaced_dependency 4.5.6 REQUIRED) find_package(transitive_dependency 7.8.9 REQUIRED) else() @@ -17,6 +18,7 @@ else() set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Foo Bar ") endif() add_subdirectory(dependency) + add_subdirectory(header_only) add_subdirectory(namespaced_dependency) add_subdirectory(transitive_dependency) endif() @@ -24,7 +26,8 @@ endif() add_executable(main main.cpp) target_link_libraries( - main dependency ns::namespaced_dependency transitive_dependency::transitive_dependency + main dependency header_only ns::namespaced_dependency + transitive_dependency::transitive_dependency ) enable_testing() diff --git a/test/header_only/CMakeLists.txt b/test/header_only/CMakeLists.txt new file mode 100644 index 0000000..1ea9aac --- /dev/null +++ b/test/header_only/CMakeLists.txt @@ -0,0 +1,28 @@ +cmake_minimum_required(VERSION 3.14...3.22) + +project( + header_only + VERSION 1.0 + LANGUAGES CXX + DESCRIPTION "A header only dependency for testing PackageProject.cmake" +) + +add_library(${PROJECT_NAME} INTERFACE) + +target_include_directories( + dependency PUBLIC $ + $ +) + +add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../.. PackageProject) + +packageProject( + NAME ${PROJECT_NAME} + VERSION ${PROJECT_VERSION} + BINARY_DIR ${PROJECT_BINARY_DIR} + INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include + INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION} + VERSION_HEADER "${PROJECT_NAME}/version.h" + DEPENDENCIES "" + CPACK "${TEST_CPACK}" +) diff --git a/test/header_only/include/header_only/adder.h b/test/header_only/include/header_only/adder.h new file mode 100644 index 0000000..541562f --- /dev/null +++ b/test/header_only/include/header_only/adder.h @@ -0,0 +1,5 @@ +#pragma once + +inline constexpr long add(int a, int b) { + return a + b; +} diff --git a/test/main.cpp b/test/main.cpp index dcd4ed3..f185a4c 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include @@ -27,5 +29,11 @@ int main() { result &= TRANSITIVE_DEPENDENCY_VERSION_MINOR == 8; result &= TRANSITIVE_DEPENDENCY_VERSION_PATCH == 9; result &= TRANSITIVE_DEPENDENCY_VERSION_TWEAK == 21948124; + result &= (5 == add(2,3)); + result &= HEADER_ONLY_VERSION == std::string("1.2"); + result &= HEADER_ONLY_VERSION_MAJOR == 1; + result &= HEADER_ONLY_VERSION_MINOR == 2; + result &= HEADER_ONLY_VERSION_PATCH == 0; + result &= HEADER_ONLY_VERSION_TWEAK == 0; return result ? 0 : 1; } From 61aba0f827295e7165675803b3d164a7fe5f30bb Mon Sep 17 00:00:00 2001 From: Arniiiii Date: Wed, 21 Aug 2024 03:06:03 +0000 Subject: [PATCH 03/10] micro fix of test for header_only --- test/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/main.cpp b/test/main.cpp index f185a4c..a1de1c8 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -30,9 +30,9 @@ int main() { result &= TRANSITIVE_DEPENDENCY_VERSION_PATCH == 9; result &= TRANSITIVE_DEPENDENCY_VERSION_TWEAK == 21948124; result &= (5 == add(2,3)); - result &= HEADER_ONLY_VERSION == std::string("1.2"); + result &= HEADER_ONLY_VERSION == std::string("1.0"); result &= HEADER_ONLY_VERSION_MAJOR == 1; - result &= HEADER_ONLY_VERSION_MINOR == 2; + result &= HEADER_ONLY_VERSION_MINOR == 0; result &= HEADER_ONLY_VERSION_PATCH == 0; result &= HEADER_ONLY_VERSION_TWEAK == 0; return result ? 0 : 1; From 1e1edb29b2538f7d7b705b3fed3e917b9c6f65a4 Mon Sep 17 00:00:00 2001 From: Arni Date: Sun, 25 Aug 2024 11:55:35 +0000 Subject: [PATCH 04/10] Update .gitignore Co-authored-by: Lars Melchior --- .gitignore | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index e2a28eb..0b84e72 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ /build /out /.vs -.cache/ -compile_commands.json -install_dir/ +/.cache +/compile_commands.json +/install_dir From d86e151b9e3d33da813cd943c8f37b5f71bd6475 Mon Sep 17 00:00:00 2001 From: Arniiiii Date: Sun, 25 Aug 2024 11:58:38 +0000 Subject: [PATCH 05/10] maybe fix CI --- .github/workflows/test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4bbe1fc..6b2684c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,14 +34,14 @@ jobs: cmake -S test -B build/local cmake --build build/local cmake --build build/local --target test - cmake --install build/local --prefix ./install_dir + sudo cmake --install build/local - name: test installed build run: | sudo apt install fzf ripgrep - fzf --walker-root=./install_dir -f "lib /cmake/ /dependencyConfig.cmake" | rg lib | rg cmake | rg Config.cmake - fzf --walker-root=./install_dir -f header_onlyConfig.cmake | rg share/cmake - cmake -S test -B build/installed -DCMAKE_INSTALL_PREFIX=./install_dir -D TEST_INSTALLED_VERSION=1 + fzf --walker-root=/usr -f "lib /cmake/ /dependencyConfig.cmake" | rg lib | rg cmake | rg Config.cmake + fzf --walker-root=/usr -f header_onlyConfig.cmake | rg share/cmake + cmake -S test -B build/installed -D TEST_INSTALLED_VERSION=1 cmake --build build/installed cmake --build build/installed --target test From 5a8101eab9cbf76efbdb9e6b6b6f64f9f4bcbe5f Mon Sep 17 00:00:00 2001 From: Arniiiii Date: Sun, 25 Aug 2024 12:00:56 +0000 Subject: [PATCH 06/10] fix formatting --- test/header_only/include/header_only/adder.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/header_only/include/header_only/adder.h b/test/header_only/include/header_only/adder.h index 541562f..6811804 100644 --- a/test/header_only/include/header_only/adder.h +++ b/test/header_only/include/header_only/adder.h @@ -1,5 +1,3 @@ #pragma once -inline constexpr long add(int a, int b) { - return a + b; -} +inline constexpr long add(int a, int b) { return a + b; } From f0b861370e76121564033a606140d524dd6747f5 Mon Sep 17 00:00:00 2001 From: Arniiiii Date: Mon, 26 Aug 2024 05:58:37 +0000 Subject: [PATCH 07/10] fix formatting. --- test/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/main.cpp b/test/main.cpp index a1de1c8..b2f8c4a 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -1,11 +1,11 @@ #include #include +#include +#include #include #include #include #include -#include -#include #include @@ -29,7 +29,7 @@ int main() { result &= TRANSITIVE_DEPENDENCY_VERSION_MINOR == 8; result &= TRANSITIVE_DEPENDENCY_VERSION_PATCH == 9; result &= TRANSITIVE_DEPENDENCY_VERSION_TWEAK == 21948124; - result &= (5 == add(2,3)); + result &= (5 == add(2, 3)); result &= HEADER_ONLY_VERSION == std::string("1.0"); result &= HEADER_ONLY_VERSION_MAJOR == 1; result &= HEADER_ONLY_VERSION_MINOR == 0; From c238aa69eb294ad953a76e20aa99176388f8137f Mon Sep 17 00:00:00 2001 From: Arniiiii Date: Mon, 26 Aug 2024 09:15:24 +0000 Subject: [PATCH 08/10] maybe fix tests --- .github/workflows/test.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6b2684c..39e3739 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,9 +38,8 @@ jobs: - name: test installed build run: | - sudo apt install fzf ripgrep - fzf --walker-root=/usr -f "lib /cmake/ /dependencyConfig.cmake" | rg lib | rg cmake | rg Config.cmake - fzf --walker-root=/usr -f header_onlyConfig.cmake | rg share/cmake + # test if header only library's CMake configs are installed to a ABI-independent dir. + test -e /usr/share/cmake/header_only-1.0/header_onlyConfig.cmake cmake -S test -B build/installed -D TEST_INSTALLED_VERSION=1 cmake --build build/installed cmake --build build/installed --target test From 028acfde5f755dc3fe359324ad580e8268ca886b Mon Sep 17 00:00:00 2001 From: Arniiiii Date: Mon, 26 Aug 2024 09:46:21 +0000 Subject: [PATCH 09/10] place comment to the end of command, not as separate command. --- .github/workflows/test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 39e3739..7c0fc81 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,8 +38,7 @@ jobs: - name: test installed build run: | - # test if header only library's CMake configs are installed to a ABI-independent dir. - test -e /usr/share/cmake/header_only-1.0/header_onlyConfig.cmake + test -e /usr/share/cmake/header_only-1.0/header_onlyConfig.cmake # test if header only library's CMake configs are installed to a ABI-independent dir. cmake -S test -B build/installed -D TEST_INSTALLED_VERSION=1 cmake --build build/installed cmake --build build/installed --target test From 8c5fb16703c0f3f23fec30873da0f9d73812f949 Mon Sep 17 00:00:00 2001 From: Arniiiii Date: Mon, 26 Aug 2024 09:49:18 +0000 Subject: [PATCH 10/10] check for cmake config in /usr/local/share, not /usr/share --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7c0fc81..e0ddf3e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,7 +38,7 @@ jobs: - name: test installed build run: | - test -e /usr/share/cmake/header_only-1.0/header_onlyConfig.cmake # test if header only library's CMake configs are installed to a ABI-independent dir. + test -e /usr/local/share/cmake/header_only-1.0/header_onlyConfig.cmake # test if header only library's CMake configs are installed to a ABI-independent dir. cmake -S test -B build/installed -D TEST_INSTALLED_VERSION=1 cmake --build build/installed cmake --build build/installed --target test