Skip to content

Commit 1f46240

Browse files
authored
Update OpenMP detection for macOS (#15040)
Updated OpenMP detection for macOS with hints to brew library paths and set required compile flags.
1 parent d43ba29 commit 1f46240

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

dependencies/FindOpenMPMacOS.cmake

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,53 @@
1+
# Copyright 2019-2026 CERN and copyright holders of ALICE O2.
2+
# See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
# All rights not expressly granted are reserved.
4+
#
5+
# This software is distributed under the terms of the GNU General Public
6+
# License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
#
8+
# In applying this license CERN does not waive the privileges and immunities
9+
# granted to it by virtue of its status as an Intergovernmental Organization
10+
# or submit itself to any jurisdiction.
11+
112
find_library(OpenMP_LIBRARY
2-
NAMES omp
13+
NAMES omp libomp
14+
HINTS
15+
/opt/homebrew/opt/libomp/lib
16+
/usr/local/opt/libomp/lib
317
)
418

519
find_path(OpenMP_INCLUDE_DIR
6-
omp.h
20+
NAMES omp.h
21+
HINTS
22+
/opt/homebrew/opt/libomp/include
23+
/usr/local/opt/libomp/include
724
)
825

926
mark_as_advanced(OpenMP_LIBRARY OpenMP_INCLUDE_DIR)
1027

1128
include(FindPackageHandleStandardArgs)
12-
find_package_handle_standard_args(OpenMP DEFAULT_MSG
13-
OpenMP_LIBRARY OpenMP_INCLUDE_DIR)
29+
find_package_handle_standard_args(
30+
OpenMPMacOS
31+
DEFAULT_MSG
32+
OpenMP_LIBRARY OpenMP_INCLUDE_DIR
33+
)
1434

15-
if (OpenMP_FOUND)
35+
if (OpenMPMacOS_FOUND)
1636
set(OpenMP_LIBRARIES ${OpenMP_LIBRARY})
1737
set(OpenMP_INCLUDE_DIRS ${OpenMP_INCLUDE_DIR})
18-
set(OpenMP_COMPILE_OPTIONS -Xpreprocessor -fopenmp)
1938

20-
set(OpenMP_CXX_FOUND True)
21-
set(OpenMPMacOS_FOUND True)
22-
add_library(OpenMP::OpenMP_CXX SHARED IMPORTED)
39+
set(OpenMP_CXX_FOUND TRUE)
40+
set(OpenMP_FOUND TRUE)
41+
42+
add_library(OpenMP::OpenMP_CXX INTERFACE IMPORTED)
2343
set_target_properties(OpenMP::OpenMP_CXX PROPERTIES
24-
IMPORTED_LOCATION ${OpenMP_LIBRARIES}
2544
INTERFACE_INCLUDE_DIRECTORIES "${OpenMP_INCLUDE_DIRS}"
26-
INTERFACE_COMPILE_OPTIONS "${OpenMP_COMPILE_OPTIONS}"
45+
INTERFACE_COMPILE_OPTIONS "-Xclang;-fopenmp"
46+
INTERFACE_LINK_LIBRARIES "${OpenMP_LIBRARIES}"
47+
)
48+
message(STATUS
49+
"Found OpenMP (macOS workaround): "
50+
"library=${OpenMP_LIBRARY}, "
51+
"include=${OpenMP_INCLUDE_DIR}"
2752
)
2853
endif()

0 commit comments

Comments
 (0)