Fortran extension: fpp ignored
I'm looking at a Fortran project (not mine) which uses mostly *.f90
files, and one .fpp
(via preprocessor) file which prevents the main executable from being compiled. The issues is that CMake does not seem to understand that the .fpp
file is a Fortran source file. A workaround is to rename the file with a .F
extension, and then the dependencies are correctly determined by CMake.
Here is a boiled down version of the issue I'm facing.
main.f90
program main
use MyMod
character(len=80) :: hello
call get_hello(hello)
write(*,*) hello
end program
mymod.fpp
(this is fixed format Fortran, with some dummy preprocessor blocks)
module MyMod
implicit none
public :: get_hello
contains
subroutine get_hello(txt)
character(len=80), intent(inout) :: txt
write(txt,'(a,5(1x,a),a)')
#ifdef __GFORTRAN__
2 'Hello gfortran'
#else
2 'Hello other'
#endif
return
end subroutine get_hello
end module MyMod
CMakeLists.txt
cmake_minimum_required(VERSION 2.6.0)
project(xyz Fortran)
add_executable(xyz main.f90 mymod.fpp)
$ cmake --version
cmake version 3.11.20180401-g323d6
...
$ cmake ..
...
$ cmake --build .
Scanning dependencies of target xyz
[ 50%] Building Fortran object CMakeFiles/xyz.dir/main.f90.o
/dir/to/src/main.f90:2:10:
use MyMod
1
Fatal Error: Can't open module file ‘mymod.mod’ for reading at (1): No such file or directory
compilation terminated.
CMakeFiles/xyz.dir/build.make:62: recipe for target 'CMakeFiles/xyz.dir/main.f90.o' failed
make[2]: *** [CMakeFiles/xyz.dir/main.f90.o] Error 1
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/xyz.dir/all' failed
make[1]: *** [CMakeFiles/xyz.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
the workaround for this example is to mv mymod.fpp mymod.F
and edit CMakeLists.txt
, then the example builds successfully. Any other workarounds or fixes are most welcome!