-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
399 lines (343 loc) · 18.4 KB
/
Copy pathCMakeLists.txt
File metadata and controls
399 lines (343 loc) · 18.4 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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
# ────────────────────────────────────────────────────────
# | FastLanes |
# ────────────────────────────────────────────────────────
# CMakeLists.txt
# ────────────────────────────────────────────────────────
cmake_minimum_required(VERSION 3.22)
# Requirements : -------------------------------------------------------------------------------------------------------
# On non-Windows platforms, default to Clang unless the user explicitly sets a compiler
# (e.g. -DCMAKE_CXX_COMPILER=g++). On Windows, let CMake use the default (MSVC from vcvars).
if (NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
if (NOT DEFINED CMAKE_CXX_COMPILER)
find_program(CLANG_CXX NAMES clang++ REQUIRED)
find_program(CLANG_C NAMES clang REQUIRED)
set(CMAKE_C_COMPILER "${CLANG_C}" CACHE STRING "C Compiler" FORCE)
set(CMAKE_CXX_COMPILER "${CLANG_CXX}" CACHE STRING "C++ Compiler" FORCE)
endif ()
endif ()
# ---------------------------------------------------------------------------------------------------------------------
# Prevent Windows <minwindef.h> from defining min/max macros,
# which collide with std::numeric_limits<…>::max() and
# Flatbuffers’ own max() methods.
#
# Defining NOMINMAX here ensures that any inclusion of
# windows.h or other Win32 headers won’t inject those macros.
# ----------------------------------------------------------------------------------------------------------------------
add_compile_definitions(NOMINMAX)
# Project : ------------------------------------------------------------------------------------------------------------
project(FastLanes)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
#-----------------------------------------------------------------------------------------------------------------------
include(FetchContent)
include(CheckCXXCompilerFlag)
include(CMakePrintHelpers)
# https://stackoverflow.com/questions/56089330/cmake-creates-lots-of-targets-i-didnt-specify
set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1)
include(CTest)
include(GNUInstallDirs)
include(enable_sanitizer)
# Checks : -------------------------------------------------------------------------------------------------------
if (MSVC)
message(STATUS "-- FLS: Building with MSVC ${CMAKE_CXX_COMPILER_VERSION}")
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
message(STATUS "-- FLS: Building with GCC ${CMAKE_CXX_COMPILER_VERSION}")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11)
message(FATAL_ERROR "Only GCC >= 11 is supported (C++20 requirement)!")
endif ()
elseif (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
message(FATAL_ERROR "Only Clang, GCC, and MSVC are supported!")
elseif (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13)
message(FATAL_ERROR "Only Clang >= 13 is supported!")
endif ()
# Disallow configuring in the source tree
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "-- FLS : Please run CMake in a separate build directory!")
endif ()
# Flags : --------------------------------------------------------------------------------------------------------------
message("---------------------------------------------------------------------------------------------------------")
message("-- FLS: detecting flags.")
if (MSVC)
# MSVC auto-targets the host architecture. No manual arch flags needed.
message(STATUS "-- FLS: MSVC build — no arch flags applied.")
# Warning level: /W3 for initial port (tighten to /W4 /WX later).
# /Zc:__cplusplus is needed so __cplusplus reports the correct standard version.
# /bigobj is needed for large translation units (e.g. materializer.cpp).
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /Zc:__cplusplus /bigobj /MP")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3")
else ()
# First, check if running on GitHub Actions
if (DEFINED ENV{GITHUB_ACTIONS} AND "$ENV{GITHUB_ACTIONS}" STREQUAL "true")
message(STATUS "Running on GitHub Actions runner.")
set(IS_GITHUB_ACTIONS ON)
endif ()
# Check if the compiler supports -mavx512dq
check_cxx_compiler_flag("-mavx512dq" COMPILER_SUPPORTS_AVX512DQ)
# Detect AVX-512DQ hardware support via /proc/cpuinfo
set(HAS_HW_AVX512DQ OFF)
if (EXISTS "/proc/cpuinfo")
file(READ "/proc/cpuinfo" CPUINFO_CONTENT)
if (CPUINFO_CONTENT MATCHES "avx512dq")
set(HAS_HW_AVX512DQ ON)
endif ()
endif ()
if (COMPILER_SUPPORTS_AVX512DQ AND HAS_HW_AVX512DQ AND NOT IS_GITHUB_ACTIONS)
message(STATUS "Compiler and hardware both support AVX-512DQ. Adding flag '-mavx512dq'.")
set(FLAGS "-mavx512dq")
elseif (COMPILER_SUPPORTS_AVX512DQ AND HAS_HW_AVX512DQ AND IS_GITHUB_ACTIONS)
message(WARNING "Hardware supports AVX-512DQ, but not adding on GitHub Actions runner.")
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|i[3-6]86")
message(STATUS "Setting '-march=native' for x86 processors without AVX-512DQ.")
set(FLAGS "-march=native")
else ()
message(STATUS "No instruction set flags applied.")
endif ()
# Append the computed FLAGS to the compiler flags if defined
if (FLAGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS}")
endif ()
# Flags for warnings and errors (common to Clang and GCC):
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wnon-virtual-dtor -Wunused -Wpedantic -Woverloaded-virtual")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror")
# Clang-only warning flags (GCC equivalents are covered by clang-tidy):
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow -Wconversion -Winconsistent-missing-override -Wshorten-64-to-32")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow -Wconversion")
endif ()
# GCC-only warning flags:
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsuggest-override")
endif ()
# On Windows (Clang, not MSVC), vectorize-width pragmas may not be honoured
# because the CI runners lack AVX-512. Demote the transform-warning to a
# non-fatal warning so -Werror does not reject advisory hints.
if (WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-pass-failed")
endif ()
endif ()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
message("---------------------------------------------------------------------------------------------------------")
message("-- FLS: Debug mode enabled. Adding -g and -O0.")
if (NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0")
endif ()
endif ()
# Options : ------------------------------------------------------------------------------------------------------------
option(FLS_BUILD_TESTING "Build Test" OFF)
option(FLS_BUILD_BENCHMARKING "Enable Benchmark Build" OFF)
option(FLS_BUILD_EXAMPLES "Build Examples" OFF)
option(FLS_BUILD_CUDA "Build FastLanes CUDA reader" OFF)
option(FLS_BUILD_GTEST "Build GTEST" OFF)
option(FLS_BUILD_PYTHON "Build FastLanes Python bindings" OFF)
option(FLS_BUILD_SHARED_LIBS "Build FastLanes library as shared" OFF)
option(FLS_ENABLE_INSTALL "Generate install targets for FastLanes" ON)
option(FLS_ENABLE_CLANG_TIDY "Enable clang_tidy on all targets" OFF)
option(FLS_ENABLE_IWYU "Enable include-what-you-use tool" OFF)
option(FLS_ENABLE_DOC "Enable Doc build" OFF)
option(FLS_ENABLE_TABLE_LOG "Enable Table Log" OFF)
option(FLS_ENABLE_VERBOSE_OUTPUT "Enable verbose output" OFF)
option(FLS_ENABLE_DATA "Enable Data" OFF)
option(FLS_ENABLE_FSST_TESTING_AND_BENCHMARKING "Build FSST" OFF)
option(FLS_ENABLE_GALP_TESTING_AND_BENCHMARKING "Build GALP" OFF)
# Definitions: ---------------------------------------------------------------------------------------------------------
add_compile_definitions(FLS_CMAKE_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
if (FLS_ENABLE_CLANG_TIDY)
message("---------------------------------------------------------------------------------------------------------")
message("-- FLS: Enabling CLANG-TIDY.")
find_program(CLANG_TIDY_EXE NAMES clang-tidy)
if (NOT CLANG_TIDY_EXE)
message(FATAL_ERROR "-- FLS: clang-tidy not found.")
else ()
if (NOT DEFINED CMAKE_CXX_CLANG_TIDY)
set(CMAKE_CXX_CLANG_TIDY
${CLANG_TIDY_EXE};
--quiet;
--config-file=${CMAKE_SOURCE_DIR}/.clang-tidy)
message("-- FLS: Using project-level .clang-tidy")
else ()
message(FATAL_ERROR "-- FLS: Do not override the clang-tidy configuration. Use the project-level .clang-tidy file instead. Current setting: ${CMAKE_CXX_CLANG_TIDY}")
endif ()
execute_process(
COMMAND ${CLANG_TIDY_EXE} --version
OUTPUT_VARIABLE CLANG_TIDY_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message("-- FLS: clang-tidy version: ${CLANG_TIDY_VERSION}")
endif ()
endif ()
# GTEST : --------------------------------------------------------------------------------------------------------------
if (FLS_BUILD_TESTING OR FLS_BUILD_CUDA OR FLS_ENABLE_FSST_TESTING_AND_BENCHMARKING OR FLS_ENABLE_GALP_TESTING_AND_BENCHMARKING)
message("---------------------------------------------------------------------------------------------------------")
message("-- FLS: Building GTEST:")
include(GoogleTest)
# Gtest: -----------------------------------------------------------------------------------------------------------
FetchContent_Declare(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.15.2
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
enable_testing()
# Silence clang-tidy warnings from googletest (we don't want to lint third-party code)
foreach (_t gtest gtest_main gmock gmock_main)
if (TARGET ${_t})
set_target_properties(${_t} PROPERTIES CXX_CLANG_TIDY "")
endif ()
endforeach ()
# On Windows, GoogleTest uses Microsoft-specific language extensions like `__try`
# that trigger Clang's -Wlanguage-extension-token warning. Since we build with -Werror,
# selectively disable that warning (and suppress all warnings with -w) ONLY for GoogleTest.
if (MSVC)
foreach (_t gtest gtest_main gmock gmock_main)
if (TARGET ${_t})
get_target_property(_aliased ${_t} ALIASED_TARGET)
if (NOT _aliased)
target_compile_options(${_t} PRIVATE /w)
endif ()
endif ()
endforeach ()
elseif (WIN32)
foreach (_t gtest gtest_main gmock gmock_main)
if (TARGET ${_t})
get_target_property(_aliased ${_t} ALIASED_TARGET)
if (NOT _aliased)
target_compile_options(${_t} PRIVATE -Wno-language-extension-token -w)
endif ()
endif ()
endforeach ()
endif ()
# On Linux with Clang or GCC, libstdc++ deprecates get_temporary_buffer (used by stable_sort),
# which triggers -Wdeprecated-declarations; with -Werror that breaks the build.
# Relax ONLY this warning for GoogleTest targets.
if (UNIX AND NOT APPLE)
foreach (_t gtest gtest_main gmock gmock_main)
if (TARGET ${_t})
get_target_property(_aliased ${_t} ALIASED_TARGET)
if (NOT _aliased)
target_compile_options(${_t} PRIVATE
$<$<COMPILE_LANG_AND_ID:CXX,Clang,GNU>:
-Wno-error=deprecated-declarations
-Wno-deprecated-declarations>)
endif ()
endif ()
endforeach ()
endif ()
endif ()
# ALP: -----------------------------------------------------------------------------------------------------------------
if (true)
message("---------------------------------------------------------------------------------------------------------")
message("-- FLS: Building ALP Lib.")
add_compile_definitions(ALP_N_VECTORS_PER_ROWGROUP=64)
set(ALP_ENABLE_ADAPTIVE_MODE OFF CACHE BOOL "Enable adaptive mode" FORCE)
endif ()
if (true)
message("---------------------------------------------------------------------------------------------------------")
message("-- FLS: Building FastLanes Lib.")
# Source: ----------------------------------------------------------------------------------------------------------
if (FLS_BUILD_SHARED_LIBS)
message("-- FLS: Shared is enabled!")
endif ()
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src)
endif ()
# CLANG TIDY : --------------------------------------------------------------------------------------------------------------
if (FLS_ENABLE_CLANG_TIDY)
message("---------------------------------------------------------------------------------------------------------")
message("-- FLS: Disabling CLANG-TIDY.")
set(CMAKE_CXX_CLANG_TIDY "")
endif ()
# CUDA : ---------------------------------------------------------------------------------------------------------------
if (FLS_BUILD_CUDA)
message("---------------------------------------------------------------------------------------------------------")
message("--: Building CU-FastLanes Lib.")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/cuda)
endif ()
# DATA : ---------------------------------------------------------------------------------------------------------------
if (FLS_BUILD_TESTING OR
FLS_BUILD_BENCHMARKING OR
FLS_BUILD_EXAMPLES OR
FLS_ENABLE_DATA OR
FLS_ENABLE_GALP_TESTING_AND_BENCHMARKING OR
FLS_ENABLE_FSST_TESTING_AND_BENCHMARKING)
message("---------------------------------------------------------------------------------------------------------")
message("-- FLS: Enabling Data.")
# If the user has set FASTLANES_DATA_DIR in their environment, use that:
if (DEFINED ENV{FASTLANES_DATA_DIR})
set(data_SOURCE_DIR "$ENV{FASTLANES_DATA_DIR}")
message("-- FLS : Using FASTLANES_DATA_DIR from environment: ${data_SOURCE_DIR}")
else ()
include(FetchContent)
FetchContent_Declare(
data
GIT_REPOSITORY https://github.com/cwida/FastLanes_Data.git
GIT_TAG main
)
FetchContent_MakeAvailable(data)
set(data_SOURCE_DIR "${data_SOURCE_DIR}") # from FetchContent
message("-- FLS : Fetched FastLanes_Data into: ${data_SOURCE_DIR}")
endif ()
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/data/include)
add_compile_definitions(FASTLANES_DATA_DIR="${data_SOURCE_DIR}")
cmake_print_variables(data_SOURCE_DIR)
endif ()
if (FLS_ENABLE_IWYU)
message("---------------------------------------------------------------------------------------------------------")
message("-- FLS: Enabling IWYU")
find_program(iwyu_path NAMES include-what-you-use iwyu REQUIRED)
if (NOT iwyu_path)
message(WARNING "-- FLS_ERROR: Could not find the program include-what-you-use")
endif ()
endif ()
# Verbose : ------------------------------------------------------------------------------------------------------------
if (FLS_ENABLE_VERBOSE_OUTPUT)
include(verbose_options)
print_verbose_options()
endif ()
# Benchmark : ----------------------------------------------------------------------------------------------------------
if (FLS_BUILD_BENCHMARKING)
message("---------------------------------------------------------------------------------------------------------")
message("- Benchmark:")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/benchmark)
endif ()
# Test: ----------------------------------------------------------------------------------------------------------------
if (FLS_BUILD_TESTING)
message("---------------------------------------------------------------------------------------------------------")
message("-- FLS: Build Testing.")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/test/include)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test)
endif ()
# FSST: ----------------------------------------------------------------------------------------------------------------
if (FLS_ENABLE_FSST_TESTING_AND_BENCHMARKING)
message("---------------------------------------------------------------------------------------------------------")
message("-- FLS: Adding FSST Testing and Benchmarking.")
add_subdirectory(fsst)
endif ()
# Example : ------------------------------------------------------------------------------------------------------------
if (FLS_BUILD_EXAMPLES)
message("---------------------------------------------------------------------------------------------------------")
message("- Examples:")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/examples)
endif ()
# Playground : ---------------------------------------------------------------------------------------------------------
if (EXISTS "${CMAKE_SOURCE_DIR}/playground/CMakeLists.txt")
message("---------------------------------------------------------------------------------------------------------")
message("- FLS: Adding Playground ")
add_subdirectory(playground)
endif ()
# Python : -------------------------------------------------------------------------------------------------------------
if (FLS_BUILD_PYTHON)
message("----------------------------------------------------------------------------------------------------------")
message("- FLS: Building FastLanes Python Extension")
add_subdirectory(python) # your module’s CMakeLists.txt
endif ()
# FSST: ----------------------------------------------------------------------------------------------------------------
if (FLS_ENABLE_GALP_TESTING_AND_BENCHMARKING)
message("---------------------------------------------------------------------------------------------------------")
message("-- FLS: Adding GALP Testing and Benchmarking.")
add_subdirectory(galp)
endif ()