Skip to content

Commit 357844a

Browse files
committed
cmake: Add install target
We can now install the headers, which allows KDAlgorithms to be packaged by Brew and other package managers. Added a test, called by CI, which tests building a standalone example against a system-wide KDAlgorithms.
1 parent bb4443d commit 357844a

File tree

6 files changed

+110
-2
lines changed

6 files changed

+110
-2
lines changed

.github/workflows/build.yml

+10
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ jobs:
7777
-DCMAKE_BUILD_TYPE=Release
7878
-DBUILD_TESTING=ON
7979
-DKDALGORITHMS_BUILD_TEST=ON
80+
-DCMAKE_INSTALL_PREFIX=installed
8081
8182
- name: Build Project (Release)
8283
run: cmake --build ./build-release
@@ -85,6 +86,15 @@ jobs:
8586
id: tests2
8687
run: ctest --test-dir ./build-release -C Release --output-on-failure
8788

89+
- name: Install Project
90+
run: cmake --install ./build-release
91+
92+
- name: Build standalone example against systemwide KDAlgorithms
93+
run: |
94+
cd tests/test_install
95+
cmake -DCMAKE_PREFIX_PATH="../../installed" .
96+
cmake --build .
97+
8898
- name: Read tests log when it fails
8999
uses: andstor/file-reader-action@v1
90100
if: ${{ steps.tests1.outcome == 'failure' || steps.tests2.outcome == 'failure' }}

CMakeLists.txt

+52-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ endif()
99

1010
add_library(kdalgorithms INTERFACE)
1111
add_library(KDAB::KDAlgorithms ALIAS kdalgorithms)
12-
target_include_directories(kdalgorithms INTERFACE src/)
12+
target_include_directories(kdalgorithms INTERFACE
13+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
14+
$<INSTALL_INTERFACE:include>
15+
)
1316

1417
if(MSVC)
1518
target_compile_options(kdalgorithms INTERFACE /Zc:__cplusplus)
@@ -95,3 +98,51 @@ if(BUILD_TESTING AND ${KDALGORITHMS_BUILD_TEST})
9598

9699
add_subdirectory(Inspiration)
97100
endif()
101+
102+
install(TARGETS kdalgorithms EXPORT KDAlgorithmsTargets)
103+
104+
install(EXPORT KDAlgorithmsTargets
105+
FILE KDAlgorithmsTargets.cmake
106+
NAMESPACE KDAB::
107+
DESTINATION lib/cmake/KDAlgorithms
108+
)
109+
110+
install(FILES
111+
src/kdalgorithms.h
112+
DESTINATION include/kdalgorithms
113+
)
114+
115+
install(FILES
116+
src/kdalgorithms_bits/read_iterator_wrapper.h
117+
src/kdalgorithms_bits/find_if.h
118+
src/kdalgorithms_bits/filter.h
119+
src/kdalgorithms_bits/generate.h
120+
src/kdalgorithms_bits/insert_wrapper.h
121+
src/kdalgorithms_bits/is_const_method.h
122+
src/kdalgorithms_bits/is_detected.h
123+
src/kdalgorithms_bits/method_tests.h
124+
src/kdalgorithms_bits/operators.h
125+
src/kdalgorithms_bits/reserve_helper.h
126+
src/kdalgorithms_bits/return_type_trait.h
127+
src/kdalgorithms_bits/shared.h
128+
src/kdalgorithms_bits/to_function_object.h
129+
src/kdalgorithms_bits/transform.h
130+
src/kdalgorithms_bits/zip.h
131+
src/kdalgorithms_bits/tuple_utils.h
132+
src/kdalgorithms_bits/invoke.h
133+
src/kdalgorithms_bits/cartesian_product.h
134+
DESTINATION include/kdalgorithms/kdalgorithms_bits
135+
)
136+
137+
include(CMakePackageConfigHelpers)
138+
139+
configure_package_config_file(
140+
KDAlgorithmsConfig.cmake.in
141+
${CMAKE_CURRENT_BINARY_DIR}/KDAlgorithmsConfig.cmake
142+
INSTALL_DESTINATION lib/cmake/KDAlgorithms
143+
)
144+
145+
install(FILES
146+
${CMAKE_CURRENT_BINARY_DIR}/KDAlgorithmsConfig.cmake
147+
DESTINATION lib/cmake/KDAlgorithms
148+
)

KDAlgorithmsConfig.cmake.in

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
@PACKAGE_INIT@
3+
4+
include("${CMAKE_CURRENT_LIST_DIR}/KDAlgorithmsTargets.cmake")

REUSE.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ SPDX-PackageSupplier = "<[email protected]>"
44
SPDX-PackageDownloadLocation = "https://www.github.com/KDAB/KDAlgorithms"
55

66
[[annotations]]
7-
path = ["run", ".gitignore", "CMakeLists.txt", "CMakePresets.json", "README.md", "_clang-format", ".pre-commit-config.yaml", "appveyor.yml", "Documentation/**", "Example/CMakeLists.txt", "Inspiration/CMakeLists.txt", "REUSE.toml"]
7+
path = ["run", ".gitignore", "CMakeLists.txt", "KDAlgorithmsConfig.cmake.in", "CMakePresets.json", "README.md", "_clang-format", ".pre-commit-config.yaml", "appveyor.yml", "Documentation/**", "Example/CMakeLists.txt", "Inspiration/CMakeLists.txt", "tests/test_install/CMakeLists.txt", "REUSE.toml"]
88
precedence = "aggregate"
99
SPDX-FileCopyrightText = "2022 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>"
1010
SPDX-License-Identifier = "MIT"

tests/test_install/CMakeLists.txt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Tests that users can use find_package and "link" against KDAlgorithms target
2+
# This test is built by the GitHub CI workflow
3+
4+
cmake_minimum_required(VERSION 3.10)
5+
6+
project(test_find_package LANGUAGES CXX)
7+
8+
set(CMAKE_CXX_STANDARD 14)
9+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
10+
11+
find_package(KDAlgorithms REQUIRED)
12+
13+
add_executable(${PROJECT_NAME} main.cpp)
14+
15+
target_link_libraries(${PROJECT_NAME} PRIVATE KDAB::kdalgorithms)

tests/test_install/main.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/****************************************************************************
2+
**
3+
** This file is part of KDAlgorithms
4+
**
5+
** SPDX-FileCopyrightText: 2022 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
6+
**
7+
** SPDX-License-Identifier: MIT
8+
**
9+
****************************************************************************/
10+
11+
#include <kdalgorithms/kdalgorithms.h>
12+
13+
#include <iostream>
14+
#include <string>
15+
#include <vector>
16+
17+
int main()
18+
{
19+
auto vec = kdalgorithms::iota(1, 100);
20+
auto odds = kdalgorithms::filtered(vec, [](int i) { return i % 2 == 1; });
21+
auto result = kdalgorithms::accumulate(odds, [](const std::string &partial, int value) {
22+
return partial + "," + std::to_string(value);
23+
});
24+
25+
std::cout << result << "\n";
26+
27+
return 0;
28+
}

0 commit comments

Comments
 (0)