Fortran languages standards keep long backward compatibility (e.g Fortran 2018 allows Fortran 1958 fixed width format). Fortran compilers, like on C++, take years to add the full feature set, if ever. Automatically determining if a particular compiler supports a needed modern Fortran feature is very straightforward with CMake.
This particular example is for
CMakeLists.txt is below.
Unlike C++, we do not typically need to enable modern Fortran features with specific compiler flags.
The modern Fortran features are enabled by default across all commonly used Fortran compilers including:
- …and more
cmake_minimum_required(VERSION 3.1) project(es Fortran) include(CheckFortranSourceCompiles) check_fortran_source_compiles("program es; error stop; end" f2008 SRC_EXT f90) if(f2008) add_executable(myprog myprog.f90) endif()