Skip to content

Commit 5f51898

Browse files
make ARCH_INDEPENDENT libraries to have CMake configs installed to share (#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 <TheLartians@users.noreply.github.com> * 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 <TheLartians@users.noreply.github.com>
1 parent 2d8a468 commit 5f51898

7 files changed

Lines changed: 55 additions & 4 deletions

File tree

.github/workflows/test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ jobs:
3434
cmake -S test -B build/local
3535
cmake --build build/local
3636
cmake --build build/local --target test
37-
sudo -E cmake --build build/local --target install
37+
sudo cmake --install build/local
3838
3939
- name: test installed build
4040
run: |
41+
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.
4142
cmake -S test -B build/installed -D TEST_INSTALLED_VERSION=1
4243
cmake --build build/installed
4344
cmake --build build/installed --target test

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
/build
22
/out
3-
/.vs
3+
/.vs
4+
/.cache
5+
/compile_commands.json
6+
/install_dir

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ function(packageProject)
115115

116116
if(PROJECT_ARCH_INDEPENDENT)
117117
set(wbpvf_extra_args ARCH_INDEPENDENT)
118+
# install to architecture independent (share) directory
119+
set(INSTALL_DIR_FOR_CMAKE_CONFIGS ${CMAKE_INSTALL_DATADIR})
120+
else()
121+
# if x32 or multilib->x32 , install to (lib) directory. if x64, install to (lib64) directory
122+
set(INSTALL_DIR_FOR_CMAKE_CONFIGS ${CMAKE_INSTALL_LIBDIR})
118123
endif()
119124

120125
write_basic_package_version_file(
@@ -141,7 +146,7 @@ function(packageProject)
141146
)
142147

143148
set("${PROJECT_NAME}_INSTALL_CMAKEDIR"
144-
"${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}${PROJECT_VERSION_SUFFIX}"
149+
"${INSTALL_DIR_FOR_CMAKE_CONFIGS}/cmake/${PROJECT_NAME}${PROJECT_VERSION_SUFFIX}"
145150
CACHE PATH "CMake package config location relative to the install prefix"
146151
)
147152

test/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,24 @@ project(
1010

1111
if(TEST_INSTALLED_VERSION)
1212
find_package(dependency 1.2 REQUIRED)
13+
find_package(header_only 1.0 REQUIRED)
1314
find_package(namespaced_dependency 4.5.6 REQUIRED)
1415
find_package(transitive_dependency 7.8.9 REQUIRED)
1516
else()
1617
if(TEST_CPACK)
1718
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Foo Bar <foo@bar.local>")
1819
endif()
1920
add_subdirectory(dependency)
21+
add_subdirectory(header_only)
2022
add_subdirectory(namespaced_dependency)
2123
add_subdirectory(transitive_dependency)
2224
endif()
2325

2426
add_executable(main main.cpp)
2527

2628
target_link_libraries(
27-
main dependency ns::namespaced_dependency transitive_dependency::transitive_dependency
29+
main dependency header_only ns::namespaced_dependency
30+
transitive_dependency::transitive_dependency
2831
)
2932

3033
enable_testing()

test/header_only/CMakeLists.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
cmake_minimum_required(VERSION 3.14...3.22)
2+
3+
project(
4+
header_only
5+
VERSION 1.0
6+
LANGUAGES CXX
7+
DESCRIPTION "A header only dependency for testing PackageProject.cmake"
8+
)
9+
10+
add_library(${PROJECT_NAME} INTERFACE)
11+
12+
target_include_directories(
13+
dependency PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
14+
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
15+
)
16+
17+
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../.. PackageProject)
18+
19+
packageProject(
20+
NAME ${PROJECT_NAME}
21+
VERSION ${PROJECT_VERSION}
22+
BINARY_DIR ${PROJECT_BINARY_DIR}
23+
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include
24+
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
25+
VERSION_HEADER "${PROJECT_NAME}/version.h"
26+
DEPENDENCIES ""
27+
CPACK "${TEST_CPACK}"
28+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
inline constexpr long add(int a, int b) { return a + b; }

test/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <dependency/dependency.h>
22
#include <dependency/version.h>
3+
#include <header_only/adder.h>
4+
#include <header_only/version.h>
35
#include <namespaced_dependency/namespaced_dependency.h>
46
#include <namespaced_dependency/version.h>
57
#include <transitive_dependency/transitive_dependency.h>
@@ -27,5 +29,11 @@ int main() {
2729
result &= TRANSITIVE_DEPENDENCY_VERSION_MINOR == 8;
2830
result &= TRANSITIVE_DEPENDENCY_VERSION_PATCH == 9;
2931
result &= TRANSITIVE_DEPENDENCY_VERSION_TWEAK == 21948124;
32+
result &= (5 == add(2, 3));
33+
result &= HEADER_ONLY_VERSION == std::string("1.0");
34+
result &= HEADER_ONLY_VERSION_MAJOR == 1;
35+
result &= HEADER_ONLY_VERSION_MINOR == 0;
36+
result &= HEADER_ONLY_VERSION_PATCH == 0;
37+
result &= HEADER_ONLY_VERSION_TWEAK == 0;
3038
return result ? 0 : 1;
3139
}

0 commit comments

Comments
 (0)