A tool to bundle custom headers into one single .cpp file.
This tool is based on LLVM/Clang. You can either use system libraries or build strictly against a custom LLVM version.
On Ubuntu/Debian:
$ sudo apt install llvm-dev libclang-dev build-essential cmake ninja-buildFor a fully static binary, you need to build LLVM from source or use a static distribution.
# Example: Build LLVM 21.1.0 from source
git clone https://github.com/llvm/llvm-project.git
cd llvm-project
git checkout llvmorg-21.1.0
cmake -S llvm -B build -G Ninja \
-DCMAKE_INSTALL_PREFIX=$HOME/llvm-install \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS="clang" \
-DLLVM_ENABLE_ZSTD=OFF \
-DBUILD_SHARED_LIBS=OFF
cmake --build build --target installSystem Dependencies:
cmake -S . -B build -G Ninja
cmake --build buildCustom LLVM:
If you have a custom LLVM installed (e.g. in ~/llvm-install) but want to link dynamically:
cmake -S . -B build -G Ninja \
-DLLVM_DIR=$HOME/llvm-install/lib/cmake/llvm \
-DClang_DIR=$HOME/llvm-install/lib/cmake/clang
cmake --build buildIf you built LLVM manually as above:
cmake -S . -B build -G Ninja \
-DBUILD_STATIC=ON \
-DUSE_STATIC_CRT=ON \
-DLLVM_DIR=$HOME/llvm-install/lib/cmake/llvm \
-DClang_DIR=$HOME/llvm-install/lib/cmake/clang
cmake --build build$ ./build/cpp-bundle FILE [OPTIONS]...Since this tool is based on LLVM/Clang preprocessor, you could use the same options to bundle your code.
It is common to use a library in online competitive programming contests like Codeforces, AtCoder, etc. However, this kind of contest only allows you to submit a single C++ code. Therefore, if we modularize our library, we need to bundle them.