PROJECT(hello Fortran) CMAKE_MINIMUM_REQUIRED(VERSION 3.0) FILE(WRITE s1.f " PROGRAM Hello\n print *,'Hello World'\n END PROGRAM") ADD_CUSTOM_COMMAND( OUTPUT s1.copy.f DEPENDS s1.f COMMAND ${CMAKE_COMMAND} -E copy s1.f s1.copy.f ) ADD_CUSTOM_TARGET( copy DEPENDS s1.copy.f SOURCES s1.f ) ADD_EXECUTABLE(hello s1.f) ADD_DEPENDENCIES(hello copy)