Skip to content
Bryan Chan edited this page Apr 22, 2021 · 7 revisions

Building Classic Flang on LLVM 12

Sample script (adapted from upstream instructions):

#!/bin/bash

buildtype=Debug
installdir=$PWD/install
builddir=$PWD/build

if [ ! -d classic-flang-llvm-project ]; then
  git clone -b release_12x https://github.com/flang-compiler/classic-flang-llvm-project
fi
if [ ! -d classic-flang ]; then
  git clone https://github.com/flang-compiler/flang classic-flang
fi

mkdir -p $builddir/llvm
pushd $builddir/llvm
cmake -G Ninja \
  -DCMAKE_BUILD_TYPE=$buildtype \
  -DCMAKE_INSTALL_PREFIX=$installdir \
  -DCMAKE_C_COMPILER=gcc \
  -DCMAKE_C_COMPILER_LAUNCHER=ccache \
  -DCMAKE_CXX_COMPILER=g++ \
  -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
  -DCLANG_OPENMP_NVPTX_DEFAULT_ARCH=sm_70 \
  -DLLVM_ENABLE_PROJECTS="clang" \
  -DLLVM_ENABLE_CLASSIC_FLANG=on \
  -DLLVM_ENABLE_ASSERTIONS=on \
  -DLLVM_OPTIMIZED_TABLEGEN=on \
  -DLLVM_TARGETS_TO_BUILD="AArch64;NVPTX;X86" \
  ../../classic-flang-llvm-project/llvm || exit 1
ninja check-all install || exit 1
popd

if ! llvm_lit="$(realpath --canonicalize-existing $builddir/llvm/bin/llvm-lit 2>/dev/null)" || \
    [ ! -x "$llvm_lit" ]; then
  echo "no usable llvm-lit"
  exit 1
fi

mkdir -p $builddir/openmp-shared
pushd $builddir/openmp-shared
cmake -G Ninja \
  -DCMAKE_BUILD_TYPE=$buildtype \
  -DCMAKE_INSTALL_PREFIX=$installdir \
  -DCMAKE_C_COMPILER=$installdir/bin/clang \
  -DCMAKE_CXX_COMPILER=$installdir/bin/clang++ \
  -DOPENMP_LLVM_TOOLS_DIR="$(dirname $llvm_lit)" \
  -DLIBOMPTARGET_NVPTX_COMPUTE_CAPABILITIES=70 \
  ../../classic-flang-llvm-project/openmp || exit 1
ninja check-openmp install || exit 1
popd

mkdir -p $builddir/libpgmath
pushd $builddir/libpgmath
cmake -G Ninja \
  -DCMAKE_BUILD_TYPE=$buildtype \
  -DCMAKE_INSTALL_PREFIX=$installdir \
  -DCMAKE_C_COMPILER=$installdir/bin/clang \
  -DCMAKE_CXX_COMPILER=$installdir/bin/clang++ \
  -DLLVM_CONFIG=$installdir/bin/llvm-config \
  -DLLVM_TARGETS_TO_BUILD="AArch64;X86" \
  -DLIBPGMATH_LLVM_LIT_EXECUTABLE="$llvm_lit" \
  ../../classic-flang/runtime/libpgmath || exit 1
ninja check-libpgmath install || exit 1
popd

mkdir -p $builddir/classic-flang
pushd $builddir/classic-flang
cmake -Wno-dev -G 'Unix Makefiles' \
  -DCMAKE_BUILD_TYPE=$buildtype \
  -DCMAKE_INSTALL_PREFIX=$installdir \
  -DCMAKE_C_COMPILER=$installdir/bin/clang \
  -DCMAKE_CXX_COMPILER=$installdir/bin/clang++ \
  -DCMAKE_Fortran_COMPILER=$installdir/bin/flang \
  -DCMAKE_Fortran_COMPILER_ID=Flang \
  -DFLANG_LLVM_EXTENSIONS=on \
  -DLLVM_INCLUDE_DOCS=on \
  -DLLVM_ENABLE_DOXYGEN=on \
  -DLLVM_CONFIG=$installdir/bin/llvm-config \
  -DLLVM_TARGETS_TO_BUILD="AArch64;X86" \
  -DLLVM_EXTERNAL_LIT="$llvm_lit" \
  -DWITH_WERROR=off \
  ../../classic-flang || exit 1
make install || exit 1
make check-all || exit 1
popd

echo "SUCCESS"
Clone this wiki locally