This brief CMake script works across operating systems to build Flang-f18 and LLVM from source. It is inspired by Jeff Hammond.
cmake -B build --install-prefix=/path/to/install-llvmBuild + install LLVM Flang:
cmake --build buildby specifying the "url" variable, particular versions of LLVM can be built, for example the 22.x release:
cmake -B build \
-Durl=https://github.com/llvm/llvm-project/archive/refs/heads/release/22.x.zipThe source download is about 300 MB. LLVM takes about a half-hour to build on a powerful laptop or workstation.
To use the compiler after install:
source clang-latest.shor on Windows Powershell:
. clang-latest.ps1lldLLVM linkermlirintermediate representationpstlParallel STL (optional)pollyLoop optimization (optional)
See ulimit settings if link failures occur.
The installed binaries take a few gigabytes of disk space.
du -sh ~/llvm-latest # the install prefix3.5G
About 3.5 Gigabytes are used for the installed LLVM binaries.
The source directory can be deleted after the build / install is complete.
du -sh $TMPDIR/llvm-src1.8G
The build directory can be deleted after the build / install is complete.
du -sh $TMPDIR/llvm-build5.0G
Interesting. A linux system I used also had
1024and macOS has256. I will note it in the Readme.