From a2fd3166e786fa6c347ceb0810e354ab16aebe86 Mon Sep 17 00:00:00 2001 From: Christopher Weyand Date: Mon, 4 Dec 2023 11:21:49 +0100 Subject: [PATCH] find omp fallback for macos --- .github/workflows/ci.yml | 1 + source/girgs/CMakeLists.txt | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c1da7c4..b57797b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,6 +18,7 @@ jobs: matrix: build_type: [Release, Debug] + cpp_compiler: [cl, g++, clang++, c++] include: - os: windows-latest c_compiler: cl diff --git a/source/girgs/CMakeLists.txt b/source/girgs/CMakeLists.txt index 5a021d7..045793b 100644 --- a/source/girgs/CMakeLists.txt +++ b/source/girgs/CMakeLists.txt @@ -4,7 +4,28 @@ # # find_package(THIRDPARTY REQUIRED) -find_package(OpenMP REQUIRED) +find_package(OpenMP) + +# FindOpenMP.cmake does not reliably find a user installed openmp library for clang/llvm on +# both Linux- and macOS-systems (even for CMake Version >= 3.12). The following section +# manually sets the required fields for clang-like compiler. +if(NOT OpenMP_FOUND) + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") + # This will find default libomp-installations for homebrew/MacPorts + find_library(LIBOMP_PATH NAMES omp PATHS "/usr/local/opt/libomp/lib" "/opt/local/lib/libomp" "/opt/homebrew/opt/libomp/lib") + find_path(LIBOMP_INCLUDE NAMES omp.h PATHS "/usr/local/opt/libomp/include" "/opt/local/include/libomp" "/opt/homebrew/opt/libomp/include") + if(LIBOMP_PATH AND LIBOMP_INCLUDE) + set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I${LIBOMP_INCLUDE}" CACHE STRING "Manually set" FORCE) + set(OpenMP_CXX_LIB_NAMES "omp" CACHE STRING "Manually set" FORCE) + set(OpenMP_omp_LIBRARY "${LIBOMP_PATH}" CACHE STRING "Manually set" FORCE) + endif() + endif() + + # After setting basic OpenMP-folders, run find_package again to set everything. Also acts as a final sanity check. + find_package(OpenMP REQUIRED) + message(STATUS "OMP lib found manually after CMake module failed") +endif() + # # Library name and options