cmake, fortran 2008, and .f08 file extension
Asked Answered
L

2

4

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.
Lionfish answered 28/7, 2014 at 21:56 Comment(4)
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.Penile
To add to @Penile 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.Dulci
Do you rename all files every time you add a feature from a new standard?Dambro
Also see How to use gfortran for .f90 file extension?, How can gfortran tell if I am compiling f90 or f95 code?, Makefile with different source types, Correct suffix for Fortran 2003 source file - Intel Fortran compiler, etc.Lorollas
P
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)
Polky answered 3/4, 2018 at 10:1 Comment(0)
H
0

You can use

ifx /extfor:f08 /free main.f08

Since ifort is now deprecated i used ifx.

But using /extfor:f08 /free compiler option is a non-standard way.

Horsemanship answered 21/11, 2023 at 14:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.