From d5ab3581fe655f418b3c5ad95d9a8874a9972553 Mon Sep 17 00:00:00 2001 From: Renato Golin Date: Thu, 21 Nov 2024 10:28:41 +0000 Subject: [PATCH] [CMake] Add hack to find LLVM's OpenMP with GCC --- cmake/modules/openmp.cmake | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cmake/modules/openmp.cmake b/cmake/modules/openmp.cmake index 2cb2cfe3f..87fc327c4 100644 --- a/cmake/modules/openmp.cmake +++ b/cmake/modules/openmp.cmake @@ -1,5 +1,19 @@ option(USE_OpenMP "Use OpenMP" ON) +# We don't want GOMP because its performance sinks for large core count, so we force libomp +# This finds the library path from the system's clang for OpenMP +# +# On Fedora, it's at the same place as others, so we don't need to look elsewhere +# On Ubuntu, it's in /usr/lib/llvm-${version}, so find_package finds GOMP for GCC instead. +execute_process ( + COMMAND bash -c "for lib in $(clang -lomp -### 2>&1); do echo $lib | grep -o \"\\/.*llvm.*\\w\"; done" + OUTPUT_VARIABLE LLVM_OMP_PATH +) +# Only if we found an "llvm" path that we need to add +if (LLVM_OMP_PATH) + set(CMAKE_PREFIX_PATH ${LLVM_OMP_PATH}) +endif() + if(USE_OpenMP) find_package(OpenMP) if(OPENMP_FOUND)