diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index 5ab4a67..f6c3374 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -19,13 +19,17 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest] + os: [ubuntu-latest, windows-latest, macos-latest] steps: - uses: actions/checkout@v4 with: submodules: 'recursive' + - name: Install OpenMP on macOS + if: matrix.os == 'macos-latest' + run: brew install libomp + - name: Setup MSVC Developer Command Prompt if: matrix.os == 'windows-latest' uses: TheMrMilchmann/setup-msvc-dev@v3.0.1 diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fd6f1c..1ba6364 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,13 +57,29 @@ set(EIGEN_INCLUDE_DIRS ${EIGEN3_INCLUDE_DIR}) # ============================================================================== # Find OpenMP # ============================================================================== +if(APPLE AND USE_OPENMP) + # Help CMake find Homebrew's libomp on macOS + execute_process(COMMAND brew --prefix libomp + OUTPUT_VARIABLE LIBOMP_PREFIX + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET) + if(LIBOMP_PREFIX) + set(OpenMP_CXX_FLAGS "-Xclang -fopenmp" CACHE STRING "" FORCE) + set(OpenMP_CXX_LIB_NAMES "omp" CACHE STRING "" FORCE) + set(OpenMP_omp_LIBRARY "${LIBOMP_PREFIX}/lib/libomp.dylib" CACHE STRING "" FORCE) + include_directories("${LIBOMP_PREFIX}/include") + endif() +endif() + find_package(OpenMP) if (USE_OPENMP) if(NOT OPENMP_FOUND) - message(FATAL_ERROR "OPENMP not found.") + message(WARNING "OpenMP not found. Building without OpenMP support.") + set(USE_OPENMP OFF) + else() + add_definitions(-DUSE_OPENMP) + set(TRGT_LNK_LBS_ADDITIONAL OpenMP::OpenMP_CXX) endif() - add_definitions(-DUSE_OPENMP) - set(TRGT_LNK_LBS_ADDITIONAL OpenMP::OpenMP_CXX) endif (USE_OPENMP) # ==============================================================================