CMake builds for modern Fortran 2008 / 2018

Fortran languages standards keep long backward compatibility. Fortran 2018 finally deprecated Fortran 1958 fixed width format. In general across languages, compiler vendors take years to add the full language feature set. Automatically determining if a particular compiler supports a needed modern Fortran feature is straightforward with CMake (and Meson).

This particular example is for Fortran 2008 error stop.

Example CMakeLists.txt is below. Unlike C++, we do not typically need to enable modern Fortran features with specific compiler flags. Modern Fortran features are typically enabled by default.


check_fortran_source_compiles("error stop; end" f08errorstop
                              SRC_EXT f90)



Fortran 2008 submodule support was added in CMake 3.12. CMake 3.14 added check_fortran_source_runs().