GOTM

Modern CMake and sub-modules

Karsten Bolding

June 16, 2019


Modern CMake

Modern CMake is about targets and properties and provides a model for creating re-usable software components easy integratable with each other. In order to fully benefit from this we re-wrote the old monolithic CMakeLists.txt to a series of smaller and easier to handle configuration files.

A minimum CMake version of 3.0 is required.

Using Git submodules

A number of software components are used by FABM, GOTM and GETM (and 3rd party software projects as well). Cross maintaining these components across different use cases has some times been a hassle and resulted in reduced progress. Utilising the Modern CMake principles and Git’s submodule facility we have now moved shared code componets out of GOTM.

So far - yaml, flexout and fabm are submodules in GOTM.

The submodules are full clones of the respective repositories - we have put the code in the extern folder in the GOTM root folder.

As a consequence of adding FABM as a submodule it is not necessery to specify FABM_BASE anymore.

GOTM code already cloned

From a users point of view we have made the transition very smooth and in general things should work just out of the box. There is one small caveat though - when updating the GOTM source code using git pull - an additional argument must be provided to also update the submodules.

git pull

becomes

git pull --recurse-submodules

Using the following setting:

git config  submodule.recurse true

git pull will in the future automatically also update the submodules.

During the update of the code a warning might be issued. The reason is that before the command to configure via CMake was e.g.:

cmake ~/GOTM/code/src

This has now been changed to:

cmake ~/GOTM/code

i.e. src/ is dropped and we are using CMakeLists.txt in the main GOTM folder.

It is possible to get rid of the warning by editing the CMakeCache.txt in the build directory as follows:

sed -i -e "s#/code/src#/code#" CMakeCache.txt

followed by:

cmake -c CMakeCache.txt

New GOTM clone

When making a new clone it is important to add options to inform Git about the submodules. This is done like:

git clone https://github.com/gotm-model/code.git
git submodule update --init --recursive

With git 1.7.3 and up the commands can be combined to one:

git clone --recurse-submodules https://github.com/gotm-model/code.git

When the code is cloned the instructions just given above can be used.