1- cmake_minimum_required (VERSION 3.10 )
2-
3- project (NEXT)
4-
5- # Output directories
6- set (CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR } /build)
7- set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR } )
8- set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR } )
9- set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR } )
10-
11- # Precision / SIMD mode options
12- option (NEXT_FP32 "Use 32-bit floats (scalar)" OFF )
13- option (NEXT_FP64 "Use 64-bit floats (scalar)" ON )
14- option (NEXT_SIMD32 "Use 32-bit SIMD (SSE)" OFF )
15- option (NEXT_SIMD64 "Use 64-bit SIMD (SSE)" OFF )
16- option (NEXT_AVX512_32 "Use 32-bit SIMD (AVX-512)" OFF )
17- option (NEXT_AVX512_64 "Use 64-bit SIMD (AVX-512)" OFF )
18-
19- # List of all modes
20- set (NEXT_MODES
21- NEXT_FP32
22- NEXT_FP64
23- NEXT_SIMD32
24- NEXT_SIMD64
25- NEXT_AVX512_32
26- NEXT_AVX512_64
27- )
28-
29- # Count enabled modes
30- set (NEXT_MODE_COUNT 0)
31- foreach (m ${NEXT_MODES} )
32- if (${m} )
33- math (EXPR NEXT_MODE_COUNT "${NEXT_MODE_COUNT} + 1" )
34- endif ()
35- endforeach ()
36-
37- # Enforce exactly one mode
38- if (NEXT_MODE_COUNT EQUAL 0)
39- message (FATAL_ERROR "You must enable one precision/SIMD mode." )
40- elseif (NEXT_MODE_COUNT GREATER 1)
41- message (FATAL_ERROR "You must enable ONLY ONE of: NEXT_FP32, NEXT_FP64, NEXT_SIMD32, NEXT_SIMD64, NEXT_AVX512_32, NEXT_AVX512_64." )
42- endif ()
43-
44- # Apply compile definitions and flags
45- if (NEXT_FP32)
46- add_compile_definitions (NEXT_FP32 )
47-
48- elseif (NEXT_FP64)
49- add_compile_definitions (NEXT_FP64 )
50-
51- elseif (NEXT_SIMD32)
52- add_compile_definitions (NEXT_SIMD32 )
53- add_compile_options (-msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 )
54-
55- elseif (NEXT_SIMD64)
56- add_compile_definitions (NEXT_SIMD64 )
57- add_compile_options (-msse2 -msse3 -mssse3 -msse4.1 -msse4.2 )
58-
59- elseif (NEXT_AVX512_32)
60- add_compile_definitions (NEXT_AVX512_32 )
61- add_compile_options (-mavx512f -mavx512dq -mavx512vl )
62-
63- elseif (NEXT_AVX512_64)
64- add_compile_definitions (NEXT_AVX512_64 )
65- add_compile_options (-mavx512f -mavx512dq -mavx512vl )
66-
67- endif ()
68-
69- # Includes and sources
70- include_directories (${CMAKE_SOURCE_DIR } /include )
71- include_directories (${CMAKE_SOURCE_DIR } /src )
72- file (GLOB SRC_FILES ${CMAKE_SOURCE_DIR } /src/*.cpp )
73-
74- # Build executable
75- add_executable (next ${SRC_FILES} )
76-
1+ cmake_minimum_required (VERSION 3.10 )
2+
3+ project (NEXT)
4+
5+ # ============================
6+ # Output directories
7+ # ============================
8+ set (CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR } /build)
9+ set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR } )
10+ set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR } )
11+ set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR } )
12+
13+ # ============================
14+ # Precision / SIMD mode options
15+ # ============================
16+ option (NEXT_FP32 "Use 32-bit floats (scalar)" OFF )
17+ option (NEXT_FP64 "Use 64-bit floats (scalar)" ON )
18+ option (NEXT_SIMD32 "Use 32-bit SIMD (SSE)" OFF )
19+ option (NEXT_SIMD64 "Use 64-bit SIMD (SSE)" OFF )
20+ option (NEXT_AVX512_32 "Use 32-bit SIMD (AVX-512)" OFF )
21+ option (NEXT_AVX512_64 "Use 64-bit SIMD (AVX-512)" OFF )
22+
23+ set (NEXT_MODES
24+ NEXT_FP32
25+ NEXT_FP64
26+ NEXT_SIMD32
27+ NEXT_SIMD64
28+ NEXT_AVX512_32
29+ NEXT_AVX512_64
30+ )
31+
32+ # Count enabled modes
33+ set (NEXT_MODE_COUNT 0)
34+ foreach (m ${NEXT_MODES} )
35+ if (${m} )
36+ math (EXPR NEXT_MODE_COUNT "${NEXT_MODE_COUNT} + 1" )
37+ endif ()
38+ endforeach ()
39+
40+ # Enforce exactly one mode
41+ if (NEXT_MODE_COUNT EQUAL 0)
42+ message (FATAL_ERROR "You must enable one precision/SIMD mode." )
43+ elseif (NEXT_MODE_COUNT GREATER 1)
44+ message (FATAL_ERROR "You must enable ONLY ONE of: NEXT_FP32, NEXT_FP64, NEXT_SIMD32, NEXT_SIMD64, NEXT_AVX512_32, NEXT_AVX512_64." )
45+ endif ()
46+
47+ # ============================
48+ # Apply compile definitions and flags
49+ # ============================
50+ if (NEXT_FP32)
51+ add_compile_definitions (NEXT_FP32 )
52+
53+ elseif (NEXT_FP64)
54+ add_compile_definitions (NEXT_FP64 )
55+
56+ elseif (NEXT_SIMD32)
57+ add_compile_definitions (NEXT_SIMD32 )
58+ add_compile_options (-msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 )
59+
60+ elseif (NEXT_SIMD64)
61+ add_compile_definitions (NEXT_SIMD64 )
62+ add_compile_options (-msse2 -msse3 -mssse3 -msse4.1 -msse4.2 )
63+
64+ elseif (NEXT_AVX512_32)
65+ add_compile_definitions (NEXT_AVX512_32 )
66+ add_compile_options (-mavx512f -mavx512dq -mavx512vl )
67+
68+ elseif (NEXT_AVX512_64)
69+ add_compile_definitions (NEXT_AVX512_64 )
70+ add_compile_options (-mavx512f -mavx512dq -mavx512vl )
71+
72+ endif ()
73+
74+ # ============================
75+ # Includes and sources
76+ # ============================
77+ include_directories (${CMAKE_SOURCE_DIR } /include )
78+ include_directories (${CMAKE_SOURCE_DIR } /src )
79+ file (GLOB SRC_FILES ${CMAKE_SOURCE_DIR } /src/*.cpp )
80+
81+ add_executable (next ${SRC_FILES} )
82+
83+ # ============================
84+ # OpenMP detection + CI-safe auto-install
85+ # ============================
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)..." )
107+
108+ if (EXISTS "/usr/bin/apt" )
109+ 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+
115+ elseif (EXISTS "/usr/bin/dnf" )
116+ execute_process (
117+ COMMAND sudo dnf install -y libomp-devel
118+ RESULT_VARIABLE OMP_INSTALL_RESULT
119+ )
120+
121+ elseif (EXISTS "/usr/bin/pacman" )
122+ execute_process (
123+ COMMAND sudo pacman -Sy --noconfirm openmp
124+ RESULT_VARIABLE OMP_INSTALL_RESULT
125+ )
126+
127+ elseif (EXISTS "/usr/bin/zypper" )
128+ execute_process (
129+ COMMAND sudo zypper install -y libomp-devel
130+ RESULT_VARIABLE OMP_INSTALL_RESULT
131+ )
132+
133+ else ()
134+ message (FATAL_ERROR "Unsupported Linux distro for automatic OpenMP installation." )
135+ endif ()
136+
137+ else ()
138+ message (FATAL_ERROR "Automatic OpenMP installation not supported on this OS." )
139+ endif ()
140+
141+ if (OMP_INSTALL_RESULT EQUAL 0)
142+ message (STATUS "OpenMP installed successfully. Re-run CMake configuration." )
143+ message (FATAL_ERROR "" )
144+ else ()
145+ message (FATAL_ERROR "Automatic OpenMP installation failed. Check CI logs and package manager output." )
146+ endif ()
147+
148+ endif ()
0 commit comments