Implementation:Duckdb Duckdb Add Executable Targets
Overview
Concrete tool for building DuckDB CLI, test runner, and benchmark runner executables provided by the CMake build system.
This implementation defines the executable targets that link the compiled duckdb_static library and third-party dependencies into runnable binaries. Each target is conditionally included based on CMake build options.
Code Reference
Source Locations
| Component | Location |
|---|---|
| CLI shell executable | tools/shell/CMakeLists.txt:L1-50
|
| Test runner executable | test/CMakeLists.txt:L1-58
|
| Benchmark runner executable | benchmark/CMakeLists.txt:L1-32
|
| Subdirectory inclusion logic | CMakeLists.txt:L796-847
|
Subdirectory Inclusion (Root CMakeLists.txt)
# CLI shell
if(BUILD_SHELL)
add_subdirectory(tools/shell)
endif()
# Test runner and benchmarks
if(BUILD_UNITTESTS)
add_subdirectory(test)
endif()
if(BUILD_BENCHMARKS)
add_subdirectory(benchmark)
endif()
CLI Shell Target (tools/shell/CMakeLists.txt)
add_executable(duckdb_cli
shell.c
linenoise.cpp
# additional shell source files
)
target_link_libraries(duckdb_cli
duckdb_static
${READLINE_LIBRARIES} # optional readline support
)
set_target_properties(duckdb_cli PROPERTIES OUTPUT_NAME duckdb)
Test Runner Target (test/CMakeLists.txt)
add_executable(unittest
unittest.cpp
# test source files from test/ subdirectories
)
target_link_libraries(unittest
duckdb_static
test_helpers
)
Benchmark Runner Target (benchmark/CMakeLists.txt)
add_executable(benchmark_runner
benchmark_runner.cpp
# benchmark definition files
)
target_link_libraries(benchmark_runner
duckdb_static
)
Parameters
| CMake Option | Default | Description |
|---|---|---|
BUILD_SHELL |
TRUE |
Build the interactive CLI shell executable |
BUILD_UNITTESTS |
FALSE |
Build the test runner executable (also gates benchmark inclusion) |
BUILD_BENCHMARKS |
FALSE |
Build the benchmark runner executable |
I/O Contract
Inputs
| Input | Description |
|---|---|
duckdb_static |
Compiled static library containing all DuckDB core modules and third-party dependencies |
| Shell source files | tools/shell/shell.c, tools/shell/linenoise.cpp, and related files
|
| Test source files | test/unittest.cpp and test case files under test/
|
| Benchmark source files | benchmark/benchmark_runner.cpp and benchmark definitions under benchmark/
|
readline (optional) |
System library for enhanced CLI line editing; detected at configure time |
Outputs
| Output Path | Description |
|---|---|
build/release/duckdb |
CLI shell executable (interactive SQL REPL) |
build/release/test/unittest |
Test runner executable for automated verification |
build/release/benchmark/benchmark_runner |
Benchmark runner executable for performance testing |
Usage Examples
Build All Executables
mkdir -p build/release
cd build/release
cmake -DCMAKE_BUILD_TYPE=Release \
-DBUILD_UNITTESTS=TRUE \
-DBUILD_BENCHMARKS=TRUE \
../..
make -j$(nproc)
This produces all three executables: duckdb, unittest, and benchmark_runner.
Build CLI Shell Only
cmake -DCMAKE_BUILD_TYPE=Release \
-DBUILD_UNITTESTS=FALSE \
../..
make -j$(nproc)
Produces only the duckdb CLI executable, skipping test and benchmark targets.
Build With Readline Support
# Ensure readline development headers are installed
sudo apt-get install libreadline-dev
cmake -DCMAKE_BUILD_TYPE=Release ../..
make -j$(nproc)
CMake auto-detects readline at configure time. When found, the CLI shell is built with enhanced line editing, history, and tab completion.
Using Makefile Convenience Targets
# Build release CLI
make release
# Build debug with tests
make debug
# Build only the test runner
make unit