we have a problem with debugging Fortran code, because the source code reference in the object file is not set correctly. Find below a minimal example to reproduce the problem.
Apparently, during preprocessing of a source file with the Intel compiler the result is written to the terminal and then redirected into a subfolder. This behavior is defined in CMAKE_Fortran_PREPROCESS_SOURCE (more precisely, here: -E > <PREPROCESSED_SOURCE>). The preprocessed file contains a reference to the source file in the first line comment (# 1 “…\main.f” in the minimal example), which is used by the Intel compiler to create the reference in the object file. But since the preprocessed file is shifted into a subfolder, the relative path becomes outdated and in the object file we get an invalid path (CMakeFiles\hello_world_fortran.dir…\main.f in the minimal example).
We use Ninja version 1.9.0, CMake version 3.19.3, IFort version 19.1.1.216, and Fortran 77.
Any help to fix the problem and suggestions, how to circumvent it for the moment is appreciated. If you need additional information, I will be happy to provide.
Thanks in advance
Andreas
Since I cannot upload attachments here is the minimal example in text form: main.f
PROGRAM HELLO
C
C The typical hello world program
C
WRITE (,) ‘Hello World!’
END
CMakeLists.txt
set ( CMAKE_MAKE_PROGRAM “N:/software/ninja-build/ninja/v1.9.0/WINDOWS64/ninja.exe” )
set ( CMAKE_Fortran_COMPILER “C:/Program\ Files\ (x86)/IntelSWTools/compilers_and_libraries_2020.1.216/windows/bin/intel64/ifort.exe” )
set ( CMAKE_Fortran_COMPILER_FORCED TRUE )
Adapt the Fortran file to fixed format (the white spaces do not show here in the forum), so add 6 white spaces at the beginning of each non-comment line.
Adapt the path to the Fortran Compiler and to Ninja in CMakeLists.txt
Run CMake
cmake -DCMAKE_BUILD_TYPE=Debug -G Ninja …
Build
ninja -v all
THE PROBLEM
Open CMakeFiles\hello_world_fortran.dir\main.f.obj in a text editor. Here, you see the source path ‘CMakeFiles\hello_world_fortran.dir…\main.f’.
This path is wrong and therefore debug source information in Fortran code is not accessible.
FURTHER INFORMATION
Open CMakeFiles\hello_world_fortran.dir\main.f-pp.f.
In the first line is a relative path to the source, which is used by IFort to produce the wrong path in the object file.
Looking at the preprocessing step or rather the corresponding CMake variable: CMAKE_Fortran_PREPROCESS_SOURCE <CMAKE_Fortran_COMPILER> -fpp -E > <PREPROCESSED_SOURCE>
With -E you get terminal output of the preprocessed file. This output then is directed into PREPROCESSED_SOURCE in a subfolder, which breaks the relative path.
We use Ninja version 1.9.0, CMake version 3.19.3, and IFort version 19.1.1.216.
Thanks for the report. There is now support for skipping the preprocessing step if that is suitable for you. It was added in CMake 3.18 and you can set it at the target level or per-source file if one is more appropriate.
In the meantime, this should probably be addressed since there are files which do require preprocessing. Could you please file an issue for this?