diff --git a/CMakeLists.txt b/CMakeLists.txt index a300feae031..471ee04dd41 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -288,11 +288,17 @@ endif() option(WITH_OPENMP "Build with parallelization using OpenMP" TRUE) if(WITH_OPENMP) if(APPLE) - set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp -I/usr/local/opt/libomp/include") - set(OpenMP_C_LIB_NAMES "omp") - set(OpenMP_CXX_FLAGS "${OpenMP_C_FLAGS}") - set(OpenMP_CXX_LIB_NAMES "${OpenMP_C_LIB_NAMES}") - set(OpenMP_omp_LIBRARY "/usr/local/opt/libomp/lib/libomp.dylib") + # libomp 15.0+ from brew is keg-only, + # because it can override GCC headers and result in broken builds, + # so have to search in other locations. + execute_process(COMMAND brew --prefix libomp + OUTPUT_VARIABLE HOMEBREW_LIBOMP_PREFIX + OUTPUT_STRIP_TRAILING_WHITESPACE) + set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp -I${HOMEBREW_LIBOMP_PREFIX}/include") + set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I${HOMEBREW_LIBOMP_PREFIX}/include") + set(OpenMP_C_LIB_NAMES omp) + set(OpenMP_CXX_LIB_NAMES omp) + set(OpenMP_omp_LIBRARY ${HOMEBREW_LIBOMP_PREFIX}/lib/libomp.dylib) endif() find_package(OpenMP COMPONENTS C CXX) endif()