Compile from source¶
Getting started¶
The SPEX source code can be compiled using the multi-platform Cmake build system. See http://www.cmake.org/ for more information and downloads, or check the package manager of your Linux distribution. The SPEX install needs CMake version 3.22 or higher.
Since SPEX is programmed mostly in Fortran 90, it is recommended to use a recent Fortran compiler. SPEX has been tested with GFortran (version 4 and above) and the Intel Fortran Compiler.
You can get the latest version of the SPEX source code from Codeberg.org (which is a Github alternative).
Warning
Because the SPEX data files are handled by the large file service of git, please make sure that you do not only clone the repository, but also check out the git lfs files. You may need to install the git-lfs package in your environment.
Please ensure that you have installed the git-lfs package in your environment, before you execute these commands:
git lfs install # Needs to be executed once to add LFS support to the local git installation.
git clone https://codeberg.org/SPEX/spex.git
cd spex
git lfs fetch --all
git lfs checkout
Library dependencies¶
SPEX depends on a few external libraries to function. For some of those, the library source code has been included in the SPEX source code package. By default, CMake will look for system libraries to link to. If they are not there, then the version in the source package will be used.
The following libraries and packages are required to compile SPEX:
CMake
X11
Libedit
CFITSIO
Astropy (**)
Numpy (**)
Matplotlib (**)
Meson (**)
(*) The SPEX source tree also contains the library if necessary. (**) These packages are only necessary for the Python interface.
All these libraries are commonly available in Linux distributions, so please read the documentation of your distribution to find out how to install these libraries. Please note that some distributions require you to also install the ‘development’ package of a library to be able to use them during compilation. In the Debian repository, for example, the development package of libedit is called ‘libedit-dev’.
Below, we list some library-specific comments that can be helpful in case of problems.
Libedit¶
The libedit library handles the command-line input at the SPEX prompt. This library is commonly available on both Linux and Mac. On some Linux distributions, it may be needed to install the development library to have it availble for compilation purposes (e.g. ‘libedit-dev’ on Debian/Ubuntu systems).
CFITSIO¶
The cmake program will be able to find system versions of CFITSIO automatically. If CFITSIO is not installed,
please install it using a package manager (e.g. libcfitsio-dev) or compile it yourself. In case cmake cannot find
the CFITSIO library, then add the flag -DCFITSIO_ROOT_DIR=/usr/local to the cmake command (in this example,
CFITSIO was compiled using --prefix=/usr/local and the library is found in /usr/local/lib/libcfitsio.so.
Make sure to provide the path where your libcfitsio library is installed).
BLAS and LAPACK¶
Some of the SPEX models depend heavily on the BLAS and LAPACK linear algebra packages. The default routines are available in the SPEX source tree, but compiling those will not provide the best performance. The performance improves substantially if an optimized BLAS or LAPACK library is used. There are three tested options:
Intel Math Kernel Library (MKL)
OpenBLAS
Apple Acceleration framework
When compiling with the Intel Fortran compiler, using MKL is quite obvious. To link the MKL library, add the following option to the cmake command:
cmake . -DMKL=YES
If MKL is not set, cmake will look for other options, like OpenBLAS, if they are installed on your machine. If nothing is found, the non-optimized code in the SPEX source tree is used.
MacOS instructions¶
The compilation of SPEX on MacOS is slightly more demanding. SPEX can run natively on MacOS (without ports), but then it needs a few pre-installed programs:
Xcode and the Xcode command-line tools (Through the App store)
A Fortran compiler. For example GCC/GFORTRAN.
General Compilation Instructions¶
When all library dependencies are installed, the compilation process can begin. Execute cmake in the root directory of the SPEX source tree, where CMakeLists.txt is located (mind the dot):
unix:~/Software/spex> cd build
unix:~/Software/spex/build> cmake .. -DCMAKE_INSTALL_PREFIX=<your-preferred-install-location>
Please change <your-preferred-install-location> in the path that you want to install SPEX in.
For example: $HOME/spex4 to install SPEX in your home directory.
The program will be installed to /opt/spex by default if no install prefix is specified.
If no errors occured and all libraries were found, then type ‘make’:
unix:~/Software/spex/build> make
When the program needs to be installed in a directory owned by the user, then execute:
unix:~/Software/spex/build> make install
When the program needs to be installed in a non-user director, then execute:
unix:~/Software/spex/build> sudo make install
Before you can run SPEX, the environment needs to be set. This can be done with the source command:
source $HOME/spex4/spexdist.sh (bash shell)
source $HOME/spex4/spexdist.csh (C-type shell)
In case you used another prefix for the SPEX installation directory, you can find spexdist.sh or spexdist.csh in the prefix directory that you set. To load the SPEX environment automatically, add the relevant source line to your ~/.cshrc or ~/.bashrc file.
Optional features¶
There are several options that can be passed to CMake to influence the build process through the -D operator. Of course, all options can be combined in a single cmake call. See the cmake documentation and the CMakeLists.txt file for details.
Compiler selection¶
Select a different fortran compiler:
unix:~/Software/spex/build> cmake . -DCMAKE_Fortran_COMPILER=ifort
Python interface¶
By default, SPEX tries to build the Python interfaces as well. If you do not need the Python interfaces, then provide the following flag to CMake:
unix:~/Software/spex/build> cmake . -DNOPYTHON=YES
Troubleshooting¶
During the CMake process, it will try to find the compilers and libraries it needs, but this does not always work if the libraries are in a non-standard location. You can provide the following flags to CMake to point it in the right direction:
-DCMAKE_Fortran_COMPILER=gfortran: Specify the Fortran compiler to use.-DCFITSIO_ROOT_DIR=/usr/local: Specify the directory where CFITSIO is installed.
If you are installing SPEX inside a Python virtual environment, then you can provide
the flag -DPython3_FIND_VIRTUALENV=ONLY. This will tell CMake to only look for
Python related dependencies in the virtual environment that you loaded.