The following issue has been SUBMITTED.
==
http://www.vtk.org/Bug/view.php?id=12215
==
Reported By:Mohamad Sindi
Assigned To:
==
Project:CMake
Issue ID: 12215
Category: CMake
Reproducibility:always
Severity: major
Priority: normal
Status: new
==
Date Submitted: 2011-05-23 13:54 AST
Last Modified: 2011-05-23 13:54 AST
==
Summary:CMake Not Detecting Basic Fortran Dependencies
Description:
I have the below directory structure for Fortran code which has very basic
dependencies, yet CMake seems to fail to recognize the dependencies:
src/
CMakeLists.txt
lib1/CMakeLists.txt
lib1/lib1.f
lib2/CMakeLists.txt
lib2/lib2.f
lib3/CMakeLists.txt
lib3/lib3.f
main/CMakeLists.txt
main/myMain.f
Dependencies are:
myMain uses lib3
lib3 uses lib2
lib2 uses lib1
My top directory CMakeLists.txt looks like this:
[sindimo@lnx src]$ cat CMakeLists.txt
CMAKE_MINIMUM_REQUIRED (VERSION 2.8)
PROJECT(Fortran-Example-Dependency-Failure Fortran)
INCLUDE_DIRECTORIES(/workspace/Fortran-Example-Dependency-Failure/obj/linux_gnu_release_64-bit)
set (EXECUTABLE_OUTPUT_PATH
"/workspace/Fortran-Example-Dependency-Failure/bin/linux_gnu_release_64-bit")
set (LIBRARY_OUTPUT_PATH
"/workspace/Fortran-Example-Dependency-Failure/obj/linux_gnu_release_64-bit")
set (CMAKE_Fortran_MODULE_DIRECTORY
"/workspace/Fortran-Example-Dependency-Failure/obj/linux_gnu_release_64-bit")
ADD_SUBDIRECTORY(lib3)
ADD_SUBDIRECTORY(lib2)
ADD_SUBDIRECTORY(lib1)
ADD_SUBDIRECTORY(main)
The subdirectory CMakeLists.txt files look like:
[sindimo@lnx src]$ cat lib1/CMakeLists.txt
ADD_LIBRARY(lib1 SHARED lib1.f)
[sindimo@lnx src]$ cat lib2/CMakeLists.txt
ADD_LIBRARY(lib2 SHARED lib2.f)
[sindimo@lnx src]$ cat lib3/CMakeLists.txt
ADD_LIBRARY(lib3 SHARED lib3.f)
[sindimo@lnx src]$ cat main/CMakeLists.txt
ADD_EXECUTABLE(Fortran-Example-Dependency-Failure.exe myMain.f)
TARGET_LINK_LIBRARIES(Fortran-Example-Dependency-Failure.exe lib1 lib2 lib3)
When I run cmake followed by make I get the below error which apparently seems
to be due to CMake not figuring out the correct dependencies in Fortran and
doing the wrong build sequence:
[sindimo@lnx build_linux_gnu_release_64-bit]$ cmake ../src
-- The CXX compiler identification is GNU
-- The Fortran compiler identification is GNU
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working Fortran compiler: /usr/bin/gfortran
-- Check for working Fortran compiler: /usr/bin/gfortran -- works
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Checking whether /usr/bin/gfortran supports Fortran 90
-- Checking whether /usr/bin/gfortran supports Fortran 90 -- yes
-- Configuring done
-- Generating done
-- Build files have been written to:
/workspace/Fortran-Example-Dependency-Failure/build_linux_gnu_release_64-bit
[sindimo@lnx build_linux_gnu_release_64-bit]$ make
Scanning dependencies of target lib3
[ 25%] Building Fortran object lib3/CMakeFiles/lib3.dir/lib3.f.o
In file /workspace/Fortran-Example-Dependency-Failure/src/lib3/lib3.f:6
use m_lib2
1
Fatal Error: Can't open module file 'm_lib2.mod' for reading at (1): No such
file or directory
make[2]: *** [lib3/CMakeFiles/lib3.dir/lib3.f.o] Error 1
make[1]: *** [lib3/CMakeFiles/lib3.dir/all] Error 2
make: *** [all] Error 2
To my understanding CMake should be able to handle such simple Fortran
dependencies (as I recall, it uses similar intelligence to that of makedepf90),
am I doing something wrong here or is this considered too complicated of a
Fortran dependency for CMake to handle?
As a work around, if I add the below dependency statements manually to the top
level CMakeLists.txt file, things go well:
ADD_DEPENDENCIES(lib2 lib1)
ADD_DEPENDENCIES(lib3 lib2)
Also if I sort the ADD_SUBDIRECTORY commands in the correct build sequence, that
obviously solves the problem as well.
However our actual application that we need to use CMake with consists of
hundreds of libraries, so adding these dependencies manually or sorting them in
the correct build sequence is not feasible.
The "Mastering CMake" 4th edition book mentions an "output_required_files"
command which should take a source file and