Skip to content

Commit

Permalink
make ARCH_INDEPENDENT libraries to have CMake configs installed to sh…
Browse files Browse the repository at this point in the history
…are (#42)

* make ARCH_INDEPENDENT libraries to have CMake configs installed to share

* 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`

* micro fix of test for header_only

* Update .gitignore

Co-authored-by: Lars Melchior <[email protected]>

* maybe fix CI

* fix formatting

* fix formatting.

* maybe fix tests

* place comment to the end of command, not as separate command.

* check for cmake config in /usr/local/share, not /usr/share

---------

Co-authored-by: Lars Melchior <[email protected]>
  • Loading branch information
Arniiiii and TheLartians authored Sep 2, 2024
1 parent 2d8a468 commit 5f51898
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/build
/out
/.vs
/.vs
/.cache
/compile_commands.json
/install_dir
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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"
)

Expand Down
5 changes: 4 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@ 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()
if(TEST_CPACK)
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Foo Bar <[email protected]>")
endif()
add_subdirectory(dependency)
add_subdirectory(header_only)
add_subdirectory(namespaced_dependency)
add_subdirectory(transitive_dependency)
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()
Expand Down
28 changes: 28 additions & 0 deletions test/header_only/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
)

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}"
)
3 changes: 3 additions & 0 deletions test/header_only/include/header_only/adder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

inline constexpr long add(int a, int b) { return a + b; }
8 changes: 8 additions & 0 deletions test/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <dependency/dependency.h>
#include <dependency/version.h>
#include <header_only/adder.h>
#include <header_only/version.h>
#include <namespaced_dependency/namespaced_dependency.h>
#include <namespaced_dependency/version.h>
#include <transitive_dependency/transitive_dependency.h>
Expand Down Expand Up @@ -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;
}

0 comments on commit 5f51898

Please sign in to comment.