Skip to content

Commit 0686512

Browse files
committed
move more of the matlab openmp logic to cmake script
1 parent 21c0812 commit 0686512

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

CMakeLists.txt

+18-5
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,30 @@ if(FINUFFT_BUILD_MATLAB)
2424
# When building for matlab, we will fetch the OpenMP library used by matlab
2525
# instead of system default for compatibility.
2626
find_package(Matlab REQUIRED)
27-
find_library(OpenMP_iomp5_LIBRARY NAMES iomp5 HINTS ${Matlab_ROOT_DIR}/sys/os/ PATH_SUFFIXES glnxa64 maci64)
28-
find_library(OpenMP_pthreads_LIBRARY NAMES pthread CMAKE_FIND_ROOT_PATH_BOTH)
27+
find_library(matlab_iomp5_lib NAMES iomp5 HINTS ${Matlab_ROOT_DIR}/sys/os/ PATH_SUFFIXES glnxa64 maci64)
28+
find_library(pthreads_lib NAMES pthread CMAKE_FIND_ROOT_PATH_BOTH)
29+
30+
# Create a "fake" imported library pointing to the matlab openmp implementation
31+
add_library(OpenMP::OpenMP_CXX SHARED IMPORTED)
32+
set_target_properties(OpenMP::OpenMP_CXX PROPERTIES IMPORTED_LOCATION ${matlab_iomp5_lib})
33+
target_link_libraries(OpenMP::OpenMP_CXX INTERFACE ${pthreads_lib})
34+
# Set the OpenMP flag.
35+
if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
36+
target_compile_options(OpenMP::OpenMP_CXX INTERFACE -Xclang -fopenmp)
37+
else()
38+
target_compile_options(OpenMP::OpenMP_CXX INTERFACE -fopenmp)
39+
endif()
40+
else()
41+
# For non-matlab builds, find system OpenMP
42+
if(FINUFFT_USE_OPENMP)
43+
find_package(OpenMP REQUIRED)
44+
endif()
2945
endif()
3046

3147
# Find required packages
3248
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
3349
find_package(FFTW REQUIRED)
3450

35-
if(FINUFFT_USE_OPENMP)
36-
find_package(OpenMP REQUIRED)
37-
endif()
3851

3952
set(FINUFFT_FFTW_LIBRARIES "FFTW::Float" "FFTW::Double" "FFTW::Float${FINUFFT_FFTW_SUFFIX}" "FFTW::Double${FINUFFT_FFTW_SUFFIX}")
4053

CMakePresets.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,7 @@
7777
"cacheVariables": {
7878
"FINUFFT_FFTW_SUFFIX": "Threads",
7979
"FINUFFT_BUILD_MATLAB": "ON",
80-
"FINUFFT_ENABLE_SANITIZERS": "OFF",
81-
"OpenMP_C_LIB_NAMES": "iomp5;pthreads",
82-
"OpenMP_CXX_LIB_NAMES": "iomp5;pthreads",
83-
"OpenMP_C_FLAGS": "-fopenmp",
84-
"OpenMP_CXX_FLAGS": "-fopenmp"
80+
"FINUFFT_ENABLE_SANITIZERS": "OFF"
8581
}
8682
}
8783
],

0 commit comments

Comments
 (0)