|
| 1 | +# |
| 2 | +# Copyright (C) 2025 The ESPResSo project |
| 3 | +# |
| 4 | +# This file is part of ESPResSo. |
| 5 | +# |
| 6 | +# ESPResSo is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU General Public License as published by |
| 8 | +# the Free Software Foundation, either version 3 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# ESPResSo is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU General Public License |
| 17 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | +# |
| 19 | + |
| 20 | +# Find the fftw3 libraries (with variants MPI, OpenMP, etc.) and header files. |
| 21 | +# |
| 22 | +# The following variables and imported targets are created: |
| 23 | +# |
| 24 | +# - `fftw3_INCLUDE_DIR` : folder containing `fftw3.h` |
| 25 | +# - `fftw3_MPI_INCLUDE_DIR` : folder containing `fftw3-mpi.h` |
| 26 | +# - `fftw3_FOUND` : true if `espresso::fftw3` exists and all required components were found |
| 27 | +# - `fftw3_mpi_FOUND` : true if `espresso::fftw3_mpi` exists |
| 28 | +# - `fftw3_omp_FOUND` : true if `espresso::fftw3_omp` exists |
| 29 | +# - `fftw3_threads_FOUND` : true if `espresso::fftw3_threads` exists |
| 30 | + |
| 31 | +include(FindPackageHandleStandardArgs) |
| 32 | + |
| 33 | +set(fftw3_PRECISIONS "" "f") |
| 34 | +set(fftw3_COMPONENTS "mpi" "omp" "threads") |
| 35 | +set(fftw3_MODULES ${fftw3_COMPONENTS}) |
| 36 | +list(TRANSFORM fftw3_MODULES PREPEND "_") |
| 37 | +list(INSERT fftw3_MODULES 0 "") |
| 38 | + |
| 39 | +find_path(fftw3_INCLUDE_DIR fftw3.h) |
| 40 | +find_path(fftw3_MPI_INCLUDE_DIR fftw3-mpi.h) |
| 41 | + |
| 42 | +foreach(PRECISION IN LISTS fftw3_PRECISIONS) |
| 43 | + foreach(COMPONENT IN LISTS fftw3_COMPONENTS) |
| 44 | + find_library(fftw3${PRECISION}_${COMPONENT}_LIBRARIES |
| 45 | + fftw3${PRECISION}_${COMPONENT}) |
| 46 | + mark_as_advanced(fftw3${PRECISION}_${COMPONENT}_LIBRARIES) |
| 47 | + endforeach() |
| 48 | + find_library(fftw3${PRECISION}_LIBRARIES fftw3${PRECISION}) |
| 49 | + mark_as_advanced(fftw3${PRECISION}_LIBRARIES) |
| 50 | +endforeach() |
| 51 | + |
| 52 | +# dependencies bookkeeping |
| 53 | +set(fftw3_LIBRARIES_REQUIRED fftw3_INCLUDE_DIR) |
| 54 | +foreach(PRECISION IN LISTS fftw3_PRECISIONS) |
| 55 | + list(APPEND fftw3_LIBRARIES_REQUIRED fftw3${PRECISION}_LIBRARIES) |
| 56 | +endforeach() |
| 57 | + |
| 58 | +# find library components |
| 59 | +set(FPHSA_NAME_MISMATCHED 1) |
| 60 | +foreach(COMPONENT IN LISTS fftw3_COMPONENTS) |
| 61 | + if(${COMPONENT} IN_LIST fftw3_FIND_COMPONENTS) |
| 62 | + set(fftw3_COMPONENT_DEPS fftw3_INCLUDE_DIR) |
| 63 | + if(${COMPONENT} STREQUAL "mpi") |
| 64 | + list(APPEND fftw3_COMPONENT_DEPS fftw3_MPI_INCLUDE_DIR) |
| 65 | + endif() |
| 66 | + foreach(PRECISION IN LISTS fftw3_PRECISIONS) |
| 67 | + list(APPEND fftw3_COMPONENT_DEPS fftw3${PRECISION}_${COMPONENT}_LIBRARIES) |
| 68 | + endforeach() |
| 69 | + find_package_handle_standard_args(fftw3_${COMPONENT} DEFAULT_MSG ${fftw3_COMPONENT_DEPS}) |
| 70 | + if(${fftw3_FIND_REQUIRED_${COMPONENT}}) |
| 71 | + list(APPEND fftw3_LIBRARIES_REQUIRED ${fftw3_COMPONENT_DEPS}) |
| 72 | + endif() |
| 73 | + endif() |
| 74 | +endforeach() |
| 75 | +list(REMOVE_DUPLICATES fftw3_LIBRARIES_REQUIRED) |
| 76 | +unset(FPHSA_NAME_MISMATCHED) |
| 77 | + |
| 78 | +# find main library, but fail if required components are missing |
| 79 | +find_package_handle_standard_args(fftw3 DEFAULT_MSG ${fftw3_LIBRARIES_REQUIRED}) |
| 80 | + |
| 81 | +foreach(MODULE IN LISTS fftw3_MODULES) |
| 82 | + if(fftw3${MODULE}_FOUND AND NOT TARGET espresso::fftw3${MODULE}) |
| 83 | + add_library(espresso::fftw3${MODULE} INTERFACE IMPORTED) |
| 84 | + target_include_directories( |
| 85 | + espresso::fftw3${MODULE} |
| 86 | + INTERFACE "${fftw3_INCLUDE_DIR}" "$<$<STREQUAL:${MODULE},_mpi>:${fftw3_MPI_INCLUDE_DIR}>") |
| 87 | + foreach(PRECISION IN LISTS fftw3_PRECISIONS) |
| 88 | + target_link_libraries( |
| 89 | + espresso::fftw3${MODULE} |
| 90 | + INTERFACE "${fftw3${PRECISION}${MODULE}_LIBRARIES}") |
| 91 | + endforeach() |
| 92 | + endif() |
| 93 | +endforeach() |
0 commit comments