CMake builds for modern Fortran

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 CMake example is for error stop. Unlike C++, we do not typically need to enable modern Fortran features with specific compiler flags. Modern Fortran features are typically enabled by default.

include(CheckSourceCompiles)

set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
# save link time, only compile is needed

check_source_compiles(Fortran "program test
error stop
end" f08errorstop)

if(f08errorstop)
  ...
endif()

Fortran submodule is supported by CMake.