3

I am trying to configure a Fortran 2008 project to use CMake; the files in the project have the ".f08" extension. However, I cannot get CMake to work even with a "hello world" example. Here are the relevant parts of my CMakeLists.txt file:

cmake_minimum_required(VERSION 2.8)

project (hello)
enable_language (Fortran)

set (CMAKE_Fortran_SOURCE_FILE_EXTENSIONS ${CMAKE_Fortran_SOURCE_FILE_EXTENSIONS} "f08;F08")

add_executable ("hello-world" "hello-world.f08")
set_target_properties (hello-world PROPERTIES LINKER_LANGUAGE Fortran)

Three notes:

  1. The Makefile generated does not compile "hello-world.f08" into an object file.
  2. The "set_target_properties" is needed. Otherwise, CMake reports that it "can not determine linker language for target:hello-world".
  3. Renaming the file to "hello-world.f95" along with the corresponding change in CMakeLists.txt makes things work. Even the "set_target_properties" command is no longer needed.
  • 8
    Just give free form Fortran source files the `.f90` extension. Using the extension to indicate the language standard level is generally regarded as a mistake. – IanH Jul 28 '14 at 22:27
  • 1
    To add to @IanH some compilers will reject extension like .f08. In particular, `ifort` will complain with `ld:testf08.f08: file format not recognized; treating as linker script` and fail without even trying to compile. Use `.f90` and use your FFLAGS to put in the `-std=f2008`(gfortran) which will actually use the F2008 standard, unlike counting on the extension to do so. – casey Jul 29 '14 at 02:12
  • 2
    Do you rename all files every time you add a feature from a new standard? – Vladimir F Героям слава Jul 29 '14 at 06:38
  • Also see [How to use gfortran for .f90 file extension?](https://stackoverflow.com/q/40034609/608639), [How can gfortran tell if I am compiling f90 or f95 code?](https://stackoverflow.com/q/10884260/608639), [Makefile with different source types](https://stackoverflow.com/q/8940552/608639), [Correct suffix for Fortran 2003 source file - Intel Fortran compiler](https://stackoverflow.com/q/20269076/608639), etc. – jww Jun 12 '17 at 06:25

1 Answers1

2

If you need to specify Fortran files with unrecognized extensions, you can set the source file's LANGUAGE property, e.g.:

set_source_files_properties(hello-world.f08 PROPERTIES LANGUAGE Fortran)
Mike T
  • 41,085
  • 18
  • 152
  • 203