@@ -26,6 +26,49 @@ option(RAYX_REQUIRE_H5 "If option 'RAYX_ENABLE_H5' is ON, this option will add t
2626option (RAYX_STATIC_LIB "This option builds 'rayx-core' as a static library." OFF )
2727# ------------------
2828
29+ # ---- Specific macos compiler options and flags concerning OpenMP ----
30+ if (APPLE )
31+ # Detect architecture and package manager
32+ if (CMAKE_SYSTEM_PROCESSOR MATCHES "arm64" )
33+ set (HOMEBREW_PREFIX "/opt/homebrew" )
34+ else ()
35+ set (HOMEBREW_PREFIX "/usr/local" )
36+ endif ()
37+
38+ # MacPorts detection
39+ if (EXISTS "/opt/local/include/libomp" )
40+ set (OpenMP_INCLUDE_DIR "/opt/local/include/libomp" )
41+ set (OpenMP_LIBRARY "/opt/local/lib/libomp.dylib" )
42+ message (STATUS "Using MacPorts OpenMP installation" )
43+ else ()
44+ # Homebrew fallback
45+ set (OpenMP_INCLUDE_DIR "${HOMEBREW_PREFIX} /opt/libomp/include" )
46+ set (OpenMP_LIBRARY "${HOMEBREW_PREFIX} /opt/libomp/lib/libomp.dylib" )
47+ message (STATUS "Using Homebrew OpenMP installation" )
48+ endif ()
49+
50+ # Common OpenMP settings
51+ set (OpenMP_C_FLAGS "-Xpreprocessor -fopenmp -I${OpenMP_INCLUDE_DIR} " )
52+ set (OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I${OpenMP_INCLUDE_DIR} " )
53+ set (OpenMP_C_LIB_NAMES "omp" )
54+ set (OpenMP_CXX_LIB_NAMES "omp" )
55+ set (OpenMP_omp_LIBRARY "${OpenMP_LIBRARY} " )
56+ set (OpenMP_omp_INCLUDE_DIRS "${OpenMP_INCLUDE_DIR} " )
57+
58+ if (RAYX_ENABLE_OPENMP)
59+ find_package (OpenMP REQUIRED)
60+ if (OpenMP_CXX_FOUND)
61+ message (STATUS "OpenMP found:" )
62+ message (STATUS " Include dirs: ${OpenMP_CXX_INCLUDE_DIRS} " )
63+ message (STATUS " Libraries: ${OpenMP_CXX_LIBRARIES} " )
64+
65+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS} " )
66+ include_directories (${OpenMP_omp_INCLUDE_DIRS} )
67+ link_libraries (${OpenMP_omp_LIBRARY} )
68+ endif ()
69+ endif ()
70+ endif ()
71+
2972
3073# ---- Build options ----
3174set (CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR} /bin/release)
0 commit comments