Skip to content

Commit 36e1f34

Browse files
committed
fixed two issues: macos pathes and libomp
1 parent 9681b4c commit 36e1f34

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

CMakeLists.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,49 @@ option(RAYX_REQUIRE_H5 "If option 'RAYX_ENABLE_H5' is ON, this option will add t
2626
option(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 ----
3174
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/bin/release)

Intern/rayx-core/src/Rml/Locate.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <windows.h>
1010
#elif defined(__APPLE__)
1111
#include <cassert>
12+
#include <libproc.h>
13+
#include <unistd.h>
1214
#else
1315
#include <limits.h>
1416
#include <unistd.h>
@@ -63,6 +65,17 @@ std::filesystem::path ResourceHandler::getExecutablePath() {
6365
// If the buffer was too small, increase size and retry
6466
buffer.resize(buffer.size() * 2);
6567
}
68+
#elif defined(__APPLE__)
69+
std::vector<char> buffer(PROC_PIDPATHINFO_MAXSIZE);
70+
pid_t pid = getpid();
71+
int ret = proc_pidpath(pid, buffer.data(), buffer.size());
72+
if (ret <= 0) {
73+
// Fehler beim Auslesen des Pfads
74+
return std::filesystem::path();
75+
}
76+
buffer[ret] = '\0'; // Null-terminieren, falls nicht bereits geschehen
77+
// Optional: buffer kann länger als der Pfad sein, daher String kürzen
78+
return std::filesystem::path(buffer.data());
6679

6780
#else
6881
static_assert(false, "macOS support is not implemented yet");
@@ -80,7 +93,7 @@ std::filesystem::path ResourceHandler::getFullPath(const std::filesystem::path&
8093
}
8194
}
8295

83-
#if defined(__linux__)
96+
#if defined(__linux__) || defined(__APPLE__)
8497
// Check in /usr (package install)
8598
std::filesystem::path path = std::filesystem::path("/usr") / baseDir / relativePath;
8699
if (fileExists(path)) return path;

0 commit comments

Comments
 (0)