Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Put back the FFTW3 find tool and now link to the BLAS and LAPACK libr…
Browse files Browse the repository at this point in the history
…aries correctly.
  • Loading branch information
daminton committed Feb 16, 2024
1 parent 66150cd commit af84884
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 21 deletions.
15 changes: 10 additions & 5 deletions buildscripts/set_environment_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@ FCFLAGS="-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}"
FFLAGS="${FCFLAGS}"
CFLAGS="${FCFLAGS} -Wno-deprecated-non-prototype"
CXXFLAGS="${CFLAGS}"
HDF5_ROOT="${PREFIX}"

NCDIR=${NETCDF_HOME:-"${PREFIX}"}
NFDIR=${NETCDF_FORTRAN_HOME:-"${PREFIX}"}
NETCDF_FORTRAN_HOME="${NFDIR}"
NETCDF_FORTRAN_INCLUDE="${NFDIR}/include"
ZLIB_ROOT=${ZLIB_ROOT:-"${ZLIB_HOME}"}
ZLIB_ROOT=${ZLIB_ROOT:-"${PREFIX}"}
HDF5_ROOT=${HDF5_ROOT:-"${HDF5_HOME}"}
HDF5_ROOT=${HDF5_ROOT:-"${PREFIX}"}
HDF5_LIBDIR="${HDF5_ROOT}/lib"
HDF5_INCLUDE_DIR="${HDF5_ROOT}/include"
HDF5_PLUGIN_PATH="${HDF5_LIBDIR}/plugin"
NCDIR="${PREFIX}"
NFDIR="${PREFIX}"
NETCDF_FORTRAN_HOME="${NFDIR}"
NETCDF_FORTRAN_INCLUDE="${NFDIR}/include"

FC="$(command -v gfortran-12)"
F77="${FC}"
F95="${FC}"
Expand Down
29 changes: 29 additions & 0 deletions cmake/Modules/FindFFTW3.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2023 - David Minton
# This file is part of Swiftest.
# Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
# Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with Swiftest.
# If not, see: https://www.gnu.org/licenses.

# - Finds the FFTW3 library
MESSAGE(STATUS "Looking for FFTW3")
FIND_PATH(FFTW3_INCLUDE_DIR NAMES fftw3.h HINTS ENV FFTW3_HOME PATH_SUFFIXES include)
FIND_LIBRARY(FFTW3_LIBRARY NAMES libfftw3.a HINTS ENV FFTW3_HOME PATH_SUFFIXES lib)

IF(NOT FFTW3_INCLUDE_DIR OR NOT FFTW3_LIBRARY)
MESSAGE(STATUS "FFTW3 not found")
SET(FFTW3_FOUND FALSE)
ELSE ()
MESSAGE(STATUS "FFTW3 found")
SET(FFTW3_FOUND TRUE)
MESSAGE(STATUS "Found FFTW3: ${FFTW3_LIBRARY}")

ADD_LIBRARY(FFTW3::FFTW3 UNKNOWN IMPORTED PUBLIC)
SET_TARGET_PROPERTIES(FFTW3::FFTW3 PROPERTIES
IMPORTED_LOCATION "${FFTW3_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${FFTW3_INCLUDE_DIR}"
)
ENDIF()
mark_as_advanced(FFTW3_LIBRARY FFTW3_INCLUDE_DIR)
2 changes: 0 additions & 2 deletions cmake/Modules/FindSHTOOLS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
FIND_PATH(SHTOOLS_INCLUDE_DIR NAMES shtools.h HINTS ENV SHTOOLS_HOME PATH_SUFFIXES include)
FIND_LIBRARY(SHTOOLS_LIBRARY NAMES libSHTOOLS.a HINTS ENV SHTOOLS_HOME PATH_SUFFIXES lib)
ADD_LIBRARY(SHTOOLS::serial UNKNOWN IMPORTED PUBLIC)
FIND_PACKAGE(FFTW3 REQUIRED)
FIND_PACKAGE(BLAS REQUIRED)
SET_TARGET_PROPERTIES(SHTOOLS::serial PROPERTIES
IMPORTED_LOCATION "${SHTOOLS_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${SHTOOLS_INCLUDE_DIR}"
Expand Down
14 changes: 0 additions & 14 deletions cmake/Modules/SetSwiftestFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -518,10 +518,6 @@ IF (CMAKE_BUILD_TYPE STREQUAL "RELEASE" OR CMAKE_BUILD_TYPE STREQUAL "PROFILE")
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}"
Fortran "/Qfma" # Intel Windows
)
# Tells the compiler to link to certain libraries in the Intel oneAPI Math Kernel Library (oneMKL).
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}"
Fortran "/Qmkl" # Intel Windows
)
# Enables additional interprocedural optimizations for a single file compilation
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}"
Fortran "/Qip" # Intel Windows
Expand Down Expand Up @@ -553,13 +549,6 @@ IF (CMAKE_BUILD_TYPE STREQUAL "RELEASE" OR CMAKE_BUILD_TYPE STREQUAL "PROFILE")
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}"
Fortran "-fma" # Intel
)
# Tells the compiler to link to certain libraries in the Intel oneAPI Math Kernel Library (oneMKL).
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}"
Fortran "-mkl"
)
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}"
Fortran "-qmkl"
)
# Enables additional interprocedural optimizations for a single file compilation
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}"
Fortran "-ip" # Intel
Expand All @@ -575,9 +564,6 @@ IF (CMAKE_BUILD_TYPE STREQUAL "RELEASE" OR CMAKE_BUILD_TYPE STREQUAL "PROFILE")
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}"
Fortran "-finline-functions" # GNU
)
SET_COMPILE_FLAG(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_FLAGS_RELEASE}"
Fortran "-llapack"
)
ENDIF ()
ENDIF ()

Expand Down
17 changes: 17 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,23 @@ ELSE ()
TARGET_LINK_LIBRARIES(${SWIFTEST_DRIVER} PUBLIC SHTOOLS::serial)
ENDIF()

# Add in the BLAS, LAPACK, and FFTW3 libraries
IF (COMPILER_OPTIONS STREQUAL "GNU")
IF (APPLE)
SET(BLA_VENDOR "Apple" CACHE STRING "BLAS vendor")
ELSE ()
SET(BLA_VENDOR "OpenBLAS" CACHE STRING "BLAS vendor")
ENDIF ()
ELSEIF (COMPILER_OPTIONS STREQUAL "INTEL")
SET(BLA_VENDOR "Intel10_64lp" CACHE STRING "BLAS vendor")
ENDIF()
SET(BLA_STATIC ON)
FIND_PACKAGE(BLAS REQUIRED)
FIND_PACKAGE(LAPACK REQUIRED)
FIND_PACKAGE(FFTW3 REQUIRED)

TARGET_LINK_LIBRARIES(${SWIFTEST_LIBRARY} PUBLIC BLAS::BLAS LAPACK::LAPACK FFTW3::FFTW3)

TARGET_LINK_LIBRARIES(${SWIFTEST_DRIVER} PUBLIC ${SWIFTEST_LIBRARY})

IF (CMAKE_SYSTEM_NAME STREQUAL "Windows")
Expand Down

0 comments on commit af84884

Please sign in to comment.