Skip to content

Commit

Permalink
load fftw library on macos if conda or homebrew used
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelson-numerical-software committed Oct 19, 2024
1 parent ce12fc0 commit 981fe27
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions modules/fftw/src/cpp/FFTWWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#if WITH_OPENMP
#include <omp.h>
#endif
#include <cstdlib>
#include "FFTWDynamicLibrary.hpp"
#include "FFTWWrapper.hpp"
#include "DynamicLibrary.hpp"
Expand Down Expand Up @@ -192,6 +193,34 @@ freeFFTWLibrary()
return false;
}
//=============================================================================
#if defined(__APPLE__)
static bool
loadFFTWLibraryOnMacOs()
{
bool res = false;
char const* CONDA_PREFIX_char = std::getenv("CONDA_PREFIX");
if (CONDA_PREFIX_char) {
std::string CONDA_LIB = std::string(CONDA_PREFIX_char) + "/lib/";
std::string fftwLibraryName = CONDA_LIB + "libfftw3.3" + get_dynamic_library_extension();
std::string fftwfLibraryName = CONDA_LIB + "libfftw3f" + get_dynamic_library_extension();
res = loadFFTWLibrary(utf8_to_wstring(fftwLibraryName), utf8_to_wstring(fftwfLibraryName));
}
if (!res) {
char const* HOMEBREW_PREFIX_char = std::getenv("HOMEBREW_PREFIX");
if (HOMEBREW_PREFIX_char) {
std::string HOMEBREW_LIB = std::string(HOMEBREW_PREFIX_char) + "/lib/";
std::string fftwLibraryName
= HOMEBREW_LIB + "libfftw3.3" + get_dynamic_library_extension();
std::string fftwfLibraryName
= HOMEBREW_LIB + "libfftw3f" + get_dynamic_library_extension();
res = loadFFTWLibrary(
utf8_to_wstring(fftwLibraryName), utf8_to_wstring(fftwfLibraryName));
}
}
return res;
}
#endif
//=============================================================================
bool
loadFFTWLibrary()
{
Expand All @@ -213,12 +242,15 @@ loadFFTWLibrary()
res = loadFFTWLibrary(utf8_to_wstring(fftwLibraryName), utf8_to_wstring(fftwfLibraryName));
}
if (!res) {
// try with version 3.3 macos specific
std::string fftwLibraryName = "libfftw3.3" + get_dynamic_library_extension();
std::string fftwfLibraryName = "libfftw3f" + get_dynamic_library_extension() + ".3";
std::string fftwfLibraryName = "libfftw3f" + get_dynamic_library_extension();
res = loadFFTWLibrary(utf8_to_wstring(fftwLibraryName), utf8_to_wstring(fftwfLibraryName));
}

#if defined(__APPLE__)
if (!res) {
res = loadFFTWLibraryOnMacOs();
}
#endif
#endif
if (res) {
#if WITH_OPENMP
Expand Down

0 comments on commit 981fe27

Please sign in to comment.