Fortran: CMake 3.26.1 does not resolve module dependencies when scanning mutually-dependent static libraries
After the recent update to CMake version 3.26 (tested with both .0 and .1) our Fortran project started producing compile errors due to missing compiled module files. It seems that the issue is triggered by mutually-dependent static Fortran libraries, please see the following condensed reproducer:
cmake_minimum_required(VERSION 3.19)
project(p LANGUAGES Fortran)
file(WRITE A.f90
"subroutine A
end subroutine A")
add_library(liba STATIC A.f90)
target_link_libraries(liba PRIVATE libb)
file(WRITE B1.f90
"subroutine B1
use :: B2
end subroutine B1")
file(WRITE B2.f90
"module B2
end module B2")
add_library(libb STATIC B1.f90 B2.f90)
target_link_libraries(libb PRIVATE liba)
When trying to build this project with CMake 3.26.1 the following error is printed:
CMake Error: -E cmake_depends failed to open /scratch/build/CMakeFiles/liba.dir/fortran.internal for module information
but nevertheless the build proceeds and then fails when building libb
because of a missing module file. The same project builds just fine with CMake versions prior to 3.26.
Edited by Brad King