Draft: Prototype CMake framework
This commit implements a basic CMake scheme for Siesta and (some) utilities. It is almost completely functional, but it is lacking a few features and fixes for temporary shortcuts (see below).
The standard makefile-based build system is untouched (except for bug fixes) and will keep working, coexisting with the CMake flavor.
It needs cmake >= 3.14, and the ninja (>=1.10) backend. Both can be installed easily in most systems, in particular with conda.
From the top level, for a serial version with no extra options:
cmake -S. -B_build -GNinja
cmake --build _build
(Note that the environment variable LAPACK_LIBS must be set to the right linker string)
For the parallel version, setting also an installation directory (with appropriate LAPACK_LIBS and SCALAPACK_LIBS environment variables)):
FC=mpif90 cmake -S. -B_build -GNinja -DWITH_UTILS -DWITH_MPI=ON \
-DCMAKE_INSTALL_PREFIX=/chosen/path
cd _build
ninja gen-basis
ninja tbtrans
ninja (Will build the rest of the targets, including siesta)
ninja install
The above example shows how individual targets can be requested, in any order. Utilities will be installed together with the Siesta executable, in /chosen/path/bin
* Accepted options:
- WITH_UTILS: Compiles programs in Util besides TBrans (currently only
gen-basis and Eig2DOS as representative examples)
- WITH_MPI: Must be used with FC=mpif90 or similar
The "MPI interfaces" are now in an internal library
(whih is slimmed-down for now)
- WITH_NETCDF: See config/cmake/search_for_netcdf.make
The original intention was to use also
-DNCDF and -DNCDF_4, but support for
this depends on a too-simple simple-ncdf library
- WITH_ELPA: See config/cmake/search_for_elpa.cmake
- WITH_LUA: The environmental variable FLOOK_ROOT must be set and
point to an installation of the flook library.
* Some custom modules in config/cmake:
- To search for some libraries
- To check for out-of-source builds
* Utilities:
TBTrans (part of the standard build):
- Use a simplified fdict, with just the preprocessed files (in
Src/simple-fdict)
- A simplified ncdf library (in Src/simple-ncdf) is also used.
Eig2DOS: Very simple example.
Gen-basis:
This is an example of the use of fdf and XC by a Util program.
The CMake work has uncovered a missing explicit dependency on
'cml' in the legacy Makefile through 'die'. It has been solved
by creating a new local file 'local_die.f'.
Note that this target can link to the 'mpi' version of
SiestaXC even without any explicit MPI definitions here (since
'atomxc' does not need any MPI).
It links to the serial fdf.
Changes to existing code:
* Added local_die.f to the Gen-basis Makefile.
* Added 'bye' and 'message' to SiestaXC/local_sys.F
* (Temporary) Slim down MPI/mpi_siesta and use
the -DNO_MPI_INTERFACES preprocessor option.
* Remove explicit imports from mpi_siesta in several files in
the Siesta and TBtrans modules
In systems without mpi_f08 and mpi_ignore_tkr modules
(e.g. Marconi-100), the statement 'use mpi' in the slimmed-down
(no legacy interfaces) mpi_siesta module will not import
interfaces for 'subroutines' such as MPI_Bcast and MPI_Send.
The idiom
use mpi_siesta, only: MPI_Bcast
will then not work.
Note that in TBtrans/m_tbt_proj.F90, the interface for
MPI_WaitAll was faulty: a 'scalar' reqs(1) was passed
instead of the whole array reference.
* Expansion of tab characters in some files.
Missing bits, workarounds, and quirks
* The Ninja backend is necessary to process correctly the module
dependencies in some cases (this might be related to the use of
preprocessor blocks together with the '&' character: see
https://gitlab.kitware.com/cmake/cmake/-/issues/19586). The 'make'
backend cannot process these.
* The fdict library is not fully integrated: we just use two
preprocessed files in an alternate slimmed-down Src/simple-fdict.
* The ncdf library is not complete either (and Src/simple-ncdf is
too simple)
* Version, compiler, and library information is now designed to
be incorporated through a 'configure'd" version-info template,
but the variables needed are not fully implemented. The version
is taken from the project declaration, not from version.info.
* The handling of external libraries should be improved:
- Lapack and Scalapack need the linker flags in environment
variables.
- Netcdf and ELPA are handled through their pkgconfig files,
which might not be well constructed (see the modules
in config/cmake)
- The flook library needs its path to be set in FLOOK_ROOT.
* There are two targets for the fdf library
One version is for serial-mode programs, and the other, for MPI
programs. This is needed in 4.1.X because fdf contains the
logic for MPI broadcast, something that has been removed in the
stand-alone library.
Note the use of specific 'named' module directories at the top level.
Murky points:
* In SiestaXC, 'bye' and 'message' have been added to the local_sys.F
module, because of errors during the compilation of
*Siesta* sources (e.g. iopipes). This might be due to
the modules in SiestaXC being visible during the compilation of
Siesta sources. In principle, the Src directory comes first in
the compilation commands, but apparently the SiestaXC 'sys.mod'
is seen first. (?)