-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
656 lines (566 loc) · 23.1 KB
/
CMakeLists.txt
File metadata and controls
656 lines (566 loc) · 23.1 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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
cmake_minimum_required(VERSION 3.22)
project(tpch-cpp
VERSION 0.1.0
DESCRIPTION "High-performance TPC-H data generator with multiple format support"
LANGUAGES CXX C
)
# Set C++ standard (C++20 required for std::span in Phase 13.4 zero-copy)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Set C standard for dbgen (C code)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
# Add CMake modules directory
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# Build options
option(TPCH_BUILD_EXAMPLES "Build example applications" ON)
option(TPCH_BUILD_TESTS "Build unit tests" OFF)
option(TPCH_ENABLE_ASAN "Enable AddressSanitizer" OFF)
option(TPCH_ENABLE_ASYNC_IO "Enable async I/O with io_uring" OFF)
option(TPCH_ENABLE_ORC "Enable ORC file format support" OFF)
option(TPCH_ENABLE_PAIMON "Enable Apache Paimon table format support" OFF)
option(TPCH_ENABLE_ICEBERG "Enable Apache Iceberg table format support" OFF)
option(TPCH_ENABLE_LANCE "Enable Lance columnar format support (requires Rust)" OFF)
option(TPCH_USE_PREBUILT_LANCE_FFI "Use pre-compiled Lance FFI library when available" ON)
option(TPCH_ENABLE_PERF_COUNTERS "Enable performance counters instrumentation" OFF)
option(TPCH_ENABLE_MOLD "Enable mold linker if available (incompatible with GTest in this project)" ON)
option(TPCDS_ENABLE "Enable TPC-DS data generation (tpcds_benchmark executable)" OFF)
option(TPCH_ENABLE_NATIVE_OPTIMIZATIONS "Enable host-specific CPU optimizations such as -march=native" ON)
# Compiler configuration
include(cmake/CompilerWarnings.cmake)
# Apply compiler flags based on configuration
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
# Enable aggressive optimizations with SIMD support
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
add_compile_options(-O3)
if(TPCH_ENABLE_NATIVE_OPTIMIZATIONS)
add_compile_options(-march=native)
endif()
# Enable auto-vectorization and report optimizations
add_compile_options(
-ftree-vectorize # Enable loop vectorization
-fopt-info-vec-optimized # Report successful vectorizations
)
if(TPCH_ENABLE_NATIVE_OPTIMIZATIONS)
# Check for AVX2 support (preferred)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-mavx2" COMPILER_SUPPORTS_AVX2)
if(COMPILER_SUPPORTS_AVX2)
message(STATUS "Enabling AVX2 SIMD optimizations")
add_compile_options(-mavx2 -mfma)
else()
# Fallback to SSE4.2 (required for SIMD string utils)
check_cxx_compiler_flag("-msse4.2" COMPILER_SUPPORTS_SSE42)
if(COMPILER_SUPPORTS_SSE42)
message(STATUS "Enabling SSE4.2 SIMD optimizations")
add_compile_options(-msse4.2)
else()
message(WARNING "No SIMD support detected - performance will be degraded")
endif()
endif()
else()
message(STATUS "Host-specific CPU optimizations disabled (TPCH_ENABLE_NATIVE_OPTIMIZATIONS=OFF)")
endif()
endif()
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(-O0 -g)
endif()
if(TPCH_ENABLE_ASAN)
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
endif()
# Use mold linker if available (faster linking for both GCC and Clang)
if(TPCH_ENABLE_MOLD AND TPCH_BUILD_TESTS)
message(WARNING "mold linker is incompatible with GTest in this project. "
"Disabling mold for test builds.")
set(TPCH_ENABLE_MOLD OFF)
endif()
if(TPCH_ENABLE_MOLD)
find_program(MOLD_LINKER mold)
if(MOLD_LINKER)
message(STATUS "Found mold linker: ${MOLD_LINKER}")
add_link_options(-fuse-ld=mold)
else()
message(STATUS "mold linker not found (optional) - using default linker")
endif()
else()
message(STATUS "mold linker disabled (TPCH_ENABLE_MOLD=OFF)")
endif()
# Find required packages from system
# Note: We need to find zstd before Arrow to avoid CMake configuration issues
find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_check_modules(ZSTD libzstd)
endif()
# Find dependencies before Arrow/Parquet to ensure targets are available
# and suppress warnings from Arrow's internal dependency checks
find_package(zstd REQUIRED)
set(zstdAlt_FOUND TRUE) # Prevent Arrow from trying to find zstd again
find_package(lz4 REQUIRED)
set(lz4Alt_FOUND TRUE)
find_package(re2 REQUIRED)
set(re2Alt_FOUND TRUE)
find_package(Thrift REQUIRED)
set(ThriftAlt_FOUND TRUE)
# Find UUID library (optional, used by Paimon/Iceberg writers)
# On most Linux systems this is available; macOS/Windows may need separate install
find_library(UUID_LIBRARY NAMES uuid libuuid)
if(UUID_LIBRARY)
set(UUID_FOUND TRUE)
message(STATUS "Found uuid library: ${UUID_LIBRARY}")
else()
set(UUID_FOUND FALSE)
message(WARNING "uuid library not found - Paimon/Iceberg writers may have limited functionality")
endif()
# Protobuf handling:
# - Arrow is built WITHOUT protobuf (-DARROW_WITH_PROTOBUF=OFF)
# - ORC is built with protobuf STATICALLY EMBEDDED (-DORC_PREFER_STATIC_PROTOBUF=ON)
# - We do NOT link protobuf separately to avoid conflicts with ORC's embedded protobuf
# - ORC's CMake target (ORC::orc) handles all protobuf dependencies internally
find_package(Snappy QUIET)
find_package(ZLIB QUIET)
find_package(Arrow REQUIRED)
find_package(Parquet REQUIRED)
# Use local xsimd (modern version from third_party)
set(XSIMD_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/xsimd/include")
if(EXISTS "${XSIMD_INCLUDE_DIR}/xsimd/xsimd.hpp")
message(STATUS "Using local xsimd from: ${XSIMD_INCLUDE_DIR}")
set(xsimd_FOUND TRUE)
else()
message(STATUS "xsimd not found in third_party - will use manual SIMD intrinsics")
set(xsimd_FOUND FALSE)
endif()
if(TPCH_ENABLE_ORC)
find_package(ORC QUIET)
endif()
# Paimon support: Note that our implementation uses Parquet as backing format
# and does not require paimon-cpp C++ library, so we don't need to find it
if(TPCH_ENABLE_PAIMON)
set(Paimon_FOUND TRUE)
endif()
# Iceberg support: Similar to Paimon, our implementation uses Parquet as backing format
# and does not require iceberg-cpp C++ library, so we don't need to find it
if(TPCH_ENABLE_ICEBERG)
set(Iceberg_FOUND TRUE)
endif()
# Lance support: Requires Rust toolchain to build FFI library
if(TPCH_ENABLE_LANCE)
# Check for Rust toolchain - prefer /snap/bin for newer Rust versions
find_program(Cargo_EXECUTABLE cargo PATHS /snap/bin NO_DEFAULT_PATH)
if(NOT Cargo_EXECUTABLE)
# Fallback to system cargo
find_program(Cargo_EXECUTABLE cargo)
endif()
if(Cargo_EXECUTABLE)
message(STATUS "Found Rust toolchain: ${Cargo_EXECUTABLE}")
set(Lance_FOUND TRUE)
else()
message(FATAL_ERROR "Lance requested (TPCH_ENABLE_LANCE=ON) but Rust toolchain not found. "
"Install with: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh")
endif()
endif()
# Print found status
message(STATUS "Arrow found: ${Arrow_LIBRARY}")
message(STATUS "Parquet found: ${Parquet_LIBRARY}")
if(TPCH_ENABLE_ORC)
if(ORC_FOUND)
message(STATUS "ORC found: ${ORC_LIBRARY}")
else()
message(FATAL_ERROR "ORC requested (TPCH_ENABLE_ORC=ON) but not found - install with: sudo apt-get install liborc-dev")
endif()
else()
message(STATUS "ORC support disabled (TPCH_ENABLE_ORC=OFF)")
endif()
if(TPCH_ENABLE_PAIMON)
message(STATUS "Paimon support enabled (uses Parquet backing format)")
else()
message(STATUS "Paimon support disabled (TPCH_ENABLE_PAIMON=OFF)")
endif()
if(TPCH_ENABLE_ICEBERG)
message(STATUS "Iceberg support enabled (uses Parquet backing format)")
else()
message(STATUS "Iceberg support disabled (TPCH_ENABLE_ICEBERG=OFF)")
endif()
if(TPCH_ENABLE_LANCE)
if(Lance_FOUND)
message(STATUS "Lance support enabled (Rust FFI bridge)")
else()
message(FATAL_ERROR "Lance support requested but Rust toolchain not found")
endif()
else()
message(STATUS "Lance support disabled (TPCH_ENABLE_LANCE=OFF)")
endif()
if(TPCH_ENABLE_ASYNC_IO)
find_package(Uring QUIET)
if(Uring_FOUND)
message(STATUS "Found liburing: ${Uring_LIBRARY}")
else()
message(WARNING "liburing not found - install with: sudo apt-get install liburing-dev")
endif()
endif()
# Include directories
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
# Generate dists_generated.c from dists.dss at configure time.
# This embeds all distribution data as static C arrays, eliminating runtime
# file I/O and heap allocation for distribution loading.
find_package(Python3 REQUIRED COMPONENTS Interpreter)
set(DISTS_DSS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/third_party/tpch/dbgen/dists.dss")
set(DISTS_GENERATED_C "${CMAKE_BINARY_DIR}/generated/dists_generated.c")
execute_process(
COMMAND ${Python3_EXECUTABLE}
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/gen_dists.py"
"${DISTS_DSS_PATH}"
"${DISTS_GENERATED_C}"
RESULT_VARIABLE _gen_dists_result
OUTPUT_VARIABLE _gen_dists_output
ERROR_VARIABLE _gen_dists_error
)
if(_gen_dists_result)
message(FATAL_ERROR "gen_dists.py failed: ${_gen_dists_error}")
endif()
message(STATUS "${_gen_dists_output}")
# Re-run cmake if dists.dss or the generator script changes
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
"${DISTS_DSS_PATH}"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/gen_dists.py"
)
# Build dbgen objects
add_subdirectory(third_party/dbgen EXCLUDE_FROM_ALL)
include_directories(${DBGEN_INCLUDE_DIRS})
# TPC-DS dsdgen objects (built only when TPCDS_ENABLE=ON)
if(TPCDS_ENABLE)
add_subdirectory(third_party/dsdgen EXCLUDE_FROM_ALL)
endif()
# Copy TPC-H distribution file to build directory
# Required by dbgen for loading nations, regions, and other lookup tables
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/third_party/tpch/dbgen/dists.dss"
"${CMAKE_BINARY_DIR}/dists.dss"
COPYONLY
)
message(STATUS "Copied dists.dss to build directory")
# Build or find Rust FFI library for Lance support (if enabled)
if(TPCH_ENABLE_LANCE AND Lance_FOUND)
set(LANCE_FFI_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/lance-ffi")
set(LANCE_FFI_LIB_FINAL "${CMAKE_BINARY_DIR}/liblance_ffi.a")
set(LANCE_FFI_PREBUILT "")
if(TPCH_USE_PREBUILT_LANCE_FFI)
# In CI containers we know the exact archive name and location pattern.
# Prefer an explicit path probe over find_library() so a semicolon-based
# CMAKE_PREFIX_PATH cannot cause us to miss the prebuilt archive and
# fall back to a full Rust rebuild.
foreach(_prefix IN LISTS CMAKE_PREFIX_PATH)
if(EXISTS "${_prefix}/lib/liblance_ffi.a")
set(LANCE_FFI_PREBUILT "${_prefix}/lib/liblance_ffi.a")
break()
endif()
endforeach()
endif()
if(LANCE_FFI_PREBUILT)
message(STATUS "Using pre-compiled Lance FFI library: ${LANCE_FFI_PREBUILT}")
# Copy pre-compiled library to build directory for consistent path
add_custom_command(
OUTPUT "${LANCE_FFI_LIB_FINAL}"
COMMAND ${CMAKE_COMMAND} -E copy "${LANCE_FFI_PREBUILT}" "${LANCE_FFI_LIB_FINAL}"
DEPENDS "${LANCE_FFI_PREBUILT}"
COMMENT "Using pre-compiled Lance FFI library from ${LANCE_FFI_PREBUILT}"
VERBATIM
)
add_custom_target(lance_ffi ALL DEPENDS "${LANCE_FFI_LIB_FINAL}")
else()
if(TPCH_USE_PREBUILT_LANCE_FFI)
message(STATUS "Pre-compiled Lance FFI not found, building from source with Rust cargo")
else()
message(STATUS "Building Lance FFI library from source with Rust cargo")
endif()
set(LANCE_FFI_BUILD_DIR "${CMAKE_BINARY_DIR}/rust")
# Determine output library path based on platform and Rust target
if(APPLE)
set(RUST_TARGET "aarch64-apple-darwin")
set(LANCE_FFI_LIB "${LANCE_FFI_BUILD_DIR}/${RUST_TARGET}/release/liblance_ffi.a")
else()
# Use default native build for Linux (x86_64-unknown-linux-gnu)
set(RUST_TARGET "")
set(LANCE_FFI_LIB "${LANCE_FFI_BUILD_DIR}/release/liblance_ffi.a")
endif()
# Check for snap Rust - both cargo and rustc should come from snap together
find_program(SNAP_RUSTC rustc PATHS /snap/bin NO_DEFAULT_PATH)
if(SNAP_RUSTC)
message(STATUS "Detected Rust from snap: ${SNAP_RUSTC}")
set(RUSTC_ENV_VAR "${SNAP_RUSTC}")
else()
message(STATUS "Using system Rust compiler")
find_program(RUSTC_ENV_VAR rustc)
endif()
# Build Rust FFI library using cargo
# Note: Cargo target directory is set to build/rust to keep artifacts out of source tree
# RUSTC env var ensures correct rustc version is used (snap vs system)
set(CARGO_BUILD_CMD "env" "RUSTC=${RUSTC_ENV_VAR}"
"${Cargo_EXECUTABLE}" build --release
--manifest-path "${LANCE_FFI_DIR}/Cargo.toml"
--target-dir "${LANCE_FFI_BUILD_DIR}")
if(RUST_TARGET)
list(APPEND CARGO_BUILD_CMD --target "${RUST_TARGET}")
endif()
# io_uring is compiled in by default (see Cargo.toml default features).
# Runtime activation happens via --io-uring CLI flag, not a build switch.
add_custom_command(
OUTPUT "${LANCE_FFI_LIB_FINAL}"
COMMAND ${CMAKE_COMMAND} -E echo "Building Lance FFI library with Rust cargo ..."
COMMAND ${CMAKE_COMMAND} -E make_directory "${LANCE_FFI_BUILD_DIR}"
COMMAND ${CARGO_BUILD_CMD}
COMMAND ${CMAKE_COMMAND} -E copy "${LANCE_FFI_LIB}" "${LANCE_FFI_LIB_FINAL}"
WORKING_DIRECTORY "${LANCE_FFI_DIR}"
DEPENDS "${LANCE_FFI_DIR}/Cargo.toml"
"${LANCE_FFI_DIR}/Cargo.lock"
"${LANCE_FFI_DIR}/src/lib.rs"
"${LANCE_FFI_DIR}/src/io_uring_store.rs"
COMMENT "Compiling Lance FFI library with Rust (target: ${RUST_TARGET})"
VERBATIM
)
add_custom_target(lance_ffi ALL DEPENDS "${LANCE_FFI_LIB_FINAL}")
message(STATUS "Rust FFI build configured for Lance support")
message(STATUS " Rust target directory: ${LANCE_FFI_BUILD_DIR}")
# io_uring symbols are only present when we build from source (Cargo.toml
# has io-uring as a default feature). Pre-compiled CI libraries may not
# have them, so gate the C++ call site with this flag.
set(LANCE_FFI_HAS_IO_URING TRUE)
endif()
# Import the Rust library as an external target
add_library(lance_ffi_lib STATIC IMPORTED GLOBAL)
set_target_properties(lance_ffi_lib PROPERTIES
IMPORTED_LOCATION "${LANCE_FFI_LIB_FINAL}"
)
add_dependencies(lance_ffi_lib lance_ffi)
message(STATUS " Output library: ${LANCE_FFI_LIB_FINAL}")
endif()
# Source files for main library
set(TPCH_CORE_SOURCES
src/writers/csv_writer.cpp
src/writers/parquet_writer.cpp
src/multi_table_writer.cpp
src/dbgen/dbgen_wrapper.cpp
src/dbgen/dbgen_converter.cpp
src/dbgen/zero_copy_converter.cpp # Phase 13.4: Zero-copy optimizations
src/util/builder_pool.cpp
${DBGEN_OBJECTS}
)
# DS-10.2: io_uring pool + output stream (handle #ifdef internally, always compile)
list(APPEND TPCH_CORE_SOURCES
src/async/io_uring_pool.cpp
src/async/io_uring_output_stream.cpp
)
# Add async IO sources only if enabled
if(TPCH_ENABLE_ASYNC_IO)
list(APPEND TPCH_CORE_SOURCES
src/async/io_uring_context.cpp
src/async/shared_async_io.cpp
)
else()
# Use stub implementation when async IO is disabled
list(APPEND TPCH_CORE_SOURCES
src/async/async_io_stub.cpp
)
endif()
# Add ORC writer if enabled and available
if(TPCH_ENABLE_ORC AND ORC_FOUND)
list(APPEND TPCH_CORE_SOURCES
src/writers/orc_writer.cpp
)
endif()
# Add Paimon writer if enabled and available
if(TPCH_ENABLE_PAIMON AND Paimon_FOUND)
list(APPEND TPCH_CORE_SOURCES
src/writers/paimon_writer.cpp
)
endif()
# Add Iceberg writer if enabled and available
if(TPCH_ENABLE_ICEBERG AND Iceberg_FOUND)
list(APPEND TPCH_CORE_SOURCES
src/writers/iceberg_writer.cpp
)
endif()
# Add Lance writer if enabled and available
if(TPCH_ENABLE_LANCE AND Lance_FOUND)
list(APPEND TPCH_CORE_SOURCES
src/writers/lance_writer.cpp
)
endif()
# Create core library
add_library(tpch_core STATIC ${TPCH_CORE_SOURCES})
target_include_directories(tpch_core PUBLIC include)
# Link required libraries (Arrow and Parquet are mandatory)
target_link_libraries(tpch_core PUBLIC
Arrow::arrow
Arrow::parquet
dbgen_objs
)
# Link uuid library if found
if(UUID_FOUND)
target_link_libraries(tpch_core PUBLIC ${UUID_LIBRARY})
endif()
# Link xsimd if available (header-only library)
if(xsimd_FOUND)
target_include_directories(tpch_core PUBLIC ${XSIMD_INCLUDE_DIR})
target_compile_definitions(tpch_core PUBLIC TPCH_USE_XSIMD)
message(STATUS "xsimd SIMD optimizations enabled")
endif()
# Link ORC if enabled and available
# Note: ORC was built with static protobuf (-DORC_PREFER_STATIC_PROTOBUF=ON)
# ORC's static library (.a) requires explicit protobuf linking even though
# protobuf is embedded, because the symbols are referenced by ORC object files
if(TPCH_ENABLE_ORC AND ORC_FOUND)
target_link_libraries(tpch_core PRIVATE ORC::orc)
# Link protobuf - required for ORC static library symbols
# This does NOT cause conflicts because we don't use protobuf ourselves
# and ORC's protobuf definitions are self-contained
find_package(Protobuf QUIET)
if(Protobuf_FOUND)
if(TARGET protobuf::libprotobuf)
target_link_libraries(tpch_core PRIVATE protobuf::libprotobuf)
elseif(Protobuf_LIBRARIES)
target_link_libraries(tpch_core PRIVATE ${Protobuf_LIBRARIES})
endif()
endif()
endif()
# Paimon linking not needed - uses Parquet backing format directly
# Link Lance FFI library if enabled
if(TPCH_ENABLE_LANCE AND Lance_FOUND)
target_link_libraries(tpch_core PRIVATE lance_ffi_lib)
# Lance FFI requires Rust runtime libraries
# These are typically available on Unix-like systems
find_library(DL_LIB NAMES dl)
if(DL_LIB)
target_link_libraries(tpch_core PRIVATE ${DL_LIB})
endif()
find_library(PTHREAD_LIB NAMES pthread)
if(PTHREAD_LIB)
target_link_libraries(tpch_core PRIVATE ${PTHREAD_LIB})
endif()
find_library(M_LIB NAMES m)
if(M_LIB)
target_link_libraries(tpch_core PRIVATE ${M_LIB})
endif()
endif()
# Arrow has dependencies on system libraries that need to be linked AFTER ORC
# Link compression libraries for Arrow's support
find_library(ZLIB_LIB NAMES z)
if(ZLIB_LIB)
target_link_libraries(tpch_core PRIVATE ${ZLIB_LIB})
endif()
find_library(ZSTD_LIB NAMES zstd)
if(ZSTD_LIB)
target_link_libraries(tpch_core PRIVATE ${ZSTD_LIB})
endif()
find_library(LZ4_LIB NAMES lz4)
if(LZ4_LIB)
target_link_libraries(tpch_core PRIVATE ${LZ4_LIB})
endif()
# Snappy must come at the very end due to linker symbol ordering requirements
find_library(SNAPPY_LIB NAMES snappy)
if(SNAPPY_LIB)
target_link_libraries(tpch_core PRIVATE ${SNAPPY_LIB})
endif()
# Define compilation flags for enabled features
target_compile_definitions(tpch_core PUBLIC TPCH_DEPS_AVAILABLE)
if(TPCH_ENABLE_ORC)
target_compile_definitions(tpch_core PUBLIC TPCH_ENABLE_ORC)
endif()
if(TPCH_ENABLE_PAIMON)
target_compile_definitions(tpch_core PUBLIC TPCH_ENABLE_PAIMON)
endif()
if(TPCH_ENABLE_ICEBERG)
target_compile_definitions(tpch_core PUBLIC TPCH_ENABLE_ICEBERG)
endif()
if(TPCH_ENABLE_LANCE)
target_compile_definitions(tpch_core PUBLIC TPCH_ENABLE_LANCE)
if(LANCE_FFI_HAS_IO_URING)
target_compile_definitions(tpch_core PUBLIC TPCH_LANCE_IO_URING)
endif()
endif()
if(TPCH_ENABLE_ASYNC_IO AND Uring_FOUND)
target_link_libraries(tpch_core PUBLIC Uring::uring)
target_compile_definitions(tpch_core PUBLIC TPCH_ENABLE_ASYNC_IO)
endif()
if(TPCH_ENABLE_PERF_COUNTERS)
target_compile_definitions(tpch_core PUBLIC TPCH_ENABLE_PERF_COUNTERS)
message(STATUS "Performance counters enabled")
endif()
# Main benchmark executable
add_executable(tpch_benchmark src/main.cpp)
target_link_libraries(tpch_benchmark PRIVATE tpch_core)
# Ensure main executable sees the same compilation flags
if(TPCH_ENABLE_ORC)
target_compile_definitions(tpch_benchmark PRIVATE TPCH_ENABLE_ORC)
endif()
if(TPCH_ENABLE_PAIMON)
target_compile_definitions(tpch_benchmark PRIVATE TPCH_ENABLE_PAIMON)
endif()
if(TPCH_ENABLE_ICEBERG)
target_compile_definitions(tpch_benchmark PRIVATE TPCH_ENABLE_ICEBERG)
endif()
if(TPCH_ENABLE_LANCE)
target_compile_definitions(tpch_benchmark PRIVATE TPCH_ENABLE_LANCE)
endif()
if(TPCH_ENABLE_ASYNC_IO AND Uring_FOUND)
target_compile_definitions(tpch_benchmark PRIVATE TPCH_ENABLE_ASYNC_IO)
endif()
if(TPCH_ENABLE_PERF_COUNTERS)
target_compile_definitions(tpch_benchmark PRIVATE TPCH_ENABLE_PERF_COUNTERS)
endif()
# TPC-DS benchmark executable
if(TPCDS_ENABLE)
add_executable(tpcds_benchmark
src/tpcds_main.cpp
src/dsdgen/dsdgen_wrapper.cpp
src/dsdgen/dsdgen_converter.cpp
${DSDGEN_OBJECTS}
)
target_link_libraries(tpcds_benchmark PRIVATE tpch_core)
target_include_directories(tpcds_benchmark PRIVATE ${DSDGEN_INCLUDE_DIRS})
# dsdgen upstream has several globals defined in multiple source files
# (pCurrentFile in driver.c and grammar_support.c, etc.). Allow duplicates
# at link time — the old GCC linker accepted these by default via -fcommon.
target_link_options(tpcds_benchmark PRIVATE -Wl,--allow-multiple-definition)
# dsdgen headers require LINUX=1 and TPCDS=1 to define ds_key_t and enable
# 64-bit support (config.h/#ifdef LINUX). Also needed by dsdgen_wrapper.cpp
# and dsdgen_converter.cpp which include dsdgen C headers.
target_compile_definitions(tpcds_benchmark PRIVATE TPCDS_ENABLE LINUX=1 TPCDS=1 EMBEDDED_DSDGEN=1)
if(TPCH_ENABLE_ORC)
target_compile_definitions(tpcds_benchmark PRIVATE TPCH_ENABLE_ORC)
endif()
if(TPCH_ENABLE_PAIMON)
target_compile_definitions(tpcds_benchmark PRIVATE TPCH_ENABLE_PAIMON)
endif()
if(TPCH_ENABLE_ICEBERG)
target_compile_definitions(tpcds_benchmark PRIVATE TPCH_ENABLE_ICEBERG)
endif()
if(TPCH_ENABLE_LANCE)
target_compile_definitions(tpcds_benchmark PRIVATE TPCH_ENABLE_LANCE)
endif()
if(TPCH_ENABLE_ASYNC_IO AND Uring_FOUND)
target_compile_definitions(tpcds_benchmark PRIVATE TPCH_ENABLE_ASYNC_IO)
endif()
if(TPCH_ENABLE_PERF_COUNTERS)
target_compile_definitions(tpcds_benchmark PRIVATE TPCH_ENABLE_PERF_COUNTERS)
endif()
message(STATUS "TPC-DS support enabled: tpcds_benchmark target added")
install(TARGETS tpcds_benchmark RUNTIME DESTINATION bin)
endif()
# Examples
if(TPCH_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
# Tests
if(TPCH_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
# Install targets
install(TARGETS tpch_benchmark
RUNTIME DESTINATION bin
)
install(DIRECTORY include/tpch/
DESTINATION include/tpch
)