Advanced Build Configurations#

Introduction#

CMake is a cross-platform build-generator tool. CMake does not build the project, it generates the files needed by your build tool (GNU make, Visual Studio, etc.) for building LLVM.

If you are a new contributor, please start with the Getting Started with the LLVM System or Building LLVM with CMake pages. This page is intended for users doing more complex builds.

Many of the examples below are written assuming specific CMake Generators. Unless explicitly stated otherwise, these commands should work with any CMake generator.

Many of the build configurations mentioned on this documentation page can be utilized by using a CMake cache. A CMake cache is essentially a configuration file that sets the necessary flags for a specific build configuration.

The caches for Clang are located in /clang/cmake/caches within the monorepo. They can be passed to CMake using the -C flag as demonstrated in the examples below along with additional configuration flags.

The caches for Flang are located in /flang/cmake/caches within the monorepo. They can be passed to CMake using the -C flag as demonstrated in the examples below along with additional configuration flags. Due to the Flang’s heavy reliance on Clang, these caches ensure equal handling of Flang and Clang, resulting in both being built within the same arrangement.

Bootstrap Builds#

The Clang CMake build system supports bootstrap (aka multi-stage) builds. At a high level, a multi-stage build is a chain of builds that pass data from one stage into the next. The most common and simple version of this is a traditional bootstrap build.

In a simple two-stage bootstrap build, we build clang using the system compiler, then use that just-built clang to build clang again. In CMake this simplest form of a bootstrap build can be configured with a single option, CLANG_ENABLE_BOOTSTRAP.

$ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release \
    -DCLANG_ENABLE_BOOTSTRAP=On \
    -DLLVM_ENABLE_PROJECTS="clang" \
    <path to source>/llvm
$ ninja stage2

This command itself isn’t terribly useful because it assumes default configurations for each stage. The next series of examples utilize CMake cache scripts to provide more complex options.

By default, only a few CMake options will be passed between stages. The list, called _BOOTSTRAP_DEFAULT_PASSTHROUGH, is defined in clang/CMakeLists.txt. To force the passing of the variables between stages, use the -DCLANG_BOOTSTRAP_PASSTHROUGH CMake option, each variable separated by a “;”. For example: