Skip to content

Commit 25eb195

Browse files
committed
[ci] Test cmake integration
1 parent a58cfe4 commit 25eb195

5 files changed

Lines changed: 278 additions & 0 deletions

File tree

.github/workflows/test.yml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,121 @@ jobs:
7878

7979
- name: Build (Release)
8080
run: cmake --build build/${{ matrix.preset }} --config Release
81+
82+
# -----------------------------------------------------------------------
83+
# Shared library build
84+
# -----------------------------------------------------------------------
85+
- name: Configure (shared)
86+
run: cmake --preset ${{ matrix.preset }} -B build/${{ matrix.preset }}-shared
87+
-DBUILD_SHARED_LIBS=ON
88+
89+
- name: Build (Debug, shared)
90+
run: cmake --build build/${{ matrix.preset }}-shared --config Debug
91+
92+
- name: Run example (Debug, shared)
93+
continue-on-error: true
94+
shell: bash
95+
run: build/${{ matrix.preset }}-shared/example/Debug/eggs_assert_example
96+
97+
- name: Build (Release, shared)
98+
run: cmake --build build/${{ matrix.preset }}-shared --config Release
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_ASSERT_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+
- name: Test Consumer (FetchContent, shared) — Configure
121+
working-directory: test/cmake-fetch_content
122+
run: cmake --preset ${{ matrix.preset }} -B build-consumer-fetch_content-shared
123+
-DEGGS_ASSERT_SOURCE_DIR=${{ github.workspace }}
124+
-DEGGS_ASSERT_BUILD_SHARED_LIBS=ON
125+
126+
- name: Test Consumer (FetchContent, shared) — Build
127+
working-directory: test/cmake-fetch_content
128+
run: cmake --build build-consumer-fetch_content-shared --config Debug
129+
130+
- name: Test Consumer (FetchContent, shared) — Test
131+
working-directory: test/cmake-fetch_content
132+
run: ctest --test-dir build-consumer-fetch_content-shared --build-config Debug
133+
--output-on-failure
134+
135+
# -----------------------------------------------------------------------
136+
# Install variant — simulates a real end-user find_package workflow
137+
# -----------------------------------------------------------------------
138+
- name: Test Install (static)
139+
run: cmake --install build/${{ matrix.preset }}
140+
--prefix ${{ runner.temp }}/eggs-assert-install-static
141+
--config Release
142+
143+
- name: Upload installed package (static)
144+
uses: actions/upload-artifact@v6
145+
with:
146+
name: installed-package-static-${{ matrix.compiler }}
147+
path: ${{ runner.temp }}/eggs-assert-install-static
148+
if-no-files-found: error
149+
retention-days: 7
150+
151+
- name: Test Install (shared)
152+
run: cmake --install build/${{ matrix.preset }}-shared
153+
--prefix ${{ runner.temp }}/eggs-assert-install-shared
154+
--config Release
155+
156+
- name: Upload installed package (shared)
157+
uses: actions/upload-artifact@v6
158+
with:
159+
name: installed-package-shared-${{ matrix.compiler }}
160+
path: ${{ runner.temp }}/eggs-assert-install-shared
161+
if-no-files-found: error
162+
retention-days: 7
163+
164+
- name: Clean Source and Build Tree
165+
run: cmake -E rm -rf ./include ./src ./build
166+
167+
- name: Copy Preset (find_package)
168+
run: cp ./CMakePresets.json test/cmake-find_package
169+
170+
- name: Test Consumer (find_package, static) — Configure
171+
working-directory: test/cmake-find_package
172+
run: cmake --preset ${{ matrix.preset }} -B build-consumer-find_package-static
173+
-DCMAKE_PREFIX_PATH=${{ runner.temp }}/eggs-assert-install-static
174+
--debug-find-pkg=Eggs.Assert
175+
176+
- name: Test Consumer (find_package, static) — Build
177+
working-directory: test/cmake-find_package
178+
run: cmake --build build-consumer-find_package-static --config Debug
179+
180+
- name: Test Consumer (find_package, static) — Test
181+
working-directory: test/cmake-find_package
182+
run: ctest --test-dir build-consumer-find_package-static --build-config Debug
183+
--output-on-failure
184+
185+
- name: Test Consumer (find_package, shared) — Configure
186+
working-directory: test/cmake-find_package
187+
run: cmake --preset ${{ matrix.preset }} -B build-consumer-find_package-shared
188+
-DCMAKE_PREFIX_PATH=${{ runner.temp }}/eggs-assert-install-shared
189+
--debug-find-pkg=Eggs.Assert
190+
191+
- name: Test Consumer (find_package, shared) — Build
192+
working-directory: test/cmake-find_package
193+
run: cmake --build build-consumer-find_package-shared --config Debug
194+
195+
- name: Test Consumer (find_package, shared) — Test
196+
working-directory: test/cmake-find_package
197+
run: ctest --test-dir build-consumer-find_package-shared --build-config Debug
198+
--output-on-failure

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ if(ENABLE_INSTALL)
9292
TARGETS _eggs_assert
9393
EXPORT EggsAssertTargets
9494
FILE_SET HEADERS DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
95+
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
9596
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
9697
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
9798
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Eggs.Assert
2+
#
3+
# Copyright Agustin K-ballo Berge, Fusion Fenix 2026
4+
#
5+
# Distributed under the Boost Software License, Version 1.0. (See accompanying
6+
# file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7+
8+
cmake_minimum_required(VERSION 3.25)
9+
project(Eggs.Assert-FetchContent LANGUAGES CXX)
10+
11+
# -------------------------------------------------------------------------
12+
# EGGS_ASSERT_SOURCE_DIR is injected by the CTest fixture so that this
13+
# consumer always tests the local working tree, not a remote tag.
14+
# -------------------------------------------------------------------------
15+
if(NOT DEFINED EGGS_ASSERT_SOURCE_DIR)
16+
message(
17+
FATAL_ERROR
18+
"EGGS_ASSERT_SOURCE_DIR must be set. "
19+
"Pass -DEGGS_ASSERT_SOURCE_DIR=<path> to cmake."
20+
)
21+
endif()
22+
file(TO_CMAKE_PATH "${EGGS_ASSERT_SOURCE_DIR}" EGGS_ASSERT_SOURCE_DIR)
23+
24+
include(FetchContent)
25+
FetchContent_Declare(Eggs.Assert SOURCE_DIR "${EGGS_ASSERT_SOURCE_DIR}")
26+
FetchContent_MakeAvailable(Eggs.Assert)
27+
28+
# -------------------------------------------------------------------------
29+
# Verification target — links against the FetchContent target and runs.
30+
# -------------------------------------------------------------------------
31+
add_executable(consumer_verify ../../example/main.cpp)
32+
target_link_libraries(consumer_verify PRIVATE Eggs::Assert)
33+
34+
get_target_property(_assert_type Eggs::Assert TYPE)
35+
if(_assert_type STREQUAL "SHARED_LIBRARY")
36+
if(WIN32)
37+
add_custom_command(
38+
TARGET consumer_verify
39+
POST_BUILD
40+
COMMAND
41+
${CMAKE_COMMAND} -E copy_if_different
42+
$<TARGET_FILE:Eggs::Assert> $<TARGET_FILE_DIR:consumer_verify>
43+
)
44+
else()
45+
set_target_properties(
46+
consumer_verify
47+
PROPERTIES BUILD_RPATH "$<TARGET_FILE_DIR:Eggs::Assert>"
48+
)
49+
endif()
50+
endif()
51+
52+
# -------------------------------------------------------------------------
53+
# Confirm that the FetchContent target exposes the same properties as the
54+
# installed one (no accidental in-tree-only paths).
55+
# -------------------------------------------------------------------------
56+
foreach(
57+
_prop
58+
IN
59+
ITEMS
60+
INTERFACE_INCLUDE_DIRECTORIES
61+
INTERFACE_COMPILE_DEFINITIONS
62+
INTERFACE_COMPILE_FEATURES
63+
INTERFACE_LINK_LIBRARIES
64+
)
65+
get_target_property(_val Eggs::Assert ${_prop})
66+
message(STATUS "Eggs::Assert (FetchContent) ${_prop}: ${_val}")
67+
endforeach()
68+
69+
enable_testing()
70+
add_test(
71+
NAME verify
72+
COMMAND
73+
${CMAKE_COMMAND} -DCMD=$<TARGET_FILE:consumer_verify>
74+
-DEXPECT_CRASH=$<CONFIG:Debug> -P
75+
"${CMAKE_CURRENT_SOURCE_DIR}/../run_verify.cmake"
76+
)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Eggs.Assert
2+
#
3+
# Copyright Agustin K-ballo Berge, Fusion Fenix 2026
4+
#
5+
# Distributed under the Boost Software License, Version 1.0. (See accompanying
6+
# file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7+
8+
cmake_minimum_required(VERSION 3.25)
9+
project(Eggs.Assert-FindPackage LANGUAGES CXX)
10+
11+
# -------------------------------------------------------------------------
12+
# Find the installed package exactly as an end-user would.
13+
# -------------------------------------------------------------------------
14+
find_package(Eggs.Assert REQUIRED)
15+
16+
# -------------------------------------------------------------------------
17+
# Verification target — links against the imported target and runs.
18+
# -------------------------------------------------------------------------
19+
add_executable(consumer_verify ../../example/main.cpp)
20+
target_link_libraries(consumer_verify PRIVATE Eggs::Assert)
21+
22+
get_target_property(_assert_type Eggs::Assert TYPE)
23+
if(_assert_type STREQUAL "SHARED_LIBRARY")
24+
if(WIN32)
25+
add_custom_command(
26+
TARGET consumer_verify
27+
POST_BUILD
28+
COMMAND
29+
${CMAKE_COMMAND} -E copy_if_different
30+
$<TARGET_FILE:Eggs::Assert> $<TARGET_FILE_DIR:consumer_verify>
31+
)
32+
else()
33+
set_target_properties(
34+
consumer_verify
35+
PROPERTIES BUILD_RPATH "$<TARGET_FILE_DIR:Eggs::Assert>"
36+
)
37+
endif()
38+
endif()
39+
40+
# -------------------------------------------------------------------------
41+
# Print target properties at configure time so ctest -V shows them.
42+
# -------------------------------------------------------------------------
43+
foreach(
44+
_prop
45+
IN
46+
ITEMS
47+
INTERFACE_INCLUDE_DIRECTORIES
48+
INTERFACE_COMPILE_DEFINITIONS
49+
INTERFACE_COMPILE_FEATURES
50+
INTERFACE_LINK_LIBRARIES
51+
)
52+
get_target_property(_val Eggs::Assert ${_prop})
53+
message(STATUS "Eggs::Assert ${_prop}: ${_val}")
54+
endforeach()
55+
56+
enable_testing()
57+
add_test(
58+
NAME verify
59+
COMMAND
60+
${CMAKE_COMMAND} -DCMD=$<TARGET_FILE:consumer_verify>
61+
-DEXPECT_CRASH=$<CONFIG:Debug> -P
62+
"${CMAKE_CURRENT_SOURCE_DIR}/../run_verify.cmake"
63+
)

test/run_verify.cmake

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Eggs.Assert
2+
#
3+
# Copyright Agustin K-ballo Berge, Fusion Fenix 2026
4+
#
5+
# Distributed under the Boost Software License, Version 1.0. (See accompanying
6+
# file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7+
8+
# Runs CMD and verifies its exit behaviour:
9+
# EXPECT_CRASH=1 -> expects a non-zero / abort exit (Debug)
10+
# EXPECT_CRASH=0 -> expects a clean exit code 0 (Release)
11+
execute_process(COMMAND "${CMD}" RESULT_VARIABLE result)
12+
if(EXPECT_CRASH)
13+
if(result EQUAL 0)
14+
message(FATAL_ERROR "Expected abort but process exited 0")
15+
endif()
16+
else()
17+
if(NOT result EQUAL 0)
18+
message(FATAL_ERROR "Expected success but process exited: ${result}")
19+
endif()
20+
endif()

0 commit comments

Comments
 (0)