---
tags: clang-format, LLVM
---
# Build the newest version of clang-format from LLVM
1. Clone the LLVM project from github.
```
git clone https://github.com/llvm/llvm-project.git
```
2. Create the `build` directory in the `llvm-project`
```
cd llvm-project
mkdir build
cd build
```
3. Complie clang-format
```
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_BUILD_STATIC=true -DLLVM_ENABLE_PROJECTS="clang" ../llvm
ninja clang-format
strip clang-format
```
```
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_BUILD_STATIC=true -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" ../llvm
```
> CMAKE_BUILD_TYPE:STRING
This configures the optimization level for make or ninja builds.
>
> Possible values:
>
> | Build Type | Optimizations | Debug Info | Assertions | Best suited for |
> |:--------------:|:-------------:|:----------:|:----------:|:--------------------------:|
> | Release | For Speed | No | No | Users of LLVM and Clang |
> | Debug | None | Yes | Yes | Developers of LLVM |
> | RelWithDebInfo | For Speed | Yes | No | Users that also need Debug |
> | MinSizeRel | For Size | No | No | When disk space matters |
4. Check clang-format version
```
llvm-project/build/bin/clang-format --version
clang-format version 17.0.0 (https://github.com/llvm/llvm-project.git 01fa764c9a3473f2c63241ac5e874019e666f405)
```