-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
352 lines (306 loc) · 13 KB
/
CMakeLists.txt
File metadata and controls
352 lines (306 loc) · 13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
cmake_minimum_required(VERSION 3.16)
project(DiNoLibProject)
message(STATUS "----------------------------------------------------")
message(STATUS "Configuring project: ${CMAKE_PROJECT_NAME}")
message(STATUS "CMake version: ${CMAKE_VERSION}")
message(STATUS "Source directory: ${CMAKE_SOURCE_DIR}")
message(STATUS "Binary directory: ${CMAKE_BINARY_DIR}")
message(STATUS "----------------------------------------------------")
# Set C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
message(STATUS "C++ standard set to: ${CMAKE_CXX_STANDARD}")
# Compiler flags
add_compile_options(-march=native
-mavx
-mavx2
-msse3
-O2
-g
-fopenmp
-Wuninitialized
# -Wunused-variable
-Wparentheses
)
message(STATUS "Common compiler options added.")
message(DEBUG "Compiler options: -march=native -mavx -mavx2 -msse3 -O2 -g -fopenmp -Wuninitialized -Wparentheses")
# Set option
option(DEBUG_MSG "Enable verbose debug messages" OFF)
option(BUILD_PYTHON "Build Python bindings using pybind11" OFF)
option(BUILD_BENCHMARK "Build benchmark executables" OFF)
option(BUILD_DEMO "Build the demo folder" ON)
option(BUILD_TESTS "Build test executables" OFF)
option(BUILD_ODYSSEY "Build Odyssey components with MPI support" OFF)
option(ODYSSEY_DEBUG_RESULTS "Print Odyssey search results (query_result) for debug before copy to I,D" OFF)
option(BUILD_SING "Enable CUDA support" OFF)
# Backward compatibility: ENABLE_MPI and ODYSSEY_MPI map to BUILD_ODYSSEY
if(DEFINED ENABLE_MPI)
if(ENABLE_MPI STREQUAL "OFF" OR NOT ENABLE_MPI)
set(BUILD_ODYSSEY OFF CACHE BOOL "Build Odyssey components with MPI support" FORCE)
if(DEBUG_MSG)
message(STATUS "ENABLE_MPI=OFF detected, setting BUILD_ODYSSEY=OFF")
endif()
endif()
endif()
if(DEFINED ODYSSEY_MPI)
if(ODYSSEY_MPI STREQUAL "OFF" OR NOT ODYSSEY_MPI)
set(BUILD_ODYSSEY OFF CACHE BOOL "Build Odyssey components with MPI support" FORCE)
if(DEBUG_MSG)
message(STATUS "ODYSSEY_MPI=OFF detected (deprecated), setting BUILD_ODYSSEY=OFF")
endif()
elseif(ODYSSEY_MPI STREQUAL "ON" OR ODYSSEY_MPI)
set(BUILD_ODYSSEY ON CACHE BOOL "Build Odyssey components with MPI support" FORCE)
if(DEBUG_MSG)
message(STATUS "ODYSSEY_MPI=ON detected (deprecated), setting BUILD_ODYSSEY=ON")
endif()
endif()
endif()
message(STATUS " DEBUG_MSG: ${DEBUG_MSG}")
message(STATUS "Build options:")
message(STATUS " BUILD_PYTHON: ${BUILD_PYTHON}")
message(STATUS " BUILD_BENCHMARK: ${BUILD_BENCHMARK}")
message(STATUS " BUILD_DEMO: ${BUILD_DEMO}")
message(STATUS " BUILD_TESTS: ${BUILD_TESTS}")
message(STATUS " BUILD_ODYSSEY: ${BUILD_ODYSSEY}")
message(STATUS " ODYSSEY_DEBUG_RESULTS: ${ODYSSEY_DEBUG_RESULTS}")
message(STATUS " BUILD_SING: ${BUILD_SING}")
# Define PROJECT_ROOT_DIR for all targets (paramSetup.cpp is compiled by commons_lib and by benchmark executables)
get_filename_component(PROJECT_ROOT_DIR "${CMAKE_SOURCE_DIR}" ABSOLUTE)
add_compile_definitions(PROJECT_ROOT_DIR="${PROJECT_ROOT_DIR}")
if(DEBUG_MSG)
message(STATUS "PROJECT_ROOT_DIR set to: ${PROJECT_ROOT_DIR}")
endif()
# Use ODYSSEY_DEBUG_RESULTS so CMake does not warn "variable not used", and propagate to C++
if(ODYSSEY_DEBUG_RESULTS)
add_compile_definitions(ODYSSEY_DEBUG_RESULTS=1)
endif()
# Initialize BUILD_ODYSSEY_AVAILABLE to FALSE by default.
# It's kept as CACHE INTERNAL for user persistency, but its value will be updated.
set(BUILD_ODYSSEY_AVAILABLE FALSE CACHE INTERNAL "Internal flag indicating if MPI is available.")
if(DEBUG_MSG)
message(DEBUG "BUILD_ODYSSEY_AVAILABLE initialized to: ${BUILD_ODYSSEY_AVAILABLE}")
endif()
if (BUILD_ODYSSEY)
if(DEBUG_MSG)
message(STATUS "Attempting to build with MPI support (BUILD_ODYSSEY is ON)...")
endif()
find_package(MPI QUIET REQUIRED CXX)
if (MPI_FOUND)
if(DEBUG_MSG)
message(STATUS "MPI found and will be used:")
message(STATUS " C++ Compiler: ${MPI_CXX_COMPILER}")
message(STATUS " Includes: ${MPI_CXX_INCLUDE_DIRS}")
message(STATUS " Libraries: ${MPI_CXX_LIBRARIES}")
endif()
# Set the flag to TRUE if MPI was found. This update needs to happen BEFORE subdirectories.
set(BUILD_ODYSSEY_AVAILABLE TRUE CACHE INTERNAL "Internal flag indicating MPI is available.")
if(DEBUG_MSG)
message(DEBUG "BUILD_ODYSSEY_AVAILABLE updated to: ${BUILD_ODYSSEY_AVAILABLE} (MPI_FOUND)")
endif()
else()
if(DEBUG_MSG)
message(WARNING "MPI not found despite BUILD_ODYSSEY being ON. Odyssey MPI components will NOT be built.")
message(WARNING "To resolve this, please install an MPI implementation (e.g., OpenMPI, MPICH) or set BUILD_ODYSSEY=OFF.")
endif()
# If MPI is not found, we explicitly set the flag back to FALSE to prevent issues.
set(BUILD_ODYSSEY_AVAILABLE FALSE CACHE INTERNAL "Internal flag indicating MPI is available.")
if(DEBUG_MSG)
message(DEBUG "BUILD_ODYSSEY_AVAILABLE updated to: ${BUILD_ODYSSEY_AVAILABLE} (MPI_NOT_FOUND)")
endif()
endif()
else()
if(DEBUG_MSG)
message(STATUS "Building without MPI support (BUILD_ODYSSEY is OFF).")
endif()
# Ensure this is set if the option is OFF, before subdirectories.
set(BUILD_ODYSSEY_AVAILABLE FALSE CACHE INTERNAL "Internal flag indicating MPI is available.")
if(DEBUG_MSG)
message(DEBUG "BUILD_ODYSSEY_AVAILABLE confirmed as: ${BUILD_ODYSSEY_AVAILABLE} (BUILD_ODYSSEY OFF)")
endif()
endif()
# Initialize BUILD_SING_AVAILABLE to FALSE by default
set(BUILD_SING_AVAILABLE FALSE CACHE INTERNAL "Internal flag indicating if CUDA is available.")
if(DEBUG_MSG)
message(DEBUG "BUILD_SING_AVAILABLE initialized to: ${BUILD_SING_AVAILABLE}")
endif()
# Support both ENABLE_CUDA and SING_CUDA for backward compatibility, mapping to BUILD_SING
if(DEFINED ENABLE_CUDA)
if(ENABLE_CUDA STREQUAL "OFF" OR NOT ENABLE_CUDA)
set(BUILD_SING OFF CACHE BOOL "Enable CUDA support" FORCE)
if(DEBUG_MSG)
message(STATUS "ENABLE_CUDA=OFF detected, setting BUILD_SING=OFF")
endif()
endif()
endif()
if(DEFINED SING_CUDA)
if(SING_CUDA STREQUAL "OFF" OR NOT SING_CUDA)
set(BUILD_SING OFF CACHE BOOL "Enable CUDA support" FORCE)
if(DEBUG_MSG)
message(STATUS "SING_CUDA=OFF detected (deprecated), setting BUILD_SING=OFF")
endif()
elseif(SING_CUDA STREQUAL "ON" OR SING_CUDA)
set(BUILD_SING ON CACHE BOOL "Enable CUDA support" FORCE)
if(DEBUG_MSG)
message(STATUS "SING_CUDA=ON detected (deprecated), setting BUILD_SING=ON")
endif()
endif()
endif()
if (BUILD_SING)
if(DEBUG_MSG)
message(STATUS "Attempting to build with CUDA support (BUILD_SING is ON)...")
endif()
# Check if CUDA is available before enabling the language
find_package(CUDAToolkit QUIET)
if(CUDAToolkit_FOUND)
# Specify CUDA architectures to avoid errors
set(CMAKE_CUDA_ARCHITECTURES 75 CACHE STRING "CUDA architectures to build for")
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES OR CMAKE_CUDA_ARCHITECTURES STREQUAL "")
set(CMAKE_CUDA_ARCHITECTURES 75 CACHE STRING "CUDA architectures to build for" FORCE)
endif()
enable_language(CUDA OPTIONAL)
else()
if(DEBUG_MSG)
message(WARNING "CUDA toolkit not found. Skipping CUDA language enable.")
endif()
endif()
if (CUDAToolkit_FOUND)
set(BUILD_SING_AVAILABLE TRUE CACHE INTERNAL "Internal flag indicating CUDA is available." FORCE)
if(DEBUG_MSG)
message(STATUS "CUDA found and will be used for SING components.")
message(DEBUG "CUDAToolkit_INCLUDE_DIRS: ${CUDAToolkit_INCLUDE_DIRS}")
message(DEBUG "CUDAToolkit_LIBRARIES: ${CUDAToolkit_LIBRARIES}")
message(DEBUG "BUILD_SING_AVAILABLE updated to: ${BUILD_SING_AVAILABLE} (CUDA_FOUND)")
endif()
else()
set(BUILD_SING_AVAILABLE FALSE CACHE INTERNAL "Internal flag indicating CUDA is available." FORCE)
if(DEBUG_MSG)
message(WARNING "CUDA not found despite BUILD_SING being ON. SING CUDA components will NOT be built.")
message(DEBUG "BUILD_SING_AVAILABLE updated to: ${BUILD_SING_AVAILABLE} (CUDA_NOT_FOUND)")
endif()
endif()
else()
set(BUILD_SING_AVAILABLE FALSE CACHE INTERNAL "Internal flag indicating CUDA is available." FORCE)
if(DEBUG_MSG)
message(STATUS "Building without CUDA support (BUILD_SING is OFF).")
message(DEBUG "BUILD_SING_AVAILABLE confirmed as: ${BUILD_SING_AVAILABLE} (BUILD_SING OFF)")
endif()
endif()
if(BUILD_TESTS)
include(CTest)
enable_testing()
endif()
# Add subdirectories
if(DEBUG_MSG)
message(STATUS "----------------------------------------------------")
message(STATUS "Adding subdirectories...")
endif()
add_subdirectory(commons)
if(DEBUG_MSG)
message(STATUS "Subdirectory 'commons' added.")
endif()
add_subdirectory(lib)
if(DEBUG_MSG)
message(STATUS "Subdirectory 'lib' added.")
endif()
if(BUILD_DEMO)
add_subdirectory(demos)
if(DEBUG_MSG)
message(STATUS "Subdirectory 'demos' added.")
endif()
endif()
if(BUILD_TESTS)
add_subdirectory(tests)
if(DEBUG_MSG)
message(STATUS "Subdirectory 'tests' added.")
endif()
endif()
# Conditionally add Python bindings
if(BUILD_PYTHON)
if(DEBUG_MSG)
message(STATUS "----------------------------------------------------")
message(STATUS "BUILD_PYTHON is ON. Adding Python bindings.")
endif()
# --- ADD THIS SECTION ---
# Find Python development components *before* adding pybind11
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
if(NOT Python3_FOUND)
message(FATAL_ERROR "Python 3 development headers not found. Please install python3-dev (or similar) or set BUILD_PYTHON=OFF.")
endif()
message(STATUS "Python found: ${Python3_EXECUTABLE}")
message(STATUS "Python include dirs: ${Python3_INCLUDE_DIRS}")
message(STATUS "Python libraries: ${Python3_LIBRARIES}")
# --- END ADDITION ---
# Add pybind11
add_subdirectory(extern/pybind11)
if(DEBUG_MSG)
message(STATUS "Subdirectory 'extern/pybind11' added.")
endif()
# Build the Python module as daisy._core
pybind11_add_module(daisy_core pybinds/setup.cpp)
set_target_properties(daisy_core PROPERTIES
OUTPUT_NAME "_core"
PREFIX "" # no 'lib' prefix, produce _core.cpython-*.so
LIBRARY_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/daisy"
)
if(DEBUG_MSG)
message(STATUS "Python module 'daisy._core' created from pybinds/setup.cpp.")
endif()
target_link_libraries(daisy_core PRIVATE dino_lib)
if(DEBUG_MSG)
message(STATUS "Python module 'daisy._core' linked to 'dino_lib'.")
endif()
# Pass BUILD_SING_ENABLED definition to Python module
if (BUILD_SING_AVAILABLE)
target_compile_definitions(daisy_core PRIVATE SING_CUDA_ENABLED=1)
if(DEBUG_MSG)
message(STATUS "Python module 'daisy._core' compiled with SING_CUDA_ENABLED=1.")
endif()
else()
target_compile_definitions(daisy_core PRIVATE SING_CUDA_ENABLED=0)
if(DEBUG_MSG)
message(STATUS "Python module 'daisy._core' compiled with SING_CUDA_ENABLED=0.")
endif()
endif()
# Link Python module 'daisy._core' with MPI when Odyssey is available
if (BUILD_ODYSSEY_AVAILABLE)
if(DEBUG_MSG)
message(STATUS "Linking Python module 'daisy._core' with MPI.")
endif()
target_link_libraries(daisy_core PRIVATE ${MPI_CXX_LIBRARIES})
target_include_directories(daisy_core PRIVATE ${MPI_CXX_INCLUDE_DIRS})
if(DEBUG_MSG)
message(DEBUG "MPI Libraries: ${MPI_CXX_LIBRARIES}")
message(DEBUG "MPI Includes: ${MPI_CXX_INCLUDE_DIRS}")
endif()
else()
if(DEBUG_MSG)
message(STATUS "BUILD_ODYSSEY_AVAILABLE is FALSE. Python module 'daisy._core' will NOT be linked with MPI.")
endif()
endif()
# (Python module 'daisy._core' already configured to output into ${PROJECT_SOURCE_DIR}/daisy above)
else()
if(DEBUG_MSG)
message(STATUS "BUILD_PYTHON is OFF. Skipping Python bindings.")
endif()
endif()
# Conditionally add benchmark
if(BUILD_BENCHMARK)
if(DEBUG_MSG)
message(STATUS "----------------------------------------------------")
message(STATUS "BUILD_BENCHMARK is ON. Adding benchmark directory.")
endif()
add_subdirectory(benchmark)
if(DEBUG_MSG)
message(STATUS "Subdirectory 'benchmark' added.")
endif()
else()
if(DEBUG_MSG)
message(STATUS "BUILD_BENCHMARK is OFF. Skipping benchmark directory.")
endif()
endif()
# Note: demos subdirectory already added above conditionally
if(DEBUG_MSG)
message(STATUS "----------------------------------------------------")
message(STATUS "CMake configuration finished for ${CMAKE_PROJECT_NAME}.")
message(STATUS "----------------------------------------------------")
endif()