Skip to content

Commit 08e5e5a

Browse files
committed
[ci] Test cmake integration
1 parent 40b1212 commit 08e5e5a

5 files changed

Lines changed: 358 additions & 8 deletions

File tree

‎.github/workflows/test.yml‎

Lines changed: 185 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,193 @@ jobs:
6565
- name: Check CMake Version
6666
run: cmake --version
6767

68-
- name: Configure
69-
run: cmake --preset ${{ matrix.preset }} -B build/${{ matrix.preset }}
68+
# -----------------------------------------------------------------------
69+
# Static library build
70+
# -----------------------------------------------------------------------
71+
- name: Configure (static)
72+
run: cmake --preset ${{ matrix.preset }} -B build/${{ matrix.preset }}-static
7073

71-
- name: Build (Debug)
72-
run: cmake --build build/${{ matrix.preset }} --config Debug
74+
- name: Build (static, Debug)
75+
run: cmake --build build/${{ matrix.preset }}-static --config Debug
7376

74-
- name: Run example (Debug)
77+
- name: Run example (static, Debug)
7578
continue-on-error: true
7679
shell: bash
77-
run: build/${{ matrix.preset }}/example/Debug/eggs_assert_example
80+
run: build/${{ matrix.preset }}-static/example/Debug/eggs_assert_example
7881

79-
- name: Build (Release)
80-
run: cmake --build build/${{ matrix.preset }} --config Release
82+
- name: Build (static, Release)
83+
run: cmake --build build/${{ matrix.preset }}-static --config Release
84+
85+
# -----------------------------------------------------------------------
86+
# Shared library build
87+
# -----------------------------------------------------------------------
88+
- name: Configure (shared)
89+
run: cmake --preset ${{ matrix.preset }} -B build/${{ matrix.preset }}-shared
90+
-DBUILD_SHARED_LIBS=ON
91+
92+
- name: Build (shared, Debug)
93+
run: cmake --build build/${{ matrix.preset }}-shared --config Debug
94+
95+
- name: Run example (shared, Debug)
96+
continue-on-error: true
97+
shell: bash
98+
run: |
99+
[ "$RUNNER_OS" = "Windows" ] && cp build/${{ matrix.preset }}-shared/Debug/*.dll build/${{ matrix.preset }}-shared/example/Debug/
100+
build/${{ matrix.preset }}-shared/example/Debug/eggs_assert_example
101+
102+
- name: Build (shared, Release)
103+
run: cmake --build build/${{ matrix.preset }}-shared --config Release
104+
105+
# -----------------------------------------------------------------------
106+
# FetchContent variant — simulates embedding via FetchContent_MakeAvailable
107+
# -----------------------------------------------------------------------
108+
- name: Copy Preset (FetchContent)
109+
run: |
110+
cp ./CMakePresets.json test/cmake-fetch_content
111+
cp ./example/main.cpp test/cmake-fetch_content
112+
113+
- name: Test Consumer (FetchContent, static) — Configure
114+
working-directory: test/cmake-fetch_content
115+
run: cmake --preset ${{ matrix.preset }} -B build-consumer-fetch_content
116+
-DEGGS_ASSERT_SOURCE_DIR=${{ github.workspace }}
117+
118+
- name: Test Consumer (FetchContent, static) — Build
119+
working-directory: test/cmake-fetch_content
120+
run: cmake --build build-consumer-fetch_content --config Debug
121+
122+
- name: Test Consumer (FetchContent, static) — Test
123+
working-directory: test/cmake-fetch_content
124+
run: ctest --test-dir build-consumer-fetch_content --build-config Debug -V
125+
126+
- name: Test Consumer (FetchContent, shared) — Configure
127+
working-directory: test/cmake-fetch_content
128+
run: cmake --preset ${{ matrix.preset }} -B build-consumer-fetch_content-shared
129+
-DEGGS_ASSERT_SOURCE_DIR=${{ github.workspace }}
130+
-DEGGS_ASSERT_BUILD_SHARED_LIBS=ON
131+
132+
- name: Test Consumer (FetchContent, shared) — Build
133+
working-directory: test/cmake-fetch_content
134+
run: cmake --build build-consumer-fetch_content-shared --config Debug
135+
136+
- name: Test Consumer (FetchContent, shared) — Test
137+
working-directory: test/cmake-fetch_content
138+
run: ctest --test-dir build-consumer-fetch_content-shared --build-config Debug -V
139+
140+
# -----------------------------------------------------------------------
141+
# Install variant — simulates a real end-user find_package workflow
142+
# -----------------------------------------------------------------------
143+
- name: Test Install (static, Debug)
144+
run: cmake --install build/${{ matrix.preset }}-static
145+
--prefix ${{ runner.temp }}/eggs-assert-install-static-debug
146+
--config Debug
147+
148+
- name: Upload installed package (static, Debug)
149+
uses: actions/upload-artifact@v6
150+
with:
151+
name: installed-package-${{ matrix.compiler }}-static-debug
152+
path: ${{ runner.temp }}/eggs-assert-install-static-debug
153+
if-no-files-found: error
154+
retention-days: 7
155+
156+
- name: Test Install (static, Release)
157+
run: cmake --install build/${{ matrix.preset }}-static
158+
--prefix ${{ runner.temp }}/eggs-assert-install-static-release
159+
--config Release
160+
161+
- name: Upload installed package (static, Release)
162+
uses: actions/upload-artifact@v6
163+
with:
164+
name: installed-package-${{ matrix.compiler }}-static-release
165+
path: ${{ runner.temp }}/eggs-assert-install-static-release
166+
if-no-files-found: error
167+
retention-days: 7
168+
169+
- name: Test Install (shared, Debug)
170+
run: cmake --install build/${{ matrix.preset }}-shared
171+
--prefix ${{ runner.temp }}/eggs-assert-install-shared-debug
172+
--config Debug
173+
174+
- name: Upload installed package (shared, Debug)
175+
uses: actions/upload-artifact@v6
176+
with:
177+
name: installed-package-${{ matrix.compiler }}-shared-debug
178+
path: ${{ runner.temp }}/eggs-assert-install-shared-debug
179+
if-no-files-found: error
180+
retention-days: 7
181+
182+
- name: Test Install (shared, Release)
183+
run: cmake --install build/${{ matrix.preset }}-shared
184+
--prefix ${{ runner.temp }}/eggs-assert-install-shared-release
185+
--config Release
186+
187+
- name: Upload installed package (shared, Release)
188+
uses: actions/upload-artifact@v6
189+
with:
190+
name: installed-package-${{ matrix.compiler }}-shared-release
191+
path: ${{ runner.temp }}/eggs-assert-install-shared-release
192+
if-no-files-found: error
193+
retention-days: 7
194+
195+
- name: Clean Source and Build Tree
196+
run: cmake -E rm -rf ./include ./src ./build
197+
198+
- name: Copy Preset (find_package)
199+
run: |
200+
cp ./CMakePresets.json test/cmake-find_package
201+
cp ./example/main.cpp test/cmake-find_package
202+
203+
- name: Test Consumer (find_package, static, Debug) — Configure
204+
working-directory: test/cmake-find_package
205+
run: cmake --preset ${{ matrix.preset }} -B build-consumer-find_package-static-debug
206+
-DCMAKE_PREFIX_PATH=${{ runner.temp }}/eggs-assert-install-static-debug
207+
--debug-find-pkg=Eggs.Assert
208+
209+
- name: Test Consumer (find_package, static, Debug) — Build
210+
working-directory: test/cmake-find_package
211+
run: cmake --build build-consumer-find_package-static-debug --config Debug
212+
213+
- name: Test Consumer (find_package, static, Debug) — Test
214+
working-directory: test/cmake-find_package
215+
run: ctest --test-dir build-consumer-find_package-static-debug --build-config Debug -V
216+
217+
- name: Test Consumer (find_package, static, Release) — Configure
218+
working-directory: test/cmake-find_package
219+
run: cmake --preset ${{ matrix.preset }} -B build-consumer-find_package-static-release
220+
-DCMAKE_PREFIX_PATH=${{ runner.temp }}/eggs-assert-install-static-release
221+
--debug-find-pkg=Eggs.Assert
222+
223+
- name: Test Consumer (find_package, static, Release) — Build
224+
working-directory: test/cmake-find_package
225+
run: cmake --build build-consumer-find_package-static-release --config Release
226+
227+
- name: Test Consumer (find_package, static, Release) — Test
228+
working-directory: test/cmake-find_package
229+
run: ctest --test-dir build-consumer-find_package-static-release --build-config Release -V
230+
231+
- name: Test Consumer (find_package, shared, Debug) — Configure
232+
working-directory: test/cmake-find_package
233+
run: cmake --preset ${{ matrix.preset }} -B build-consumer-find_package-shared-debug
234+
-DCMAKE_PREFIX_PATH=${{ runner.temp }}/eggs-assert-install-shared-debug
235+
--debug-find-pkg=Eggs.Assert
236+
237+
- name: Test Consumer (find_package, shared, Debug) — Build
238+
working-directory: test/cmake-find_package
239+
run: cmake --build build-consumer-find_package-shared-debug --config Debug
240+
241+
- name: Test Consumer (find_package, shared, Debug) — Test
242+
working-directory: test/cmake-find_package
243+
run: ctest --test-dir build-consumer-find_package-shared-debug --build-config Debug -V
244+
245+
- name: Test Consumer (find_package, shared, Release) — Configure
246+
working-directory: test/cmake-find_package
247+
run: cmake --preset ${{ matrix.preset }} -B build-consumer-find_package-shared-release
248+
-DCMAKE_PREFIX_PATH=${{ runner.temp }}/eggs-assert-install-shared-release
249+
--debug-find-pkg=Eggs.Assert
250+
251+
- name: Test Consumer (find_package, shared, Release) — Build
252+
working-directory: test/cmake-find_package
253+
run: cmake --build build-consumer-find_package-shared-release --config Release
254+
255+
- name: Test Consumer (find_package, shared, Release) — Test
256+
working-directory: test/cmake-find_package
257+
run: ctest --test-dir build-consumer-find_package-shared-release --build-config Release -V

‎CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ if(ENABLE_INSTALL)
107107
TARGETS _eggs_assert
108108
EXPORT EggsAssertTargets
109109
FILE_SET HEADERS DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
110+
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
110111
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
111112
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
112113
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT
12+
"$<$<CONFIG:Debug,RelWithDebInfo>:Embedded>"
13+
)
14+
15+
# -------------------------------------------------------------------------
16+
# EGGS_ASSERT_SOURCE_DIR is injected by the CTest fixture so that this
17+
# consumer always tests the local working tree, not a remote tag.
18+
# -------------------------------------------------------------------------
19+
if(NOT DEFINED EGGS_ASSERT_SOURCE_DIR)
20+
message(
21+
FATAL_ERROR
22+
"EGGS_ASSERT_SOURCE_DIR must be set. "
23+
"Pass -DEGGS_ASSERT_SOURCE_DIR=<path> to cmake."
24+
)
25+
endif()
26+
file(TO_CMAKE_PATH "${EGGS_ASSERT_SOURCE_DIR}" EGGS_ASSERT_SOURCE_DIR)
27+
28+
include(FetchContent)
29+
FetchContent_Declare(Eggs.Assert SOURCE_DIR "${EGGS_ASSERT_SOURCE_DIR}")
30+
FetchContent_MakeAvailable(Eggs.Assert)
31+
32+
# -------------------------------------------------------------------------
33+
# Verification target — links against the FetchContent target and runs.
34+
# -------------------------------------------------------------------------
35+
add_executable(consumer_verify main.cpp)
36+
target_link_libraries(consumer_verify PRIVATE Eggs::Assert)
37+
38+
get_target_property(_assert_type Eggs::Assert TYPE)
39+
if(_assert_type STREQUAL "SHARED_LIBRARY")
40+
if(WIN32)
41+
add_custom_command(
42+
TARGET consumer_verify
43+
POST_BUILD
44+
COMMAND
45+
${CMAKE_COMMAND} -E copy_if_different
46+
$<TARGET_FILE:Eggs::Assert> $<TARGET_FILE_DIR:consumer_verify>
47+
)
48+
else()
49+
set_target_properties(
50+
consumer_verify
51+
PROPERTIES BUILD_RPATH "$<TARGET_FILE_DIR:Eggs::Assert>"
52+
)
53+
endif()
54+
endif()
55+
56+
# -------------------------------------------------------------------------
57+
# Confirm that the FetchContent target exposes the same properties as the
58+
# installed one (no accidental in-tree-only paths).
59+
# -------------------------------------------------------------------------
60+
foreach(
61+
_prop
62+
IN
63+
ITEMS
64+
INTERFACE_INCLUDE_DIRECTORIES
65+
INTERFACE_COMPILE_DEFINITIONS
66+
INTERFACE_COMPILE_FEATURES
67+
INTERFACE_LINK_LIBRARIES
68+
)
69+
get_target_property(_val Eggs::Assert ${_prop})
70+
message(STATUS "Eggs::Assert (FetchContent) ${_prop}: ${_val}")
71+
endforeach()
72+
73+
enable_testing()
74+
add_test(
75+
NAME verify
76+
COMMAND
77+
${CMAKE_COMMAND} -DCMD=$<TARGET_FILE:consumer_verify>
78+
-DEXPECT_CRASH=$<CONFIG:Debug> -P
79+
"${CMAKE_CURRENT_SOURCE_DIR}/../run_verify.cmake"
80+
)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT
12+
"$<$<CONFIG:Debug,RelWithDebInfo>:Embedded>"
13+
)
14+
15+
# -------------------------------------------------------------------------
16+
# Find the installed package exactly as an end-user would.
17+
# -------------------------------------------------------------------------
18+
find_package(Eggs.Assert REQUIRED)
19+
20+
# -------------------------------------------------------------------------
21+
# Verification target — links against the imported target and runs.
22+
# -------------------------------------------------------------------------
23+
add_executable(consumer_verify main.cpp)
24+
target_link_libraries(consumer_verify PRIVATE Eggs::Assert)
25+
26+
get_target_property(_assert_type Eggs::Assert TYPE)
27+
if(_assert_type STREQUAL "SHARED_LIBRARY")
28+
if(WIN32)
29+
add_custom_command(
30+
TARGET consumer_verify
31+
POST_BUILD
32+
COMMAND
33+
${CMAKE_COMMAND} -E copy_if_different
34+
$<TARGET_FILE:Eggs::Assert> $<TARGET_FILE_DIR:consumer_verify>
35+
)
36+
else()
37+
set_target_properties(
38+
consumer_verify
39+
PROPERTIES BUILD_RPATH "$<TARGET_FILE_DIR:Eggs::Assert>"
40+
)
41+
endif()
42+
endif()
43+
44+
# -------------------------------------------------------------------------
45+
# Print target properties at configure time so ctest -V shows them.
46+
# -------------------------------------------------------------------------
47+
foreach(
48+
_prop
49+
IN
50+
ITEMS
51+
INTERFACE_INCLUDE_DIRECTORIES
52+
INTERFACE_COMPILE_DEFINITIONS
53+
INTERFACE_COMPILE_FEATURES
54+
INTERFACE_LINK_LIBRARIES
55+
)
56+
get_target_property(_val Eggs::Assert ${_prop})
57+
message(STATUS "Eggs::Assert ${_prop}: ${_val}")
58+
endforeach()
59+
60+
enable_testing()
61+
add_test(
62+
NAME verify
63+
COMMAND
64+
${CMAKE_COMMAND} -DCMD=$<TARGET_FILE:consumer_verify>
65+
-DEXPECT_CRASH=$<CONFIG:Debug> -P
66+
"${CMAKE_CURRENT_SOURCE_DIR}/../run_verify.cmake"
67+
)

‎test/run_verify.cmake‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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(
12+
COMMAND "${CMD}"
13+
ECHO_OUTPUT_VARIABLE
14+
ECHO_ERROR_VARIABLE
15+
RESULT_VARIABLE result
16+
)
17+
if(EXPECT_CRASH)
18+
if(result EQUAL 0)
19+
message(FATAL_ERROR "Expected abort but process exited 0")
20+
endif()
21+
else()
22+
if(NOT result EQUAL 0)
23+
message(FATAL_ERROR "Expected success but process exited: ${result}")
24+
endif()
25+
endif()

0 commit comments

Comments
 (0)