Skip to content

Commit a34bff5

Browse files
Update CMakeLists.txt
1 parent 748c619 commit a34bff5

1 file changed

Lines changed: 25 additions & 44 deletions

File tree

CMakeLists.txt

Lines changed: 25 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -81,60 +81,41 @@ file(GLOB SRC_FILES ${CMAKE_SOURCE_DIR}/src/*.cpp)
8181
add_executable(next ${SRC_FILES})
8282

8383
# ============================
84-
# OpenMP detection + CI-safe auto-install
84+
# Pre-install OpenMP if needed (Clang/Linux)
8585
# ============================
86-
find_package(OpenMP QUIET)
87-
88-
if(OpenMP_CXX_FOUND)
89-
message(STATUS "OpenMP detected — enabling multithreading.")
90-
target_link_libraries(next PRIVATE OpenMP::OpenMP_CXX)
91-
92-
else()
93-
message(WARNING "OpenMP not found — attempting automatic installation (non-interactive).")
94-
95-
# Default to failure unless we explicitly succeed
96-
set(OMP_INSTALL_RESULT 1)
97-
98-
if(WIN32)
99-
message(STATUS "Installing OpenMP on Windows via winget (Build Tools)...")
100-
execute_process(
101-
COMMAND powershell -Command "winget install Microsoft.VisualStudio.2022.BuildTools --silent"
102-
RESULT_VARIABLE OMP_INSTALL_RESULT
103-
)
104-
105-
elseif(UNIX AND NOT APPLE)
106-
message(STATUS "Installing OpenMP on Linux (non-interactive)...")
86+
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND UNIX AND NOT APPLE)
87+
# Try a couple of common libomp locations; if missing, install
88+
if(NOT EXISTS "/usr/lib/llvm-18/lib/libomp.so"
89+
AND NOT EXISTS "/usr/lib/x86_64-linux-gnu/libomp.so"
90+
AND NOT EXISTS "/usr/lib/libomp.so")
91+
message(STATUS "Clang detected — installing OpenMP before configuration...")
10792

10893
if(EXISTS "/usr/bin/apt")
10994
execute_process(COMMAND sudo apt update -y)
110-
execute_process(
111-
COMMAND sudo apt install -y libomp-dev
112-
RESULT_VARIABLE OMP_INSTALL_RESULT
113-
)
114-
95+
execute_process(COMMAND sudo apt install -y libomp-dev)
11596
elseif(EXISTS "/usr/bin/dnf")
116-
execute_process(
117-
COMMAND sudo dnf install -y libomp-devel
118-
RESULT_VARIABLE OMP_INSTALL_RESULT
119-
)
120-
97+
execute_process(COMMAND sudo dnf install -y libomp-devel)
12198
elseif(EXISTS "/usr/bin/pacman")
122-
execute_process(
123-
COMMAND sudo pacman -Sy --noconfirm openmp
124-
RESULT_VARIABLE OMP_INSTALL_RESULT
125-
)
126-
99+
execute_process(COMMAND sudo pacman -Sy --noconfirm openmp)
127100
elseif(EXISTS "/usr/bin/zypper")
128-
execute_process(
129-
COMMAND sudo zypper install -y libomp-devel
130-
RESULT_VARIABLE OMP_INSTALL_RESULT
131-
)
132-
101+
execute_process(COMMAND sudo zypper install -y libomp-devel)
133102
else()
134103
message(FATAL_ERROR "Unsupported Linux distro for automatic OpenMP installation.")
135104
endif()
105+
endif()
106+
endif()
136107

137-
else()
108+
# ============================
109+
# OpenMP detection (after any pre-install)
110+
# ============================
111+
find_package(OpenMP QUIET)
112+
113+
if(OpenMP_CXX_FOUND)
114+
message(STATUS "OpenMP detected — enabling multithreading.")
115+
target_link_libraries(next PRIVATE OpenMP::OpenMP_CXX)
116+
else()
117+
message(STATUS "OpenMP not found — building in single-threaded mode.")
118+
endif()
138119
message(FATAL_ERROR "Automatic OpenMP installation not supported on this OS.")
139120
endif()
140121

@@ -145,4 +126,4 @@ else()
145126
message(FATAL_ERROR "Automatic OpenMP installation failed. Check CI logs and package manager output.")
146127
endif()
147128

148-
endif()
129+
endif()

0 commit comments

Comments
 (0)