ORB5  4.00
Loading...
Searching...
No Matches
Compiling with CMake

How to compile the code using CMake and its presets.

Author
Emmanuel Lanti
Date
07/2026

ORB5 can be compiled with CMake as an alternative to the Makefile-based build described in Get started. CMake handles configuration, dependency discovery and compiler-specific flags automatically, and ships a set of presets covering the most common configurations.

Requirements

  • CMake ≥ 3.25
  • A build generator: Unix Makefiles (default) or Ninja (via -G Ninja)
  • A supported Fortran compiler: GCC, Intel Classic and oneAPI or NVHPC (the latter is required for GPU builds)
  • The usual dependencies: MPI, HDF5, FFTW (double precision) and LAPACK

As for the Makefile build, these are normally provided by environment modules, which must be loaded before configuring (see Required modules).

Note
To keep the source directory tidy, this CMake configuration enforces out-of-source builds, i.e. the build directory must differ from the source directory.

The configure / build workflow

Building with CMake is a two-step process. First configure the project into a build directory. From the ORB5 root directory:

~/orb5> cmake -B build/release -DCMAKE_BUILD_TYPE=Release

then build it:

~/orb5> cmake --build build/release

Configuration is done only once per build directory. While developing, simply rerun the build command after editing the sources. There is no need to reconfigure. The resulting binaries (orb5 and pszs_offline) are placed in build/release/bin/.

Note that build/release is a name chosen arbitrarily. You could use whichever name fits best for your build directory. It must however match between the configure and build steps.

Available options

Options are passed at configure time with -D<OPTION>=<VALUE>:

Option Default Description
CMAKE_BUILD_TYPE (none) Debug or Release
USE_OPENMP OFF Enable OpenMP hybrid parallelism
USE_OPENACC OFF Enable GPU offload via OpenACC (NVHPC only)
USE_MPI_F08 auto Use the mpi_f08 interface (recommended). Detected at configure time.
GPU_CC 90 GPU compute capability: 80=A100, 90=H100, 100=B200

For example, to build an optimized GPU version for an H100 with the NVHPC compiler:

~/orb5> cmake -B build/gpu \
-DCMAKE_BUILD_TYPE=Release -DUSE_OPENMP=ON \
-DUSE_OPENACC=ON -DGPU_CC=90
~/orb5> cmake --build build/gpu
Note
USE_OPENACC requires the NVHPC toolchain (nvfortran).
Loading the Intel oneAPI module exposes both the oneAPI compilers (ifx/icx) and, on most installations, the classic ones (ifort/icc). CMake selects ifx by default. To build with the classic compiler instead, request it explicitly at configure time with -DCMAKE_Fortran_COMPILER=ifort. Note that ifort is deprecated and absent from recent oneAPI releases.

Using presets

Rather than remembering option combinations, you can use the presets bundled in CMakePresets.json. List them with:

~/orb5> cmake --list-presets

Configure and build a preset without any -D flags:

~/orb5> cmake --preset release-gpu-h100
~/orb5> cmake --build --preset release-gpu-h100

Each preset configures into its own build/<preset-name>/ directory, so several configurations can coexist. The available presets are:

Preset Build type Parallelism / target
debug / release Debug / Release MPI only
debug-mt / release-mt Debug / Release MPI + OpenMP
debug-gpu-h100 / release-gpu-h100 Debug / Release MPI + OpenMP + OpenACC on H100 (NVHPC)

The GPU presets automatically select the NVHPC compiler. On the other hand, the CPU presets use whichever compiler your loaded environment provides.

One-command workflows

A workflow chains the configure and build steps into a single command:

~/orb5> cmake --workflow --list-presets
~/orb5> cmake --workflow --preset release-gpu-h100

Use a workflow for the first build, for continuous integration or when you just want a binary in one shot. Use the two-step configure/build (see Using presets) for the iterative development loop, where you configure once and rebuild many times without reconfiguring.

Machine-specific settings

Site- or user-specific overrides (absolute compiler paths, non-standard dependency locations, ...) can be placed in a CMakeUserPresets.json file at the root of the repository. This file is not tracked by git and can define presets that inherit the shared ones while overriding individual cache variables.

See also
Get started
Makefiles