Build fails if PFFT is not installed
In the past (e.g. 08f04ef6), when the PFFT module was not found, waLBerla would print out:
-- Could NOT find PFFT (missing: PFFT_LIBRARIES PFFT_INCLUDE_DIR)
-- Module fft is not built, because pfft not available
and would not include src/fft
.
The way modules are imported changed around 7 months ago. Now (e.g. 01a28162), when PFFT is not found, CMake simply keeps going and includes src/fft
, which then leads to a compiler error:
In file included from /home/espresso/espresso/build/_deps/walberla-src/src/fft/Fft.cpp:3:
/home/espresso/espresso/build/_deps/walberla-src/src/fft/Fft.h:12:10: fatal error: pfft.h: No such file or directory
12 | #include "pfft.h"
| ^~~~~~~~
compilation terminated.
Several issues can be identified in the new CMake logic.
In 01a28162ae:CMakeLists.txt#L924-930
:
if ( WALBERLA_BUILD_WITH_FFTW )
if( WALBERLA_BUILD_WITH_MPI )
find_package( PFFT )
find_package( FFTW3 )
set( FFT_REQUIRED_LIBRARIES pfft fftw3_mpi fftw3 )
if( PFFT_FOUND AND FFTW3_MPI_FOUND )
set( WALBERLA_BUILD_WITH_FFT TRUE CACHE INTERNAL "Build with FFT" )
Here packages PFFT and FFTW3 are optional (default behavior of find_package()
), when they should be marked as REQUIRED
since this branch can only be executed when the user specifically requested WALBERLA_BUILD_WITH_FFTW=ON
. We ran into the same issue in ESPResSo a few years ago: we made all dependencies optional and let CMake load all dependencies that could be found on the system (unless the user specifically disabled them with CMake flags), but we eventually found out it was quite unreliable and decided to make all dependencies opt-in.
In 01a28162ae:src/CMakeLists.txt#L32-34
:
if ( FFTW3_FOUND )
add_subdirectory( fft )
endif()
Here the src/fft
module is added even if:
- PFFT is not found or FFTW3_MPI is not found, because the conditional only checks for FFTW3 -> compiler error
-
WALBERLA_BUILD_WITH_FFTW
isOFF
, because theFFTW3_FOUND
is a global variable that can be set toTRUE
by a parent project that hasfind_package(FFTW3)
and then includes waLBerla usingFetchContent()
-> compiler error
As a stop-gap solution, this last conditional was changed to if ( WALBERLA_BUILD_WITH_FFTW AND FFTW3_FOUND )
using a patch file in the FetchContent()
command of the ESPResSo CMake file.