@@ -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
55list (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 "" )
919if (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} )
1126else ()
12- find_package (FFTW REQUIRED )
27+ find_package (FFTW REQUIRED ${_fftw_components} )
1328endif ()
1429
1530# ---------------------------------------------------------------------------
@@ -19,14 +34,36 @@ if(NOT FFTW_FOUND)
1934 message (FATAL_ERROR "FFTW_FOUND is not TRUE after find_package(FFTW REQUIRED)" )
2035endif ()
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)" )
2443endif ()
2544
26- if (NOT FFTW_LIBRARIES)
45+ if (" ${ FFTW_LIBRARIES} " STREQUAL "" )
2746 message (FATAL_ERROR "FFTW_LIBRARIES is empty after find_package(FFTW REQUIRED)" )
2847endif ()
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# ---------------------------------------------------------------------------
72109message (STATUS "FindFFTW test passed!" )
73110message (STATUS " FFTW_FOUND: ${FFTW_FOUND} " )
111+ message (STATUS " FFTW_VERSION: ${FFTW_VERSION} " )
74112message (STATUS " FFTW_INCLUDE_DIRS: ${FFTW_INCLUDE_DIRS} " )
75113message (STATUS " FFTW_LIBRARIES: ${FFTW_LIBRARIES} " )
76114
0 commit comments