Skip to content

Commit cb4ff7a

Browse files
committed
[ci] Test cmake integration
1 parent 6c53389 commit cb4ff7a

4 files changed

Lines changed: 162 additions & 1 deletion

File tree

.github/workflows/test.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ jobs:
6262
if: runner.os == 'Linux'
6363
run: sudo apt-get install -y ninja-build
6464

65+
- name: Check CMake Version
66+
run: cmake --version
67+
68+
# -----------------------------------------------------------------------
69+
# Main project
70+
# -----------------------------------------------------------------------
6571
- name: Configure
6672
run: cmake --preset ${{ matrix.preset }} -B build/${{ matrix.preset }}
6773

@@ -90,3 +96,60 @@ jobs:
9096
name: test-results-${{ matrix.compiler }}
9197
path: build/${{ matrix.preset }}/test-results-*.xml
9298
retention-days: 30
99+
100+
# -----------------------------------------------------------------------
101+
# FetchContent variant — simulates embedding via FetchContent_MakeAvailable
102+
# -----------------------------------------------------------------------
103+
- name: Copy Preset (FetchContent)
104+
run: cp ./CMakePresets.json test/cmake-fetch_content
105+
106+
- name: Test Consumer (FetchContent) — Configure
107+
working-directory: test/cmake-fetch_content
108+
run: cmake --preset ${{ matrix.preset }} -B build-consumer-fetch_content
109+
-DEGGS_FLAT_MAP_SOURCE_DIR=${{ github.workspace }}
110+
111+
- name: Test Consumer (FetchContent) — Build
112+
working-directory: test/cmake-fetch_content
113+
run: cmake --build build-consumer-fetch_content --config Debug
114+
115+
- name: Test Consumer (FetchContent) — Test
116+
working-directory: test/cmake-fetch_content
117+
run: ctest --test-dir build-consumer-fetch_content --build-config Debug
118+
--output-on-failure
119+
120+
# -----------------------------------------------------------------------
121+
# Install variant — simulates a real end-user find_package workflow
122+
# -----------------------------------------------------------------------
123+
- name: Test Install
124+
run: cmake --install build/${{ matrix.preset }}
125+
--prefix ${{ runner.temp }}/eggs-flat_map-install
126+
--config Release
127+
128+
- name: Upload installed package
129+
uses: actions/upload-artifact@v6
130+
with:
131+
name: installed-package-${{ matrix.compiler }}
132+
path: ${{ runner.temp }}/eggs-flat_map-install
133+
if-no-files-found: error
134+
retention-days: 7
135+
136+
- name: Clean Source and Build Tree
137+
run: cmake -E rm -rf ./include ./src ./build
138+
139+
- name: Copy Preset (find_package)
140+
run: cp ./CMakePresets.json test/cmake-find_package
141+
142+
- name: Test Consumer (find_package) — Configure
143+
working-directory: test/cmake-find_package
144+
run: cmake --preset ${{ matrix.preset }} -B build-consumer-find_package
145+
-DCMAKE_PREFIX_PATH=${{ runner.temp }}/eggs-flat_map-install
146+
--debug-find-pkg=Eggs.FlatMap
147+
148+
- name: Test Consumer (find_package) — Build
149+
working-directory: test/cmake-find_package
150+
run: cmake --build build-consumer-find_package --config Debug
151+
152+
- name: Test Consumer (find_package) — Test
153+
working-directory: test/cmake-find_package
154+
run: ctest --test-dir build-consumer-find_package --build-config Debug
155+
--output-on-failure

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ endif()
6161
if(ENABLE_INSTALL)
6262
include(CMakePackageConfigHelpers)
6363

64-
install(TARGETS _eggs_flat_map EXPORT Eggs::FlatMap FILE_SET HEADERS)
64+
install(
65+
TARGETS _eggs_flat_map
66+
EXPORT Eggs::FlatMap
67+
FILE_SET HEADERS
68+
INCLUDES DESTINATION include
69+
)
6570

6671
install(
6772
EXPORT Eggs::FlatMap
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright Agustin K-ballo Berge, Fusion Fenix 2026
2+
#
3+
# Distributed under the Boost Software License, Version 1.0. (See accompanying
4+
# file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5+
6+
cmake_minimum_required(VERSION 3.25)
7+
project(Eggs::FlatMap-FetchContent CXX)
8+
9+
# -------------------------------------------------------------------------
10+
# EGGS_FlatMap_SOURCE_DIR is injected by the CTest fixture so that this
11+
# consumer always tests the local working tree, not a remote tag.
12+
# -------------------------------------------------------------------------
13+
if(NOT DEFINED EGGS_FLAT_MAP_SOURCE_DIR)
14+
message(
15+
FATAL_ERROR
16+
"EGGS_FLAT_MAP_SOURCE_DIR must be set. "
17+
"Pass -DEGGS_FLAT_MAP_SOURCE_DIR=<path> to cmake."
18+
)
19+
endif()
20+
file(TO_CMAKE_PATH "${EGGS_FLAT_MAP_SOURCE_DIR}" EGGS_FLAT_MAP_SOURCE_DIR)
21+
22+
include(FetchContent)
23+
FetchContent_Declare(Eggs.FlatMap SOURCE_DIR "${EGGS_FLAT_MAP_SOURCE_DIR}")
24+
FetchContent_MakeAvailable(Eggs.FlatMap)
25+
26+
# -------------------------------------------------------------------------
27+
# Verification target — identical intent to the install consumer, but this
28+
# time the target comes from FetchContent rather than an installed config.
29+
# -------------------------------------------------------------------------
30+
add_executable(consumer_verify ../../example/entity_db.cpp)
31+
target_link_libraries(consumer_verify PRIVATE Eggs::FlatMap)
32+
33+
# -------------------------------------------------------------------------
34+
# Confirm that the FetchContent target exposes the same properties as the
35+
# installed one (no accidental in-tree-only paths).
36+
# -------------------------------------------------------------------------
37+
foreach(
38+
_prop
39+
IN
40+
ITEMS
41+
INTERFACE_INCLUDE_DIRECTORIES
42+
INTERFACE_COMPILE_DEFINITIONS
43+
INTERFACE_COMPILE_FEATURES
44+
INTERFACE_LINK_LIBRARIES
45+
)
46+
get_target_property(_val Eggs::FlatMap ${_prop})
47+
message(STATUS "Eggs::FlatMap (FetchContent) ${_prop}: ${_val}")
48+
endforeach()
49+
50+
# Make the verify binary a ctest too
51+
enable_testing()
52+
add_test(NAME verify COMMAND consumer_verify)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright Agustin K-ballo Berge, Fusion Fenix 2026
2+
#
3+
# Distributed under the Boost Software License, Version 1.0. (See accompanying
4+
# file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5+
6+
cmake_minimum_required(VERSION 3.25)
7+
project(Eggs::FlatMap-FindPackage CXX)
8+
9+
# -------------------------------------------------------------------------
10+
# Find the installed package exactly as an end-user would
11+
# -------------------------------------------------------------------------
12+
find_package(Eggs.FlatMap REQUIRED)
13+
14+
# -------------------------------------------------------------------------
15+
# Verification target
16+
# Compiles a minimal translation unit that exercises the interface headers
17+
# and verifies INTERFACE_COMPILE_DEFINITIONS / INTERFACE_INCLUDE_DIRECTORIES
18+
# were exported correctly.
19+
# -------------------------------------------------------------------------
20+
add_executable(consumer_verify ../../example/entity_db.cpp)
21+
target_link_libraries(consumer_verify PRIVATE Eggs::FlatMap)
22+
23+
# -------------------------------------------------------------------------
24+
# Print target properties at configure time so ctest -V shows them
25+
# -------------------------------------------------------------------------
26+
foreach(
27+
_prop
28+
IN
29+
ITEMS
30+
INTERFACE_INCLUDE_DIRECTORIES
31+
INTERFACE_COMPILE_DEFINITIONS
32+
INTERFACE_COMPILE_FEATURES
33+
INTERFACE_LINK_LIBRARIES
34+
)
35+
get_target_property(_val Eggs::FlatMap ${_prop})
36+
message(STATUS "Eggs::FlatMap ${_prop}: ${_val}")
37+
endforeach()
38+
39+
# Make the verify binary a ctest too
40+
enable_testing()
41+
add_test(NAME verify COMMAND consumer_verify)

0 commit comments

Comments
 (0)