BUG: Fortran "module integer function" syntax not recognized
I've created a small reproducing repo with simple Fortran files and a single CMakeLists.txt
for the issue I'm about to describe here: https://github.com/tylerjereddy/cmake_fortran_module_integer_function (feel free to duplicate/modify as needed for regression testing of course).
Short description to reproduce
- clone repo
mkdir build && cd build
- Use latest
master
branch of CMake built from source cmake -G Ninja ../
cmake --build .
- Repeat
cmake --build .
over and over again and the project will rebuild a bunch of stuff no matter how many times you repeat the build:[4/4] Linking Fortran executable main
Some more details
The team I'm supporting basically summarized this as CMake not recognizing the module integer function
syntax and what you end up with is a spurious module entry in the .ddi
file (providing an integer
module that doesn't exist I suppose):
{
"revision" : 0,
"rules" :
[
{
"outputs" : [],
"primary-output" : "CMakeFiles/my_lib.dir/problem.f90.o",
"provides" :
[
{
"compiled-module-path" : "integer.mod",
"logical-name" : "integer.mod"
},
{
"compiled-module-path" : "parent.mod",
"logical-name" : "parent.mod"
}
],
"requires" : []
}
],
"version" : 0
Of course, you could circumvent this by only using a subset of valid Fortran, but ideally it would be great if we don't have to police the use of Fortran syntax that is typically accepted by the compiler, without even a warning.
diff --git a/problem.f90 b/problem.f90
index 49a6e2c..dc518e9 100644
--- a/problem.f90
+++ b/problem.f90
@@ -1,11 +1,11 @@
module parent
implicit none
interface
- module integer function myfunction()
+ integer module function myfunction()
end function myfunction
end interface
contains
- module integer function myfunction()
+ integer module function myfunction()
integer :: myfunction
myfunction = 0
end function myfunction
I looked into providing a sample patch myself, but it looks like I'd need to be able to understand C++ a fair bit to deal with the lexer/built-in Fortran parser.
I did note that you have a very similar regression test in Tests/FortranModules/Submodules/parent.f90
, and in the commit that was added these files were also modified:
Source/LexerParser/cmFortranParser.cxx
Source/LexerParser/cmFortranParser.y
Source/cmDependsFortran.cxx
Source/cmFortranParser.h
Source/cmFortranParserImpl.cxx
Those look a bit tricky to patch, so I'd need guidance if you want me to try.