[llvm] [flang-rt][build] Add support for building flang-rt as a standalone project (PR #168321)

liao jun via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 20 19:52:57 PST 2025


zjlcd wrote:

Okay, I think I completely understand what you mean. I’m trying to provide more details to explain my motivation.
When I learned that the llvm-project/compiler-rt project can be build either by using llvm-project/runtimes/CMakeLists.txt(https://github.com/llvm/llvm-project/blob/main/runtimes/CMakeLists.txt#L30) or by using llvm-project/compiler-rt/CMakeLists.txt(https://github.com/llvm/llvm-project/blob/main/compiler-rt/CMakeLists.txt) as the top-level CMake file, I tried both methods and got desired result with both. Therefore, I am trying to got the same results with the flang-rt project. in my humble opinon, the two projects should have similarities, at least in the build method.

As you described, using llvm-project/runtimes/CMakeLists.txt(https://github.com/llvm/llvm-project/blob/main/runtimes/CMakeLists.txt#L30) as the top-level CMake file to build flang-rt went very smoothly. Later, I tried to using llvm-project/flang-rt/CMakeLists.txt as the top-level CMake file and got the troubles mentioned above. In the build-flangrt.sh script, my description may have been inaccurate, causing you some confusion, for which I apologize.

using llvm-project/runtimes/CMakeLists.txt as the top-level CMake file, runtimes-flangrt.sh:
```
#!/usr/bin/bash
work_dir=`pwd`
install_dir=$work_dir/install
ROOTDIR=$work_dir/llvm-project

cd $work_dir
cd llvm-project
cd runtimes
rm -rf build
mkdir build
cd build
cmake -G "Unix Makefiles" \
      -S $ROOTDIR/runtimes \
      -DLLVM_BINARY_DIR=$ROOTDIR/build \
      -DCMAKE_Fortran_COMPILER=$install_dir/bin/flang \
      -DCMAKE_Fortran_COMPILER_WORKS=yes \
      -DLLVM_ENABLE_RUNTIMES=flang-rt \
      -DLLVM_RUNTIMES_BUILD=ON \
      -DFLANG_RUNTIME_F128_MATH_LIB="libquadmath" \
      -DCMAKE_C_COMPILER=/usr/bin/gcc \
      -DCMAKE_CXX_COMPILER=/usr/bin/g++ \
      -DLLVM_TARGET_TRIPLE="x86_64-unknown-linux-gnu" \
      -DCMAKE_INSTALL_PREFIX=$install_dir \
      ..

make -j16
make install
```
This script works smoothly.

new build-flangrt.sh:
```
#!/usr/bin/bash
work_dir=`pwd`
install_dir=$work_dir/install
ROOTDIR=$work_dir/llvm-project


cd $work_dir
cd llvm-project/flang-rt
rm -rf build
mkdir build
cd build
cmake -G "Unix Makefiles" \
      -DLLVM_ENABLE_RUNTIMES=flang-rt \
      -DLLVM_RUNTIMES_BUILD=ON \
      -DCMAKE_CXX_STANDARD=17 \
      -DLLVM_RUNTIMES_BUILD=yes \
      -DFLANG_RUNTIME_F128_MATH_LIB="libquadmath" \
      -DCMAKE_BUILD_TYPE=Release \
      -DLLVM_TARGET_TRIPLE="x86_64-unknown-linux-gnu" \
      -DLLVM_BINARY_DIR=$ROOTDIR/build \
      -DCMAKE_INSTALL_PREFIX=$install_dir \
      -DCMAKE_C_COMPILER=/usr/bin/gcc \
      -DCMAKE_CXX_COMPILER=/usr/bin/g++ \
      -DCMAKE_Fortran_COMPILER=$install_dir/bin/flang \
      -DCMAKE_Fortran_COMPILER_WORKS=yes \
      -DLLVM_INSTALL_TOOLCHAIN_ONLY=ON \
      ..

make -j16
make install
```
This script can not got desired result, and as for why deprecated CMake statements are used, it is to support older versions of CMake, but it seems that in the flang-rt project latest commit, such outdated changes are no longer necessary. `-DLLVM_RUNTIMES_BUILD=ON` doesn't work at the moment.

Thanks again.

https://github.com/llvm/llvm-project/pull/168321


More information about the llvm-commits mailing list