Ninja fortran preprocessing causes mis-reporting of error/warning locations
Here is a test case containing a simple fortran program with an error:
test.f90:
program test
implicit none
integer a
a = b
end program
CMakeLists.txt:
project(testProject Fortran)
add_executable(testProgram test.f90)
Building this project via
mkdir build && cd build
cmake -G Ninja ..
ninja
yields the following output:
[3/4] Building Fortran object CMakeFiles/testProgram.dir/test.f90.o
FAILED: CMakeFiles/testProgram.dir/test.f90.o
/usr/bin/gfortran -I../ -c CMakeFiles/testProgram.dir/test.f90-pp.f90 -o CMakeFiles/testProgram.dir/test.f90.o
CMakeFiles/testProgram.dir/test.f90-pp.f90:4:7:
# 1 "../test.f90"
1
Error: Symbol ‘b’ at (1) has no IMPLICIT type
ninja: build stopped: subcommand failed.
The error is on line 4 of the original test.f90
, but on line 8 of the preprocessed test-pp.f90
. Due to the preprocessing required by cmake/ninja, line 4 from test-pp.f90
is printed by gfortran to show the error.