Skip to content

Bug: CMake configure fails when CUDA tests are enabled without ENABLE_FLOAT_FFTW #7585

Description

@AsTonyshment

Summary

After updating to commit 59dc88428 (Add FindKML.cmake and resolve FFTW3 issue, #7576), CMake configuration fails when CUDA unit tests are enabled while ENABLE_FLOAT_FFTW is left at its default value OFF.

The failure happens because pw_test_gpu unconditionally links against FFTW3::FFTW3_FLOAT, while cmake/FindFFTW3.cmake now only defines that imported target when ENABLE_FLOAT_FFTW=ON.

Environment

  • Commit: 59dc88428
  • Branch: develop
  • Compiler: GNU 12.4.0
  • CMake: 3.28
  • CUDA: 12.1

Trigger Conditions

The issue is triggered with the following configuration:

  • USE_CUDA=ON
  • BUILD_TESTING=ON
  • ENABLE_FLOAT_FFTW=OFF or not specified, since it defaults to OFF
  • FFTW is found through cmake/FindFFTW3.cmake

Actual Behavior

CMake configure/generate fails with:

CMake Error at cmake/Testing.cmake:42 (target_link_libraries):
  Target "pw_test_gpu" links to:

    FFTW3::FFTW3_FLOAT

  but the target was not found.
Call Stack (most recent call first):
  source/source_basis/module_pw/test_gpu/CMakeLists.txt:3 (AddTest)

Analysis

ENABLE_FLOAT_FFTW defaults to OFF in the top-level CMakeLists.txt.

After #7576, cmake/FindFFTW3.cmake only searches for fftw3f and creates FFTW3::FFTW3_FLOAT when ENABLE_FLOAT_FFTW=ON.

However, source/source_basis/module_pw/test_gpu/CMakeLists.txt still registers pw_test_gpu whenever USE_CUDA=ON, and links it unconditionally against FFTW3::FFTW3_FLOAT:

if (USE_CUDA)
AddTest(
  TARGET pw_test_gpu
  LIBS parameter ${math_libs} base planewave device FFTW3::FFTW3_FLOAT
  SOURCES pw_test.cpp  pw_basis_C2R.cpp pw_basis_C2C.cpp  pw_basis_k_C2C.cpp
)
endif()

The test sources also instantiate float GPU test cases and call fftwf_* APIs, for example fftwf_plan_dft_3d, so the test itself appears to require single-precision FFTW.

Expected Behavior

One of the following should happen:

  1. pw_test_gpu should only be enabled when ENABLE_FLOAT_FFTW=ON, or
  2. the float-specific parts of pw_test_gpu should be guarded by ENABLE_FLOAT_FFTW, or
  3. ENABLE_FLOAT_FFTW=ON should remain available as long as BUILD_TESTING=ON.

The default configuration with USE_CUDA=ON and BUILD_TESTING=ON should not fail during CMake generation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions