Skip to content

Commit e6ac719

Browse files
committed
Add version detection from fftw-wisdom-to-conf when pkg-config is not used
When `pkg-config` is not found or `FFTW_ROOT` is set, the version of FFTW was not determined. This commit adds a fallback that attempts to extract the version from the `fftw-wisdom-to-conf` binary using its `-V` flag. If the command fails, a warning is issued with the output and error messages. The assignment of `FFTW_VERSION` is now conditional: it is set from `pkg-config` results only when available, and otherwise from the fallback method. This ensures the version variable is only populated when a reliable source is found.
1 parent a8c0d0d commit e6ac719

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

FindFFTW.cmake

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,33 @@ endif()
4545
# Check if we can use PkgConfig
4646
find_package(PkgConfig)
4747

48-
#Determine from PKG
48+
# Determine from PKG
4949
if( PKG_CONFIG_FOUND AND NOT FFTW_ROOT )
5050
pkg_check_modules( PKG_FFTW QUIET "fftw3" )
51+
set( FFTW_VERSION ${PKG_FFTW_VERSION} )
52+
else()
53+
# If pkg-config was skipped, there seems no way to get the version directly.
54+
# Try to deduce the version from fftw-wisdom-to-conf instead.
55+
# (From @kprussing. See https://github.com/egpbos/findFFTW/pull/8)
56+
execute_process(COMMAND ${FFTW_ROOT}/bin/fftw-wisdom-to-conf -V
57+
RESULT_VARIABLE _fftw_wtc_success
58+
OUTPUT_VARIABLE _fftw_wtc_stdout
59+
ERROR_VARIABLE _fftw_wtc_stderr)
60+
if (_fftw_wtc_success EQUAL 0)
61+
string(REGEX MATCH "FFTW *version *([0-9]+([.][0-9]+([.][0-9]+)?)?)"
62+
_fftw_wtc_version ${_fftw_wtc_stdout})
63+
string(REPLACE " " ";" _fftw_wtc_version_list ${_fftw_wtc_version})
64+
list(GET _fftw_wtc_version_list -1 FFTW_VERSION)
65+
else()
66+
message(WARNING "Error running ${FFTW_ROOT}/bin/fftw-wisdom-to-conf. "
67+
"Could not determine FFTW version.
68+
Output:
69+
${_fftw_wtc_stdout}
70+
Error:
71+
${_fftw_wtc_stderr}")
72+
endif()
5173
endif()
5274

53-
# Set variables based on pkg-config results
54-
set(FFTW_VERSION ${PKG_FFTW_VERSION})
55-
5675
#Check whether to search static or dynamic libs
5776
set( CMAKE_FIND_LIBRARY_SUFFIXES_SAV ${CMAKE_FIND_LIBRARY_SUFFIXES} )
5877

0 commit comments

Comments
 (0)