CMake

Prefer presets for local source builds, and use CPM or FetchContent when vendoring treeweave into another project.

Vendored C++

CPM.cmake:

CPMAddPackage("gh:DiamonDinoia/treeweave@stable")
add_executable(my_app example.cpp)
target_link_libraries(my_app PRIVATE treeweave::treeweave)

FetchContent:

include(FetchContent)
FetchContent_Declare(
    treeweave
    GIT_REPOSITORY https://github.com/DiamonDinoia/treeweave.git
    GIT_TAG stable
)

FetchContent_MakeAvailable(treeweave)
add_executable(my_app example.cpp)
target_link_libraries(my_app PRIVATE treeweave::treeweave)

Targets

Language

CMake target

Notes

C++

treeweave::treeweave

Header/interface target for #include <treeweave/treeweave.hpp>.

C

treeweave::treeweave_c

Shared C ABI, enabled by TREEWEAVE_BUILD_C_API=ON.

C

treeweave::treeweave_c_static

Static C ABI, enabled by TREEWEAVE_BUILD_C_API=ON.

Fortran

treeweave_fortran

Local target when TREEWEAVE_BUILD_FORTRAN=ON.

Profiles

Use cmake --preset <name> from a treeweave checkout:

Preset

What it sets

dev-release

Release build, TREEWEAVE_ARCH=native; examples/tests use their top-level defaults.

dev-debug

Debug build with -Og -g and TREEWEAVE_ARCH=native.

multiarch

TREEWEAVE_C_MULTIARCH=ON, TREEWEAVE_ARCH=x86-64; examples off.

multiarch-arm

TREEWEAVE_C_MULTIARCH=ON, TREEWEAVE_ARCH=armv8-a; examples off.

bindings-matlab

TREEWEAVE_BUILD_MATLAB=ON; examples/tests off via lib-release.

bindings-octave

Same CMake options as bindings-matlab; intended for mkoctfile/Octave builds.

bindings-fortran

TREEWEAVE_BUILD_FORTRAN=ON; examples/tests off via lib-release.

Options

These are the user-facing CMake cache options:

# Build example programs. Defaults ON for a direct treeweave checkout so
# developers can run examples immediately; defaults OFF for FetchContent and
# add_subdirectory consumers so vendoring treeweave stays small.
option(TREEWEAVE_BUILD_EXAMPLES "Build C++ examples" ${PROJECT_IS_TOP_LEVEL})
# Build the C++/C test suites. Defaults ON only for a direct treeweave checkout;
# consumers opt in explicitly when they want to test the vendored dependency.
option(TREEWEAVE_BUILD_TESTS "Build tests" ${PROJECT_IS_TOP_LEVEL})
# Build the C ABI libraries. This provides treeweave::treeweave_c
# (shared, when the platform supports shared libraries) and
# treeweave::treeweave_c_static. Most non-C++ bindings link through this ABI.
option(TREEWEAVE_BUILD_C_API "Build C ABI" ON)
# Build the Python nanobind extension and register the pytest smoke/parity
# target. Normal Python users should prefer the PyPI wheel.
option(TREEWEAVE_BUILD_PYTHON "Build Python binding" OFF)
# Register the Julia binding test suite against the C ABI. Normal Julia users
# should prefer Pkg.add, which downloads the release C ABI automatically.
option(TREEWEAVE_BUILD_JULIA "Build Julia tests" OFF)
# Build the MATLAB/Octave MEX binding and register its smoke test. The
# bindings-matlab and bindings-octave presets are the preferred entry points.
option(TREEWEAVE_BUILD_MATLAB "Build MATLAB/Octave MEX" OFF)
# Build the Fortran iso_c_binding module plus its example and tests. Requires a
# modern Fortran compiler on PATH or CMAKE_Fortran_COMPILER set explicitly.
option(TREEWEAVE_BUILD_FORTRAN "Build Fortran binding" OFF)
# Build the JavaScript/TypeScript binding. With a normal compiler this builds
# the native N-API addon; with the Emscripten preset it builds the WASM backend.
option(TREEWEAVE_BUILD_JS "Build JS/TS binding" OFF)
# Build local performance benchmark executables. OFF by default: the benchmark
# sources are not clang-tidy clean, so a top-level default would drag them into
# the analysis preset. Turn on via the bench preset.
option(TREEWEAVE_BUILD_BENCHMARKS "Build benchmarks" OFF)
# Add the native-interpolator baselines to the zeta benches: Boost.Math
# chebyshev_transform (C++, needs FFTW), GSL gsl_cheb and baobzi (C). Every
# dependency is REQUIRED once this is ON, so a missing one fails the configure.
option(TREEWEAVE_BENCH_BASELINES "Add native interpolators to the zeta benches" OFF)
# Build the CodSpeed benchmark used by CI. Prefer the codspeed preset.
option(TREEWEAVE_BUILD_CODSPEED "Build CodSpeed benchmark" OFF)
# Add documentation targets: doxygen, sphinx, and docs. Requires Doxygen,
# sphinx-build, and the Python packages from docs/requirements.txt.
option(TREEWEAVE_GENERATE_DOCS "Build docs targets" OFF)
# Build the C ABI with runtime ISA dispatch where the platform supports it. On
# x86 this builds a portable baseline plus wider variants and selects at runtime
# (GCC/Clang: SSE2/SSE4.2/AVX2/AVX-512; MSVC ABI: SSE2/AVX/AVX2/AVX-512). On
# unsupported platforms it falls back to the normal single-arch C ABI build.
option(TREEWEAVE_C_MULTIARCH "Runtime ISA dispatch" OFF)
# Fail the build if any symbol shared across the multi-arch ISA rungs differs
# between them (a leak the linker could ship at the wrong ISA). Runs
# .github/scripts/check_rung_symbols.sh on the object files whenever
# treeweave_c / treeweave_c_static builds. Needs bash + nm + objdump. Intended
# for release pipelines where TREEWEAVE_BUILD_TESTS=OFF skips the equivalent
# ctest; errors out if set without an active multi-arch fan-out.
option(TREEWEAVE_VERIFY_RUNGS "Cross-rung symbol gate at build time" OFF)
# Treat project warnings as errors. Dependency warnings are kept out of this
# policy; this is intended to keep treeweave's own code clean.
option(TREEWEAVE_WARNINGS_AS_ERRORS "Treat warnings as errors" ON)
# Enable ASan/UBSan for project targets. Prefer sanitizer presets where
# available because they pick compiler/build settings known to fit CI memory.
option(TREEWEAVE_ENABLE_SANITIZERS "Enable ASan/UBSan" OFF)
# Run clang-tidy/cppcheck. OFF by default: as a global CMAKE_CXX_CLANG_TIDY it
# would also lint vendored deps configured outside the FetchContent guard (e.g.
# nanobind in the Python preset). Turn on via the analysis preset.
option(TREEWEAVE_ENABLE_STATIC_ANALYSIS "Run static analysis" OFF)
# Build with coverage instrumentation. Prefer the coverage preset.
option(TREEWEAVE_ENABLE_COVERAGE "Build coverage" OFF)
# Link-time optimization, OFF by default: the header-only C++ API gains nothing
# and IPO fills the installed static archive with single-toolchain IL. gcc and
# MSVC ignore it when ON; see cmake/treeweave_toolchain.cmake.
option(TREEWEAVE_ENABLE_IPO "Link-time optimization" OFF)

Installed package

cmake --preset dev-release
cmake --build build/dev-release --parallel
cmake --install build/dev-release --prefix /install/prefix
find_package(treeweave REQUIRED)
target_link_libraries(my_app PRIVATE treeweave::treeweave_c)

The header-only C++ API is not part of the installed find_package(treeweave) package because it depends on FetchContent-only headers. Consume it in-tree via FetchContent or add_subdirectory. The installable part is the C ABI: treeweave::treeweave_c and treeweave::treeweave_c_static.

Source build

Requirements: a C++20 compiler and CMake 3.25 or newer. CMake fetches the dependencies automatically.

git clone https://github.com/DiamonDinoia/treeweave.git
cd treeweave
cmake --preset dev-release
cmake --build build/dev-release -j
ctest --test-dir build/dev-release

For a non-CMake C++ build, configure once to consolidate headers into <build>/include:

cmake --preset dev-release
cmake --build build/dev-release
g++ -std=c++20 -O3 -march=native examples/c++/simple1d.cpp -Ibuild/dev-release/include -o simple1d

The build writes build/dev-release/make.inc with CXX, CXXFLAGS, and TREEWEAVE_INC. examples/c++/Makefile includes it, so cd examples/c++ && make builds every example.