Cookiecutter template for CMake based Fortran projects

In case somebody is interested, I’ve created a cookiecutter-template for creating fully featured Fortran projects with CMake build from scratch. Projects created with the template will automatically contain

  • a complete CMake setup for building, testing and installing the project,
  • separate CMake config file with user customizable options,
  • separate directories for the library source and the application which uses the library (similar to the directory structure the Fortran Package manager creates),
  • unit tests which can be automatically executed,
  • an integration test, which can check, whether the installed library and its CMake package file can be found and used by other CMake-based projects and
  • GitHub workflow instructions to execute all tests (unit tests, integration test) on Linux and Mac OS whenever you push a new commit to GitHub.

A version with Fypp-based preprocessing would follow later.

Of course, as the generated project is CMake based, it can not offer the simplicity of fpm based projects. Nevertheless, for those wishing to create CMake based Fortran projects, it could provide a good start.

7 Likes

How does this project compare to the stdlib-cmake-template? Is there anything missing in either of the projects which could be improved by an exchange?

@awvwgk Good point. I’ve to admit, I’ve completely forgotten about the stdlib-cmake-template, sorry! The two approaches are very similar, which is maybe not too surprising, as they both basically offer the essence of the lessons learned in the same CMake based Fortran project project :wink:

The cookiecutter template still misses the submodule retrieval. I am thinking to set up a more general scheme without the necessity to include a separate finder for each project (which we then can of course include in the stdlib-cmake-template as well). Otherwise, there are will be no big differences, I guess.

I personally find it more comfortable to answer a few questions and then obtain an appropriate project skeleton (as in the cookiecutter approach) than cloning a repository and make some manipulation afterwards. But that is truly a matter of taste.