problem with ninja generator and gfortran preprocessing (-cpp)
Please consider this simple test case:
Building this with cmake via
cmake .. -G Ninja
ninja -v
gives me:
[1/4] /usr/bin/f95 -cpp -cpp -E ../test.f90 -o CMakeFiles/exe.dir/test.f90-pp.f90 && /usr/local/bin/cmake -E cmake_ninja_depends --tdi=CMakeFiles/exe.dir/FortranDependInfo.json --pp=CMakeFiles/exe.dir/test.f90-pp.f90 --dep=CMakeFiles/exe.dir/test.f90-pp.f90.d --obj=CMakeFiles/exe.dir/test.f90.o --ddi=CMakeFiles/exe.dir/test.f90-pp.f90.ddi
[2/4] /usr/local/bin/cmake -E cmake_ninja_dyndep --tdi=CMakeFiles/exe.dir/FortranDependInfo.json --dd=CMakeFiles/exe.dir/Fortran.dd @CMakeFiles/exe.dir/Fortran.dd.rsp
[3/4] /usr/bin/f95 -I../ -cpp -fpreprocessed -c CMakeFiles/exe.dir/test.f90-pp.f90 -o CMakeFiles/exe.dir/test.f90.o
../test.f90:7:23:
! hello world, what's up?
^
Warning: missing terminating ' character
[4/4] : && /usr/bin/f95 -cpp CMakeFiles/exe.dir/test.f90.o -o exe && :
The bogus warning here is apparently due to the way that cmake handles preprocessing with the ninja generator (in two steps). Note that in [1/4] -cpp appears twice, while in [3/4] it should not be necessary any more (and the combination of -cpp -fpreprocessed
is problematic, I suppose).
Further note: If I remove the setting of CMAKE_Fortran_FLAGS, the example does not build with the Unix Makefiles generator, since gfortran does not preprocess .f90 files by default (only .F90). With the Ninja generator, it keeps on working, because the Ninja generator apparently preprocesses all Fortran files.
I was not fully sure if this is a bug of cmake, ninja or gfortran. But my guess is that cmake's handling of preprocessing with the ninja generator is the problem.