diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 435a9ed..e0ddf3e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,10 +34,11 @@ 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 + sudo cmake --install build/local - name: test installed build run: | + 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 diff --git a/.gitignore b/.gitignore index 019dd34..0b84e72 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 2c35c56..fc90ebc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,6 +115,11 @@ function(packageProject) if(PROJECT_ARCH_INDEPENDENT) set(wbpvf_extra_args ARCH_INDEPENDENT) + # 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( @@ -141,7 +146,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" ) 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..6811804 --- /dev/null +++ b/test/header_only/include/header_only/adder.h @@ -0,0 +1,3 @@ +#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..b2f8c4a 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -1,5 +1,7 @@ #include #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.0"); + result &= HEADER_ONLY_VERSION_MAJOR == 1; + result &= HEADER_ONLY_VERSION_MINOR == 0; + result &= HEADER_ONLY_VERSION_PATCH == 0; + result &= HEADER_ONLY_VERSION_TWEAK == 0; return result ? 0 : 1; }