Skip to content

Commit a43a64f

Browse files
Mikael Zayenz Lagerkvistzayenz
authored andcommitted
Respect features when building CMake examples
1 parent cc4c6d1 commit a43a64f

5 files changed

Lines changed: 79 additions & 6 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
source_dir="${GITHUB_WORKSPACE:-$(pwd)}"
5+
build_root="${RUNNER_TEMP:-/tmp}/gecode-example-features"
6+
7+
rm -rf "$build_root"
8+
9+
cmake -S "$source_dir" -B "$build_root/int" -G Ninja \
10+
-DGECODE_ENABLE_EXAMPLES=ON \
11+
-DGECODE_ENABLE_SET_VARS=OFF \
12+
-DGECODE_ENABLE_FLOAT_VARS=OFF \
13+
-DGECODE_ENABLE_FLATZINC=OFF \
14+
-DGECODE_ENABLE_QT=OFF \
15+
-DGECODE_ENABLE_GIST=OFF
16+
17+
grep -q '^GECODE_ENABLE_SET_VARS:BOOL=OFF$' "$build_root/int/CMakeCache.txt"
18+
grep -q '^GECODE_ENABLE_FLOAT_VARS:BOOL=OFF$' "$build_root/int/CMakeCache.txt"
19+
cmake --build "$build_root/int" --target help > "$build_root/int-targets.txt"
20+
grep -q '^tsp:' "$build_root/int-targets.txt"
21+
! grep -q '^crew:' "$build_root/int-targets.txt"
22+
! grep -q '^cartesian-heart:' "$build_root/int-targets.txt"
23+
! grep -q '^archimedean-spiral:' "$build_root/int-targets.txt"
24+
cmake --build "$build_root/int" --target tsp
25+
26+
cmake -S "$source_dir" -B "$build_root/optional" -G Ninja \
27+
-DGECODE_ENABLE_EXAMPLES=ON \
28+
-DGECODE_ENABLE_SET_VARS=ON \
29+
-DGECODE_ENABLE_FLOAT_VARS=ON \
30+
-DGECODE_ENABLE_MPFR=OFF \
31+
-DGECODE_ENABLE_FLATZINC=OFF \
32+
-DGECODE_ENABLE_QT=OFF \
33+
-DGECODE_ENABLE_GIST=OFF
34+
35+
cmake --build "$build_root/optional" --target help > "$build_root/optional-targets.txt"
36+
grep -q '^crew:' "$build_root/optional-targets.txt"
37+
grep -q '^cartesian-heart:' "$build_root/optional-targets.txt"
38+
! grep -q '^archimedean-spiral:' "$build_root/optional-targets.txt"

.github/workflows/build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ jobs:
224224
shell: bash
225225
run: cmake --build "$GITHUB_WORKSPACE/build-ninja"
226226

227+
- name: Example feature selection
228+
shell: bash
229+
run: bash .github/ci/cmake-example-feature-smoke.sh
230+
227231
- name: Check
228232
shell: bash
229233
run: >

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ endif()
250250
if(GECODE_ENABLE_MINIMODEL)
251251
gecode_force_option_on(GECODE_ENABLE_SEARCH "Minimodel requires search")
252252
gecode_force_option_on(GECODE_ENABLE_INT_VARS "Minimodel requires int variables")
253-
gecode_force_option_on(GECODE_ENABLE_SET_VARS "Minimodel requires set variables")
254253
endif()
255254
if(GECODE_ENABLE_DRIVER)
256255
gecode_force_option_on(GECODE_ENABLE_SEARCH "Driver requires search")
@@ -267,8 +266,6 @@ endif()
267266
if(GECODE_ENABLE_EXAMPLES)
268267
gecode_force_option_on(GECODE_ENABLE_SEARCH "Examples require search")
269268
gecode_force_option_on(GECODE_ENABLE_INT_VARS "Examples require int variables")
270-
gecode_force_option_on(GECODE_ENABLE_SET_VARS "Examples require set variables")
271-
gecode_force_option_on(GECODE_ENABLE_FLOAT_VARS "Examples require float variables")
272269
gecode_force_option_on(GECODE_ENABLE_MINIMODEL "Examples require minimodel")
273270
gecode_force_option_on(GECODE_ENABLE_DRIVER "Examples require driver")
274271
endif()
@@ -1271,7 +1268,10 @@ if(GECODE_ENABLE_FLOAT_VARS)
12711268
endif()
12721269
endif()
12731270
if(GECODE_ENABLE_MINIMODEL)
1274-
set(mm_deps int set search)
1271+
set(mm_deps int search)
1272+
if(GECODE_ENABLE_SET_VARS)
1273+
list(APPEND mm_deps set)
1274+
endif()
12751275
if(GECODE_ENABLE_FLOAT_VARS)
12761276
list(APPEND mm_deps float)
12771277
endif()

changelog.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ Thanks: Ioannis Papatsoris
126126
Treat zero entries in the TSP example as valid zero-cost edges. This lets the
127127
br17 instance reach its optimum.
128128

129+
[ENTRY]
130+
Module: example
131+
What: bug
132+
Rank: minor
133+
Issue: 83
134+
Thanks: Mikael Zayenz Lagerkvist
135+
[DESCRIPTION]
136+
Build CMake examples only when their required variable modules and MPFR support
137+
are enabled.
138+
129139
[ENTRY]
130140
Module: flatzinc
131141
What: new

examples/CMakeLists.txt

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,35 @@ set(GECODE_EXAMPLE_SOURCES
6161
warehouses.cpp
6262
word-square.cpp)
6363

64-
set(GECODE_MPFR_EXAMPLES
64+
set(GECODE_SET_EXAMPLES
65+
crew
66+
golf
67+
hamming
68+
queen-armies
69+
steiner)
70+
71+
set(GECODE_FLOAT_EXAMPLES
72+
cartesian-heart
73+
descartes-folium)
74+
75+
set(GECODE_MPFR_FLOAT_EXAMPLES
6576
archimedean-spiral
6677
golden-spiral)
6778

6879
function(gecode_add_example source_file)
6980
get_filename_component(example_name "${source_file}" NAME_WE)
7081

71-
if(example_name IN_LIST GECODE_MPFR_EXAMPLES AND
82+
if(example_name IN_LIST GECODE_SET_EXAMPLES AND NOT GECODE_ENABLE_SET_VARS)
83+
message(STATUS "Skipping example: ${example_name} (requires set variables)")
84+
return()
85+
endif()
86+
87+
if(example_name IN_LIST GECODE_FLOAT_EXAMPLES AND NOT GECODE_ENABLE_FLOAT_VARS)
88+
message(STATUS "Skipping example: ${example_name} (requires float variables)")
89+
return()
90+
endif()
91+
92+
if(example_name IN_LIST GECODE_MPFR_FLOAT_EXAMPLES AND
7293
(NOT GECODE_ENABLE_FLOAT_VARS OR NOT GECODE_ENABLE_MPFR OR NOT MPFR_FOUND))
7394
message(STATUS "Skipping example: ${example_name} (requires MPFR float support)")
7495
return()

0 commit comments

Comments
 (0)