Build configuration

Overview

Before compiling the developer has to choose a configuration of the software. OGS comes in lots of different flavours (e.g. serial / parallelized), can be build with optional features or modules (e.g. MFront material models).

To separate source code from generated files such as compiled libraries, executables, test outputs and IDE projects we create build-directories. They can be placed arbitrarily. You can have as many build-directories as you like for e.g. different configurations but they will all use one source code directory. A typically directory structure:

  • ogs-source-code (or simply ogs)
  • build (should be placed outside the source directory)
    • release
    • debug

Configure with CMake

For configuring a build the open source tool CMake is used. CMakeLists.txt files replace traditional Makefiles or IDE project files.

We provide CMake configuration presets defined in CMakePresets.json for simple build configuration! Otherwise see Configure manually). See the following table for commonly used presets:

Available CMake presets

Ninja1 Visual Studio
CLI Release release msvc-release
CLI Debug debug msvc-debug
GUI Release release-gui msvc-release-gui
GUI Debug debug-gui msvc-debug-gui
PETSc Release2 release-petsc -
PETSc Debug2 debug-petsc -

Configure with a preset

In the source directory run cmake with a preset:

# Usage: cmake --preset [preset-name]
cmake --preset release

This will create a build-directory outside the source tree (../build/release) with the default CMake options and the Release configuration.

Additionally you can pass any CMake variable or option with -DVARIABLE_NAME=VALUE (note the -D in front!) to the CMake command. You can also overwrite the generator with the -G parameter or the build-directory with the -B parameter (to see all available options just run cmake --help)

Also all the compiled files will be generated in this directory. This keeps the actual source code clean from intermediate files which are generated from the source code. Nothing inside the build directory will ever be version controlled because its contents can be regenerated anytime from the source code.

When you want to start over with a new configuration simply delete the build-directory, create a new one and reconfigure.

See this for a list of commonly used available options.

User-defined presets

You can create a CMakeUserPresets.json file in the root source directory with your own presets (this file is ignored by git):

{
  "version": 1,
  "configurePresets": [
    {
      "name": "my-release",
      "inherits": "release",
      "cacheVariables": {
        "OGS_USE_PIP": "ON"
      }
    }
  ]
}

Windows notes

Ninja requirement: Use the Visual Studio command line

To use the Ninja build tool you need to configure in the Visual Studio command line. In the Start menu under Visual Studio 2019 you find a application link to x64 Native Tools Command Prompt for VS 2019. This starts a command line setup for Visual Studio 64-bit. Now you can use a Ninja preset:

cmake --preset release

Multi-configuration with Visual Studio

OGS requires you to have one build directory which corresponds to one configuration. If you want to have e.g. a release and a debug build you need to create two build directories. This is nothing new to Linux / GCC user but differs to Visual Studios default behavior having just one build-folder / project with different configurations. A typical Visual Studio setup with both Release and Debug configurations would be initialized as follows:

cmake --preset msvc-release # creates ../build/msvc-release/OGS.sln
cmake --preset msvc-debug   # creates ../build/msvc-debug/OGS.sln

Please also note that in Visual Studio you have to choose the correct configuration (i.e. when opening the solution-file in the release-folder you have to switch the Visual Studio configuration to Release)!

Pro Tip: Use a better terminal application

Use the Windows Terminal for a better terminal experience. It offers modern terminal features such as multiple tabs and panes.

Option: Configure manually

If you cannot use CMake presets (e.g. when your CMake installation does not support it) manually create a build directory and run CMake from within with all required parameters, e.g:

# in ogs source-directory
mkdir -p ../build/release
cd ../build/release
cmake ../../ogs -G Ninja -DCMAKE_BUILD_TYPE=Release

Using a different compiler

Set the CC and CXX environment variables, e.g.:

CC=mpicc CXX=mpic++ cmake ../ogs -G Ninja -DCMAKE_BUILD_TYPE=Release -DOGS_USE_PETSC=ON

Option: Configure with a visual tool

CMake comes with a graphical tool called cmake-gui. You can find it in the Windows Start Menu. First you need to set the source and build directory. Then click Configure. Now choose the generator to be used (e.g. Visual Studio 16 2019 for Visual Studio 2019). Now choose your desired configuration options by toggling the corresponding checkboxes. Click Configure again. Click Configure often enough until the Generate-button becomes visible. Pressing Generate will finally generate the project files inside the chosen build directory.

A more convenient way of running CMake on the command line is to use the ccmake tool. This is a shell tool but with some graphical user interface. If you want to use a preset configure with regular cmake first (ccmake does not support presets) and then run ccmake supplying the path to the build directory:

cmake --preset release
ccmake ../build/release

You are now presented the available configuration options. You can navigate in the list with the cursor keys and toggle / alter options with Enter. You may also press T to toggle (previously hidden) advanced options. Press C again until the Generate-option becomes visible. Press G to generate the project files and exit ccmake.

There is also the tool cmake-gui available (which supports presets), please see the Win-Tab for a description.

Please see the Linux instructions!


  1. Requires the ninja-tool. See install instructions↩︎

  2. Requires the pkg-config-tool. Can be installed via e.g. apt or brew↩︎ ↩︎


This article was written by Lars Bilke. If you are missing something or you find an error please let us know.
Generated with Hugo 0.122.0 in CI job 418530 | Last revision: February 8, 2024
Commit: [web] Added correct ccmake usage. 70e3bd1  | Edit this page on