Skip to content

Commit

Permalink
Fix CMake: FFTW Threads
Browse files Browse the repository at this point in the history
Trying to fix build issues on Linux in Conda-Forge in which
pthreads are over-linked and ill-resolved from FFTW.
  • Loading branch information
ax3l committed Aug 29, 2024
1 parent be7be23 commit 2243716
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
19 changes: 18 additions & 1 deletion cmake/FindHeffteFFTW.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,32 @@ if (NOT FFTW_LIBRARIES)
PREFIX ${FFTW_ROOT}
VAR FFTW_LIBRARIES
REQUIRED "fftw3" "fftw3f"
OPTIONAL "")
heffte_find_fftw_libraries(
PREFIX ${FFTW_ROOT}
VAR FFTW_THREADS_LIBRARIES
REQUIRED ""
OPTIONAL "fftw3_threads" "fftw3f_threads")
heffte_find_fftw_libraries(
PREFIX ${FFTW_ROOT}
VAR FFTW_OMP_LIBRARIES
REQUIRED ""
OPTIONAL "fftw3_omp" "fftw3f_omp")

if (FFTW_THREADS_LIBRARIES)
list(APPEND FFTW_LIBRARIES "${FFTW_THREADS_LIBRARIES}")
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
if(WIN32) # Windows has an internal pthreads lib we can use
find_package(Threads)
else()
find_package(Threads REQUIRED)
endif()
if(Threads_FOUND)
list(APPEND FFTW_LIBRARIES Threads::Threads)
endif()
endif()
if (FFTW_OMP_LIBRARIES)
list(APPEND FFTW_OMP_LIBRARIES "${FFTW_LIBRARIES}")
list(APPEND FFTW_LIBRARIES "${FFTW_OMP_LIBRARIES}")
if (Heffte_FFTW_LIBOMP)
list(APPEND FFTW_LIBRARIES "${Heffte_FFTW_LIBOMP}")
else()
Expand Down
19 changes: 15 additions & 4 deletions cmake/HeffteConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,24 @@ endif()

include("${CMAKE_CURRENT_LIST_DIR}/HeffteTargets.cmake")

if (@Heffte_ENABLE_FFTW@ AND NOT TARGET Heffte::FFTW)
add_library(Heffte::FFTW INTERFACE IMPORTED GLOBAL)
if (@Heffte_ENABLE_FFTW@)
if (NOT "@FFTW_THREADS_LIBRARIES@" STREQUAL "")
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
if(WIN32) # Windows has an internal pthreads lib we can use
find_package(Threads)
else()
find_package(Threads REQUIRED)
endif()
endif()
if ("@OpenMP_FOUND@")
find_package(OpenMP REQUIRED)
endif()
target_link_libraries(Heffte::FFTW INTERFACE @FFTW_LIBRARIES@)
set_target_properties(Heffte::FFTW PROPERTIES INTERFACE_INCLUDE_DIRECTORIES @FFTW_INCLUDES@)

if(NOT TARGET Heffte::FFTW)
add_library(Heffte::FFTW INTERFACE IMPORTED GLOBAL)
target_link_libraries(Heffte::FFTW INTERFACE @FFTW_LIBRARIES@)
set_target_properties(Heffte::FFTW PROPERTIES INTERFACE_INCLUDE_DIRECTORIES @FFTW_INCLUDES@)
endif()
endif()

if (@Heffte_ENABLE_MKL@ AND NOT TARGET Heffte::MKL)
Expand Down

0 comments on commit 2243716

Please sign in to comment.