CMake generate Fortran from template

CMake configure_file can serve to generate source code files including Fortran. For templates beyond a few lines of code, it may be useful to read the template from a file. This requires setting CMake directory property CMAKE_CONFIGURE_DEPENDS to have CMake regenerate the file if the template file changes as in the example below.

file(READ template_code)
configure_file( my.f90 @ONLY)


#example use
add_executable(main ${CMAKE_CURRENT_BINARY_DIR}/my.f90)