Set up a Linux development environment for Met.3D

This page describes the steps required to set up a development environment for Met.3D under Linux.

First, create a conda environment for building Met.3D and clone the Met.3D repository as described at Compile Met.3D from source code: Linux (conda).

Then, install and setup an IDE. We describe setups for these IDEs:

CLion

Download and install CLion from the JetBrains website.

Important

Start CLion from the terminal within your activated Met.3D conda environment. Otherwise, it might not find the correct library and include paths.

Open Met.3D as a project

When starting CLion for the first time, you can open a project from the start screen. Otherwise, open a project from the file menu by selecting File → Open. Choose the CMakeLists.txt in your cloned Met.3D repository and open it as a project. Skip the wizard and use default settings.

Set up toolchains using your conda environment

To build Met.3D, a toolchain with build tools needs to be created. Open the CLion settings (File → Settings) and navigate to Build, Execution and Deployment. Open the Toolchains settings and create a new toolchain via the plus symbol (select “System”, name the new toolchain, e.g., “Met.3D toolchain”). The following settings need to be changed:

  • CMake – Select the cmake executable in your Met.3D conda environment.

  • Build Tool – This can be your build tool of choice that is located in your Met.3D conda environment. Here we use “ninja”, also from the Met.3D conda environment.

  • C Compiler – You can leave this on auto-detect, it will usually pick up gcc from your Met.3D conda environment.

  • C++ Compiler – You can leave this on auto-detect, it will usually pick up g++ from your Met.3D conda environment.

  • Debugger – You can leave this on “Bundled GDB” or “Bundled LLDB”, whatever you prefer. We recommend LLDB as it is faster in our experience.

Click “Apply”.

Setup cmake profiles

For building Met.3D one or more CMake profiles are required, e.g., a release and a debug profile. Open the CLion settings (File → Settings) and navigate to Build, Execution and Deployment. Open the CMake settings and either edit the existing profile or create a new profile.

  • Build type – Set this to release or debug, depending on the build type.

  • Toolchain – Set this to the previously created toolchain.

  • Generator – This should be set to the generator for your build tool selected in the toolchain previously. In our case this is Ninja.

  • CMake options – Regardless of your build type you will need to add -DCMAKE_PREFIX_PATH="~/met.3d-base/local", or wherever you created your Met.3D base folder. You can additionally enable any Met.3D-specific build option (see Met.3D CMake options below), e.g. -DENABLE_OPENGL_DEBUG=ON to enable OpenGL debug messaging for a debug build.

  • Build directory – Leave as is. If you want to move the build directory, you will need to specify MET3D_HOME environment variable.

  • Build options – Adjust to the number of processor cores available, e.g., “-j 20”

Note

You can set MET3D_BASE to specify where to download third-party dependencies to. If you do that, you also have to specify it in the environment variables for your run configurations.

After you created the CMake profiles, close the settings, navigate to Tools → CMake → Reset Cache and Reload Project This generates the build folder and a default run configuration.

Next, build Met.3D by pressing the build button (hammer icon) in the top right of the editor window.

Met.3D CMake options

In addition to the standard CMake variables (such as CMAKE_BUILD_TYPE and CMAKE_PREFIX_PATH), Met.3D defines the following project-specific options. All of them default to OFF; enable one by passing -D<OPTION>=ON in the CMake options field above, or on the cmake command line.

Option

Description

Default

ENABLE_FORTRAN

Build the bundled Fortran LAGRANTO (libcalvar) code. Requires a Fortran compiler, and is a prerequisite for ENABLE_LAGRANTO_DERIVATIVES.

OFF

USE_CLANG

Build Met.3D with the Clang compiler instead of the default (GCC).

OFF

ENABLE_OPENGL_DEBUG

Enable OpenGL debug messaging to diagnose rendering and OpenGL errors. Typically combined with a debug build.

OFF

EXPERIMENTAL_PROJECTION_SUPPORT

Enable experimental support for reading projected and rotated grids (see Experimental projection support).

OFF

TEACHING

Enable the sample actors MExampleActor and MExampleMultiVarActor.

OFF

ENABLE_EXPERIMENTAL_DERIVEDVARS

Enable derived variables that are experimental and have not been tested well.

OFF

ENABLE_LAGRANTO_DERIVATIVES

Add a GUI option to compute derivatives with the LAGRANTO library (data on hybrid sigma-pressure grids only). Requires ENABLE_FORTRAN.

OFF

MET3D_ENABLE_CI_TESTS

Enable the Met.3D continuous-integration ctest targets (image-comparison tests).

OFF

Set up run configurations

To run Met.3D from within CLion, you need to create run/debug configurations. Open the run configurations dialog from the top right of your editor window, next to the build symbol. Select Edit Configurations….

A default run configuration called Met3D should already exist. If it does not exist, press the plus icon and add a new CMake Application. Set the following:

  • Target – The target should be “Met3D”. If it does not exist build the application once.

  • Executable – Should also be “Met3D”.

  • Program arguments – Add your command line arguments for Met.3D here, such as --datasets. You can view all by passing --help.

  • Working directory – Can be left as is.

Note

You have to set the MET3D_HOME environment variable, if your build directory is not inside the root of the Met.3D repository. It has to be set to the root of the Met.3D repository. Both, the run configuration and the cmake profile must have the variable set in this case.

If you leave the build directory default, this is not necessary.

Set up coding style

CLion automatically loads the .clang-format file in the Met.3D repository and uses it for auto-formatting.

Note

We recommend to set up line endings used in the IDE to be Unix (\n) line endings. Find this option in the CLion settings (File → Settings) in Editor → Code Style.

Set up file templates

A useful feature are file templates. You can set them up to follow the format guidelines as outlined in C++ coding style and GLSL coding style In the CLion settings (File -> Settings), navigate to Editor. Open the File and Code templates section.

In the Includes tab, edit the C File Header, which is included in all .c, .cpp and .h files you create. In the Files tab, additional file templates can be created, such as a template for the glsl .fx.glsl files we use. For this, you can use the GLSL Effect file template.

QtCreator

Warning

These instructions are outdated and only kept for reference.

Unfortunately, there is no conda package for QtCreator, hence either a package of your Linux distribution needs to be used (Ubuntu and OpenSuSE provide QtCreator through their package managers).

Alternatively, download and install QtCreator from the Qt website.

Important

Start QtCreator from the terminal within your activated Met.3D conda environment. Otherwise it might not find the correct library and include paths.

Open Met.3D as a project

Open the Met.3D project (File → Open File or Project → Select Met.3D’s CMakeLists.txt).

Set up configuration

  • Click “Manage Kits” → Make sure that all tools in the correct PATH are used (i.e., gcc, gdb, etc. from the conda environment - in some attempts, a “wrong” gdb was selected by default)

  • Click “Make default” for “Qt 6.X.X in PATH (met3d) - temporary” (for whichever Qt version is current as you read this)

  • Possibly adjust the Debug and Release paths for the Met.3D binaries

  • Click “Configure Project”

  • In the “Build Settings”: * In “CMake”, set CMAKE_PREFIX_PATH to ~/met.3d-base/local * In “Build Steps”, add “-j 12” (or however many core you have available) to build arguments for parallel compilation

  • In the “Run Settings”: * Change the Met.3D working directory to point to the source directory * Add the MET3D_BASE and MET3D_HOME environment variables

Note

QtCreator by default uses Clang to analyze the code. On our Ubuntu 20.04 LTS, clang is installed from the Ubuntu system but not in the conda environment above. This seems to interfere, and QtCreator displays a number of error messages related to not finding system files. We switched off the plugins “C++/ClangCodeModel” and “Code Analyzer/ClangTools” in the Help/About plugins dialog to make the error message disappear. An alternative could be to install clang in the conda environment, or to install QtCreator from the Qt downloads in the conda environment.