源码编译llvm

cmake -G "Unix Makefiles" -DLLVM_ENABLE_PROJECTS="clang;lldb;clang-tools-extra;lld" -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" -DCMAKE_BUILD_TYPE="Release" -DLLVM_ENABLE_RTTI=ON -DLLVM_INCLUDE_TESTS=OFF -DCMAKE_INSTALL_PREFIX="/opt/llvm" ../llvm
make -j
make install

常用选项

参阅

Variable Purpose
CMAKE_C_COMPILER Tells cmake which C compiler to use. By default, this will be /usr/bin/cc.
CMAKE_CXX_COMPILER Tells cmake which C++ compiler to use. By default, this will be /usr/bin/c++.
CMAKE_BUILD_TYPE Tells cmake what type of build you are trying to generate files for. Valid options are Debug, Release, RelWithDebInfo, and MinSizeRel. Default is Debug.
CMAKE_INSTALL_PREFIX Specifies the install directory to target when running the install action of the build files.
Python3_EXECUTABLE Forces CMake to use a specific Python version by passing a path to a Python interpreter. By default the Python version of the interpreter in your PATH is used.
LLVM_TARGETS_TO_BUILD A semicolon delimited list controlling which targets will be built and linked into llvm. The default list is defined as LLVM_ALL_TARGETS, and can be set to include out-of-tree targets. The default value includes: AArch64, AMDGPU, ARM, AVR, BPF, Hexagon, Lanai, Mips, MSP430, NVPTX, PowerPC, RISCV, Sparc, SystemZ, WebAssembly, X86, XCore.
LLVM_ENABLE_DOXYGEN Build doxygen-based documentation from the source code This is disabled by default because it is slow and generates a lot of output.
LLVM_ENABLE_PROJECTS A semicolon-delimited list selecting which of the other LLVM subprojects to additionally build. (Only effective when using a side-by-side project layout e.g. via git). The default list is empty. Can include: clang, clang-tools-extra, cross-project-tests, flang, libc, libclc, lld, lldb, mlir, openmp, polly, or pstl.
LLVM_ENABLE_RUNTIMES A semicolon-delimited list selecting which of the runtimes to build. (Only effective when using the full monorepo layout). The default list is empty. Can include: compiler-rt, libc, libcxx, libcxxabi, libunwind, or openmp.
LLVM_ENABLE_SPHINX Build sphinx-based documentation from the source code. This is disabled by default because it is slow and generates a lot of output. Sphinx version 1.5 or later recommended.
LLVM_BUILD_LLVM_DYLIB Generate libLLVM.so. This library contains a default set of LLVM components that can be overridden with LLVM_DYLIB_COMPONENTS. The default contains most of LLVM and is defined in tools/llvm-shlib/CMakelists.txt. This option is not available on Windows.
LLVM_OPTIMIZED_TABLEGEN Builds a release tablegen that gets used during the LLVM build. This can dramatically speed up debug builds.