Skip to content

Commit

Permalink
Fix OpenMP build with libomp 15+ (#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
hcho3 committed Oct 27, 2022
1 parent b86063e commit 2a92dad
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set (CMAKE_FIND_NO_INSTALL_PREFIX TRUE FORCE)
cmake_minimum_required (VERSION 3.13)
project(treelite LANGUAGES CXX C VERSION 3.0.0)
project(treelite LANGUAGES CXX C VERSION 3.1.0)

set(CMAKE_CXX_STANDARD 14)

Expand Down
22 changes: 19 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,28 @@ endif(UNIX)
add_library(objtreelite_common OBJECT) # Component shared by both main package and runtime

if(USE_OPENMP)
if (APPLE)
if(APPLE)
# Require CMake 3.16+ on Mac OSX, as previous versions of CMake had trouble locating
# OpenMP on Mac. See https://github.com/dmlc/xgboost/pull/5146#issuecomment-568312706
cmake_minimum_required(VERSION 3.16)
endif (APPLE)
find_package(OpenMP REQUIRED)
find_package(OpenMP)
if (NOT OpenMP_FOUND)
# Try again with extra path info; required for libomp 15+ from Homebrew
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)
find_package(OpenMP REQUIRED)
endif()
else()
find_package(OpenMP REQUIRED)
endif()
else()
message(STATUS "Disabling OpenMP")
endif()
Expand Down

0 comments on commit 2a92dad

Please sign in to comment.