Skip to content

[Code scan] Do not require fftw3f when ENABLE_FLOAT_FFTW is off #7567

Description

@njzjz

This issue is a result of a Codex global repository scan.

ENABLE_FLOAT_FFTW defaults to OFF, and the top-level build only links FFTW3::FFTW3_FLOAT when that option is enabled. However, FindFFTW3.cmake always searches for fftw3f and includes FFTW3_FLOAT_LIBRARY in find_package_handle_standard_args(), so double-precision-only FFTW installations can fail configure even when single-precision FFTW support is disabled.

Option and top-level link condition:

option(USE_ABACUS_LIBM "Build libmath from source to speed up" OFF)
option(ENABLE_LIBXC "Enable using the LibXC package" OFF)
option(ENABLE_FLOAT_FFTW "Enable using single-precision FFTW library." OFF)

find_package(FFTW3 REQUIRED)
find_package(Lapack REQUIRED)
include_directories(${FFTW3_INCLUDE_DIRS})
list(APPEND math_libs FFTW3::FFTW3 LAPACK::LAPACK BLAS::BLAS)
# ScaLAPACK is a distributed-memory library and is only needed for the
# MPI build. A serial build (e.g. the native Windows serial version)
# must not require it.
if(ENABLE_MPI)
find_package(ScaLAPACK REQUIRED)
list(APPEND math_libs ScaLAPACK::ScaLAPACK)
endif()
if(USE_OPENMP)
list(APPEND math_libs FFTW3::FFTW3_OMP)
endif()
if(ENABLE_FLOAT_FFTW)
list(APPEND math_libs FFTW3::FFTW3_FLOAT)
endif()

Find module requirement:

find_library(FFTW3_FLOAT_LIBRARY
NAMES fftw3f
HINTS ${FFTW3_DIR}
PATH_SUFFIXES "lib"
)
# both libfftw3.so and libfftw3_omp.so should be link in multi-thread term
if (USE_OPENMP)
find_library(FFTW3_OMP_LIBRARY
NAMES fftw3_omp
HINTS ${FFTW3_DIR}
PATH_SUFFIXES "lib"
)
endif()
# Handle the QUIET and REQUIRED arguments and
# set FFTW3_FOUND to TRUE if all variables are non-zero.
include(FindPackageHandleStandardArgs)
if (USE_OPENMP)
find_package_handle_standard_args(FFTW3 DEFAULT_MSG FFTW3_OMP_LIBRARY FFTW3_LIBRARY FFTW3_FLOAT_LIBRARY FFTW3_INCLUDE_DIR)
else()
find_package_handle_standard_args(FFTW3 DEFAULT_MSG FFTW3_LIBRARY FFTW3_FLOAT_LIBRARY FFTW3_INCLUDE_DIR)

Relevant code:

find_library(FFTW3_FLOAT_LIBRARY NAMES fftw3f ...)
...
find_package_handle_standard_args(FFTW3 DEFAULT_MSG FFTW3_LIBRARY FFTW3_FLOAT_LIBRARY FFTW3_INCLUDE_DIR)

Suggested fix:

Only search for and require FFTW3_FLOAT_LIBRARY when ENABLE_FLOAT_FFTW is enabled. Keep the imported FFTW3::FFTW3_FLOAT target conditional on that option as well.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    In Progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions