Skip to content

Commit

Permalink
Find FFTW3
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsvu committed Aug 11, 2023
1 parent 3a4f1c9 commit c54bb1a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 26 deletions.
36 changes: 36 additions & 0 deletions cmake/FindFFTW.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Distributed under the MIT License.
# See LICENSE.txt for details.

# Find FFTW3 (The Fastest Fourier Transform in the West)
# http://www.fftw.org/
#
# Defines the `FFTW::FFTW` target to link against.

if(NOT FFTW_ROOT)
# Need to set to empty to avoid warnings with --warn-uninitialized
set(FFTW_ROOT "")
set(FFTW_ROOT $ENV{FFTW_ROOT})
endif()

find_path(FFTW_INCLUDE_DIR
NAMES fftw3.h
PATH_SUFFIXES include
HINTS ${FFTW_ROOT}
)

find_library(FFTW_LIB
NAMES fftw3
PATH_SUFFIXES lib64 lib
HINTS ${FFTW_ROOT}
)

if (FFTW_INCLUDE_DIR AND FFTW_LIB)
add_library(FFTW::FFTW INTERFACE IMPORTED)
target_include_directories(FFTW::FFTW INTERFACE ${FFTW_INCLUDE_DIR})
target_link_libraries(FFTW::FFTW INTERFACE ${FFTW_LIB})
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(FFTW
REQUIRED_VARS FFTW_INCLUDE_DIR FFTW_LIB)
mark_as_advanced(FFTW_INCLUDE_DIR FFTW_LIB)
46 changes: 20 additions & 26 deletions cmake/FindSpEC.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,29 @@ find_package(MPI COMPONENTS C)

if (SPEC_PACKAGED_EXPORTER_LIB AND SPEC_EXPORTER_FACTORY_OBJECTS AND
SPEC_EXPORTER_INCLUDE_DIR AND MPI_C_FOUND)
add_library(SpEC::Exporter INTERFACE IMPORTED)
target_include_directories(
SpEC::Exporter INTERFACE ${SPEC_EXPORTER_INCLUDE_DIR})
add_interface_lib_headers(
TARGET SpEC::Exporter
HEADERS
Exporter.hpp
)
target_link_libraries(
SpEC::Exporter
INTERFACE
MPI::MPI_C
# The order of these next two lines is important
${SPEC_EXPORTER_FACTORY_OBJECTS}
${SPEC_PACKAGED_EXPORTER_LIB}
)

# Deal with FFTW3
#
# If it was dynamically linked into SpEC then we need to dynamically link it
# into SpECTRE.
set(_MACHINE_DEF_FILE
${SPEC_ROOT}/MakefileRules/this_machine.def)
set(_FFTW3_LINK_FLAGS "")
if (EXISTS ${_MACHINE_DEF_FILE})
file(STRINGS ${_MACHINE_DEF_FILE} _MACHINE_DEF)
# Filter starting comments
Expand All @@ -61,34 +76,13 @@ if (SPEC_PACKAGED_EXPORTER_LIB AND SPEC_EXPORTER_FACTORY_OBJECTS AND
list(TRANSFORM _MACHINE_DEF REPLACE "[ ]*#.*" "")
string(REGEX MATCH "FFTW_LIB[^;]+"
_FFTW3_DEF "${_MACHINE_DEF}")
string(REGEX REPLACE
"FFTW_LIB[ +]+=[ ]" ""
_FFTW3_LINK_FLAGS
${_FFTW3_DEF})
string(FIND ${_FFTW3_DEF} "-lfftw3" _FOUND_FFTW3_SHARED)
# If we did not find a shared lib, do not add linking flags.
if(${_FOUND_FFTW3_SHARED} STREQUAL -1)
set(_FFTW3_LINK_FLAGS "")
# If we found a shared FFTW lib in SpEC, find and link FFTW here
if(NOT ${_FOUND_FFTW3_SHARED} STREQUAL "-1")
find_package(FFTW REQUIRED)
target_link_libraries(SpEC::Exporter INTERFACE FFTW::FFTW)
endif()
endif()

add_library(SpEC::Exporter INTERFACE IMPORTED)
target_include_directories(
SpEC::Exporter INTERFACE ${SPEC_EXPORTER_INCLUDE_DIR})
add_interface_lib_headers(
TARGET SpEC::Exporter
HEADERS
Exporter.hpp
)
target_link_libraries(
SpEC::Exporter
INTERFACE
MPI::MPI_C
# The order of these next two lines is important
${SPEC_EXPORTER_FACTORY_OBJECTS}
${SPEC_PACKAGED_EXPORTER_LIB}
${_FFTW3_LINK_FLAGS}
)
endif()

include(FindPackageHandleStandardArgs)
Expand Down

0 comments on commit c54bb1a

Please sign in to comment.