cmake, fortran 2008, and .f08 file extension

2019-01-20 05:28发布

问题:

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.

回答1:

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)


标签: cmake fortran