-
Notifications
You must be signed in to change notification settings - Fork 142
Building Flang
We build Flang on Intel x86-64 and OpenPOWER hardware running either Ubuntu or Red Hat.
Building LLVM requires fairly modern compiler toolchain and CMake, check Getting started with LLVM and Building LLVM with CMake for the full list.
http://llvm.org/docs/CMake.html
- LLVM
- openmp-llvm
- modified clang
The latest supported LLVM version is 5.0. Flang also supports LLVM version 4.0.
To build version 4.0, substitute 40 for 50 in the build instructions below.
The command-line examples provided below will install everything into the default system location.
To specify a custom install location, add -DCMAKE_INSTALL_PREFIX=<INSTALL_PREFIX>
to each of the CMake commands given below.
When using a custom install location, you must make sure that the bin directory is on your PATH when building and running flang.
Flang is developed outside of the llvm source tree.
cd where/you/want/to/build
git clone https://github.com/llvm-mirror/llvm.git
cd llvm
git checkout release_50
mkdir build && cd build
cmake ..
make
sudo make install
cd where/you/want/to/build
git clone https://github.com/flang-compiler/clang.git
cd clang
git checkout flang_release_50
mkdir build && cd build
cmake ..
make
sudo make install
If you use CMAKE_INSTALL_PREFIX
in Step 1 and <INSTALL_PREFIX>/bin
is not in your path, you need to add -DLLVM_CONFIG=<INSTALL_PREFIX>/bin/llvm-config
when invoking CMake, otherwise you will encounter an error related to LLVMConfig.cmake not being found.
cd where/you/want/to/build
git clone https://github.com/llvm-mirror/openmp.git
cd openmp/runtime
git checkout release_50
mkdir build && cd build
cmake ..
make`
sudo make install
cd where/you/want/to/build
git clone https://github.com/flang-compiler/flang.git
cd flang
mkdir build && cd build
cmake -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_Fortran_COMPILER=flang ..
make
sudo make install
If you use CMAKE_INSTALL_PREFIX
in Step 1 and <INSTALL_PREFIX>/bin
is not in your path, you need to add -DLLVM_CONFIG=<INSTALL_PREFIX>/bin/llvm-config
and set the explicit paths for the compilers (i.e. -DCMAKE_CXX_COMPILER=<INSTALL_PREFIX>/bin/clang++ -DCMAKE_C_COMPILER=<INSTALL_PREFIX>/bin/clang -DCMAKE_Fortran_COMPILER=<INSTALL_PREFIX>/bin/flang
) when invoking CMake, otherwise you will encounter errors.
Spack is a flexible package manager for HPC system and can be used to build flang and its dependencies.
Get Spack
git clone https://github.com/llnl/spack.git
On bash:
source spack/share/spack/setup-env.sh
or tcsh:
source spack/share/spack/setup-env.csh
Build Flang and its depencencies:
spack install flang
Watch out for the installation path, the flang wrapper script in there is ready to use.
spack compiler add path/to/flang/bin
Now you might want to edit your ~/.spack/*/compilers.yaml to combine flang with any c compiler of your choice.
To test your installation, create a simple "hello world" program, like the following:
program hello
print *, 'hello world'
end
Next, compile the program in the following manner. We will assume the program is called hello.f90
% flang hello.f90
If the build succeeds, then you can execute the program in the following manner:
% ./a.out