.. SPDX-FileCopyrightText: 1992-2026 NWO-I/SRON Space Research Organisation Netherlands
..
.. SPDX-License-Identifier: CC-BY-4.0
.. _sec:compile:
Compile from source
===================
.. highlight:: none
Getting started
^^^^^^^^^^^^^^^
The SPEX source code can be compiled using the multi-platform Cmake build system. See ``_
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.
This Zenodo contains a tar.bz2 file containing the source code of SPEX:
`spex-3.99.00-Source.tar.bz2 `_.
Unpack it in a convenient directory::
unix:~/Software> tar xvfj spex-3.99.00-Source.tar.bz2
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
- BLAS (*)
- LAPACK (*)
- PGPLOT (*)
- 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)
- `CMake `_
- `XQuartz `_
- 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-3.99.00-Source> cmake .
If no errors occured and all libraries were found, then type 'make'::
unix:~/Software/SPEX-3.08.02-Source> make
When the program needs to be installed system wide, then execute::
unix:~/Software/SPEX-3.08.02-Source> sudo make install
The program will be installed to /opt/spex by default. Usually, administrator rights are necessary to copy the files to the right location.
Before you can run SPEX, the environment needs to be set. This can be done with the source command::
source /opt/spex/spexdist.sh (bash shell)
source /opt/spex/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-3.99.00-Source> cmake . -DCMAKE_Fortran_COMPILER=ifort
Install prefix
""""""""""""""
Install SPEX at a different location in the 'make install' step::
unix:~/Software/SPEX-3.99.00-Source> cmake . -DCMAKE_INSTALL_PREFIX=/home/user/software
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-3.99.00-Source> 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.