Skip to content

Build LLVM with MSYS2

valtron edited this page Jul 20, 2018 · 2 revisions

It's easier to install LLVM with pacman rather than building it yourself: pacman -S mingw64/mingw-w64-x86_64-llvm.

This assumes you have set up MSYS2.

To build LLVM:

  1. Using pacman, install:
    • mingw64/mingw-w64-x86_64-make
    • mingw64/mingw-w64-x86_64-gcc
    • mingw64/mingw-w64-x86_64-cmake
  2. Download LLVM source and uncompress to folder $LLVMSRC
  3. Create folder $LLVMBUILD and create build.sh containing:
    PATH="/c/Windows/system32:/d/dev/msys64/mingw64/bin"
    
    LLVMSRC="/d/dev/llvm-4.0.0.src"
    LLVMINS="/d/dev/llvm/llvm-4.0"
    
    cmake \
        -G "MinGW Makefiles" \
        -DCMAKE_INSTALL_PREFIX="$LLVMINS" \
        -DCMAKE_BUILD_TYPE="Release" \
        -DLLVM_TARGETS_TO_BUILD="X86" \
        -DLLVM_INCLUDE_TESTS=OFF \
        -DLLVM_ENABLE_CXX1Y=ON \
        -DLLVM_ENABLE_ASSERTIONS=ON \
        -DSPHINX_OUTPUT_HTML=OFF \
        -DSPHINX_OUTPUT_MAN=OFF \
        "$LLVMSRC"
    
    cmake --build .
    cmake --build . --target install
  4. Customize the paths in build.sh accordingly
  5. Customize the LLVM_* options according to your needs; they're documented here
  6. The list of backends for LLVM_TARGETS_TO_BUILD is in $LLVMSRC/CMakeLists.txt, near set(LLVM_ALL_TARGETS. Note: CppBackend was removed in 3.9 :(
  7. cd into $LLVMBUILD
  8. sh build.sh