Skip to content

Commit e5d9852

Browse files
committed
- allow to provide alternative libomp prefix
this is needed, because of different architectures, where brew would not be able to provide the correct library
1 parent ebd0b28 commit e5d9852

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

CMakeLists.txt

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -424,19 +424,26 @@ if (ENABLE_OMP)
424424
if (APPLE)
425425
find_package (OpenMP)
426426
if(NOT OpenMP_FOUND)
427-
# libomp 15.0+ from brew is keg-only, so have to search in other locations.
428-
# See https://github.com/Homebrew/homebrew-core/issues/112107#issuecomment-1278042927.
429-
execute_process(COMMAND brew --prefix libomp
430-
OUTPUT_VARIABLE HOMEBREW_LIBOMP_PREFIX
431-
OUTPUT_STRIP_TRAILING_WHITESPACE)
427+
428+
# read LIBOMP_PREFIX from environment variable
429+
if(DEFINED ENV{LIBOMP_PREFIX})
430+
set(LIBOMP_PREFIX $ENV{LIBOMP_PREFIX})
431+
else()
432+
# libomp 15.0+ from brew is keg-only, so have to search in other locations.
433+
# See https://github.com/Homebrew/homebrew-core/issues/112107#issuecomment-1278042927.
434+
execute_process(COMMAND brew --prefix libomp
435+
OUTPUT_VARIABLE LIBOMP_PREFIX
436+
OUTPUT_STRIP_TRAILING_WHITESPACE)
437+
endif()
438+
432439
# Apple/Homebrew Clang needs -Xpreprocessor to accept -fopenmp.
433440
# Store as a CMake list (semicolon-separated) so target_compile_options
434441
# passes each token as a separate argument to the compiler.
435-
set(OpenMP_C_FLAGS "-Xpreprocessor;-fopenmp;-I${HOMEBREW_LIBOMP_PREFIX}/include")
436-
set(OpenMP_CXX_FLAGS "-Xpreprocessor;-fopenmp;-I${HOMEBREW_LIBOMP_PREFIX}/include")
442+
set(OpenMP_C_FLAGS "-Xpreprocessor;-fopenmp;-I${LIBOMP_PREFIX}/include")
443+
set(OpenMP_CXX_FLAGS "-Xpreprocessor;-fopenmp;-I${LIBOMP_PREFIX}/include")
437444
set(OpenMP_C_LIB_NAMES omp)
438445
set(OpenMP_CXX_LIB_NAMES omp)
439-
set(OpenMP_omp_LIBRARY ${HOMEBREW_LIBOMP_PREFIX}/lib/libomp.dylib)
446+
set(OpenMP_omp_LIBRARY ${LIBOMP_PREFIX}/lib/libomp.dylib)
440447
set(OMP_HAVE_MONOTONIC 1 CACHE INTERNAL "" FORCE)
441448
endif()
442449
endif()

0 commit comments

Comments
 (0)