Implementation:Duckdb Duckdb Add Third Party
Metadata
| Field | Value |
|---|---|
| Type | Implementation (API Doc) |
| Source Files | CMakeLists.txt:L778-780 (function definition), CMakeLists.txt:L802-813 (invocations)
|
| Domains | Build_System |
Overview
Concrete tool for compiling vendored third-party libraries into static libraries provided by DuckDB's CMake build system. The add_third_party() CMake function is a thin wrapper around add_subdirectory() that standardises the source and binary directory paths for every vendored dependency. Each invocation brings a third-party library's CMakeLists.txt into the build graph, compiling it into a static archive that is subsequently linked into DuckDB's core targets.
Code Reference
Function Definition
function(add_third_party NAME)
add_subdirectory(
${_DUCKDB_PROJECT_SRC_DIR}/third_party/${NAME}
${_DUCKDB_PROJECT_BIN_DIR}/third_party/${NAME}
)
endfunction()
Parameters:
| Parameter | Type | Description |
|---|---|---|
NAME |
String | Name of the third-party library directory under third_party/
|
The function resolves two paths:
- Source directory:
${_DUCKDB_PROJECT_SRC_DIR}/third_party/${NAME}-- the vendored source tree containing the library's ownCMakeLists.txt. - Binary directory:
${_DUCKDB_PROJECT_BIN_DIR}/third_party/${NAME}-- the out-of-source build output directory for that library.
Invocations
The following vendored libraries are compiled via add_third_party():
add_third_party(fastpforlib)
add_third_party(fmt)
add_third_party(fsst)
add_third_party(hyperloglog)
add_third_party(libpg_query)
add_third_party(mbedtls)
add_third_party(miniz)
add_third_party(re2)
add_third_party(skiplist)
add_third_party(utf8proc)
add_third_party(yyjson)
add_third_party(zstd)
I/O Contract
Inputs
| Input | Location | Description |
|---|---|---|
| Third-party source trees | third_party/<NAME>/ |
Vendored source code for each dependency |
| Per-library CMakeLists.txt | third_party/<NAME>/CMakeLists.txt |
Build declaration for each vendored library (defines the static library target, source files, compile flags) |
_DUCKDB_PROJECT_SRC_DIR |
CMake variable | Root of the DuckDB source tree |
_DUCKDB_PROJECT_BIN_DIR |
CMake variable | Root of the DuckDB build output tree |
Outputs
Each invocation produces a static library target. The mapping from vendored directory to output library name is:
| Vendored Directory | Output Static Library Target |
|---|---|
fastpforlib |
duckdb_fastpforlib
|
fmt |
duckdb_fmt
|
fsst |
duckdb_fsst
|
hyperloglog |
duckdb_hyperloglog
|
libpg_query |
duckdb_pg_query
|
mbedtls |
duckdb_mbedtls
|
miniz |
duckdb_miniz
|
re2 |
duckdb_re2
|
skiplist |
duckdb_skiplistlib
|
utf8proc |
duckdb_utf8proc
|
yyjson |
duckdb_yyjson
|
zstd |
duckdb_zstd
|
All output static libraries are placed in the build output tree under build/<variant>/third_party/<NAME>/.
Usage Examples
Adding a New Vendored Dependency
To add a new vendored library called newlib:
- Place the library source under
third_party/newlib/. - Create
third_party/newlib/CMakeLists.txtdefining a static library target:
add_library(duckdb_newlib STATIC
src/newlib.cpp
)
target_include_directories(duckdb_newlib PUBLIC include)
- Add the invocation in the root
CMakeLists.txtalongside the other third-party libraries:
add_third_party(newlib)
- Link the new static library to the DuckDB target:
target_link_libraries(duckdb PUBLIC duckdb_newlib)
Inspecting the Build Graph
After configuring the project, the third-party targets are visible in the build graph:
# Configure
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -B build/release
# List all targets (Ninja)
ninja -C build/release -t targets | grep duckdb_
Expected output (excerpt):
duckdb_fastpforlib: STATIC_LIBRARY
duckdb_fmt: STATIC_LIBRARY
duckdb_fsst: STATIC_LIBRARY
duckdb_hyperloglog: STATIC_LIBRARY
duckdb_pg_query: STATIC_LIBRARY
duckdb_mbedtls: STATIC_LIBRARY
duckdb_miniz: STATIC_LIBRARY
duckdb_re2: STATIC_LIBRARY
duckdb_skiplistlib: STATIC_LIBRARY
duckdb_utf8proc: STATIC_LIBRARY
duckdb_yyjson: STATIC_LIBRARY
duckdb_zstd: STATIC_LIBRARY
Building Only the Third-Party Libraries
Individual third-party targets can be built in isolation for testing or debugging:
# Build only the re2 static library
cmake --build build/release --target duckdb_re2
# Build only the PostgreSQL query parser
cmake --build build/release --target duckdb_pg_query