Skip to content

Commit a8c0d0d

Browse files
committed
Add version-aware tests for FindFFTW
- Accept FFTW_TEST_VERSION to pass version requirement to find_package - Validate that FFTW_VERSION is non-empty and meets the requested version - Add CI steps for version 3 and invalid version rejection - Add version output to success message
1 parent 224792c commit a8c0d0d

2 files changed

Lines changed: 77 additions & 6 deletions

File tree

.github/workflows/test.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,24 @@ jobs:
2424
cmake -S test -B build \
2525
-DFFTW_TEST_COMPONENTS="${fftw_components}"
2626
27+
- name: Configure test with version 3
28+
run: |
29+
cmake -S test -B build \
30+
-DFFTW_TEST_COMPONENTS="${fftw_components}" \
31+
-DFFTW_TEST_VERSION=3
32+
33+
- name: Configure test with invalid version
34+
run: |
35+
set +e
36+
cmake -S test -B build_version_fail -DFFTW_TEST_VERSION=999.99.9 2>/dev/null
37+
STATUS=$?
38+
if [ $STATUS -ne 0 ]; then
39+
echo "PASS: find_package correctly rejected version 999.99.9"
40+
else
41+
echo "FAIL: find_package should have rejected version 999.99.9 but succeeded"
42+
exit 1
43+
fi
44+
2745
test-source:
2846
name: Test source install
2947
runs-on: ubuntu-latest
@@ -79,6 +97,13 @@ jobs:
7997
-DFFTW_ROOT="$HOME/fftw_install" \
8098
-DFFTW_TEST_COMPONENTS="${fftw_components}"
8199
100+
- name: Configure test with version 3
101+
run: |
102+
cmake -S test -B build \
103+
-DFFTW_ROOT="$HOME/fftw_install" \
104+
-DFFTW_TEST_COMPONENTS="${fftw_components}"
105+
-DFFTW_TEST_VERSION=3
106+
82107
test-conda:
83108
name: Test conda-forge install
84109
runs-on: ubuntu-latest
@@ -99,3 +124,11 @@ jobs:
99124
cmake -S test -B build \
100125
-DFFTW_ROOT="$CONDA_PREFIX" \
101126
-DFFTW_TEST_COMPONENTS="${fftw_components}"
127+
128+
- name: Configure test with version 3
129+
shell: micromamba-shell {0}
130+
run: |
131+
cmake -S test -B build \
132+
-DFFTW_ROOT="$CONDA_PREFIX" \
133+
-DFFTW_TEST_COMPONENTS="${fftw_components}" \
134+
-DFFTW_TEST_VERSION=3

test/CMakeLists.txt

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,27 @@ project(test_findFFTW NONE)
44
# Add the parent directory (repo root) to the module path so CMake can find FindFFTW.cmake
55
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/..")
66

7-
# Find FFTW. If FFTW_TEST_COMPONENTS is given (semicolon-separated list), those
8-
# components are required; otherwise we just require that FFTW itself is found.
7+
# ---------------------------------------------------------------------------
8+
# Build find_package arguments
9+
# ---------------------------------------------------------------------------
10+
11+
# Resolve version argument from FFTW_TEST_VERSION
12+
set(_fftw_find_version "")
13+
if(DEFINED FFTW_TEST_VERSION)
14+
set(_fftw_find_version "${FFTW_TEST_VERSION}")
15+
endif()
16+
17+
# Collect COMPONENTS argument
18+
set(_fftw_components "")
919
if(DEFINED FFTW_TEST_COMPONENTS)
10-
find_package(FFTW REQUIRED COMPONENTS ${FFTW_TEST_COMPONENTS})
20+
set(_fftw_components COMPONENTS ${FFTW_TEST_COMPONENTS})
21+
endif()
22+
23+
# Call find_package with the assembled arguments
24+
if(_fftw_find_version)
25+
find_package(FFTW ${_fftw_find_version} REQUIRED ${_fftw_components})
1126
else()
12-
find_package(FFTW REQUIRED)
27+
find_package(FFTW REQUIRED ${_fftw_components})
1328
endif()
1429

1530
# ---------------------------------------------------------------------------
@@ -19,14 +34,36 @@ if(NOT FFTW_FOUND)
1934
message(FATAL_ERROR "FFTW_FOUND is not TRUE after find_package(FFTW REQUIRED)")
2035
endif()
2136

22-
if(NOT FFTW_INCLUDE_DIRS)
37+
if("${FFTW_VERSION}" STREQUAL "")
38+
message(FATAL_ERROR "FFTW_VERSION is empty after find_package(FFTW REQUIRED)")
39+
endif()
40+
41+
if("${FFTW_INCLUDE_DIRS}" STREQUAL "")
2342
message(FATAL_ERROR "FFTW_INCLUDE_DIRS is empty after find_package(FFTW REQUIRED)")
2443
endif()
2544

26-
if(NOT FFTW_LIBRARIES)
45+
if("${FFTW_LIBRARIES}" STREQUAL "")
2746
message(FATAL_ERROR "FFTW_LIBRARIES is empty after find_package(FFTW REQUIRED)")
2847
endif()
2948

49+
# ---------------------------------------------------------------------------
50+
# Version checks
51+
# ---------------------------------------------------------------------------
52+
if(_fftw_find_version)
53+
if("${FFTW_VERSION}" STREQUAL "")
54+
message(FATAL_ERROR
55+
"FFTW_VERSION is not set after find_package. "
56+
"Version detection requires pkg-config, which is not used when "
57+
"FFTW_ROOT is set or pkg-config is unavailable. "
58+
"Do not set FFTW_TEST_VERSION when using FFTW_ROOT.")
59+
endif()
60+
61+
if(NOT "${FFTW_VERSION}" VERSION_GREATER_EQUAL "${_fftw_find_version}")
62+
message(FATAL_ERROR
63+
"Expected FFTW_VERSION >= ${_fftw_find_version} but got ${FFTW_VERSION}")
64+
endif()
65+
endif()
66+
3067
# ---------------------------------------------------------------------------
3168
# Map component names to their CMake imported target names
3269
# ---------------------------------------------------------------------------
@@ -71,6 +108,7 @@ endforeach()
71108
# ---------------------------------------------------------------------------
72109
message(STATUS "FindFFTW test passed!")
73110
message(STATUS " FFTW_FOUND: ${FFTW_FOUND}")
111+
message(STATUS " FFTW_VERSION: ${FFTW_VERSION}")
74112
message(STATUS " FFTW_INCLUDE_DIRS: ${FFTW_INCLUDE_DIRS}")
75113
message(STATUS " FFTW_LIBRARIES: ${FFTW_LIBRARIES}")
76114

0 commit comments

Comments
 (0)