[CMake] A fortran 95 module dependency issue with CMake-2.4.3

Alan W. Irwin irwin at beluga.phys.uvic.ca
Thu Oct 26 18:38:43 EDT 2006


This is an edited version of a previous post I made on the subject of the
fortran 95 module dependency issue with CMake-2.4.3.  However, my previous
post was buried in another thread (in early September) and got no response
so I will try again.

Here are three files in a test source tree that constitute a complete test
example that demonstrates a fortran 95 module dependency issue with CMake.
Note the fortran source has no comments so this is a completely separate
issue from the the well-known comment-parsing problem for fortran (77) code.

***********cat CMakeLists.txt project(test)
# libraries are all shared by default
option(BUILD_SHARED_LIBS "Build shared libraries" ON)

enable_language(Fortran)
add_library(hello SHARED hello.f90)

add_executable(hello_program hello_program.f90)
target_link_libraries(hello_program hello)
***********
***********cat hello.f90 module hello_module
   interface hello_world
     module procedure hello_world
   end interface
   contains
   subroutine hello_world()
     write(*,*) 'Hello World!'
   end subroutine hello_world
end module hello_module
***********
***********use hello_module
call hello_world
end
***********

Here are the cmake and make results starting from an empty build tree.

cmake -DCMAKE_VERBOSE_MAKEFILE=ON ../test_cmake >& cmake.out
make >& make.out

**********cat cmake.out
-- Check for working C compiler: gcc
-- Check for working C compiler: gcc -- works
-- Check size of void*
-- Check size of void* - done
-- Check for working CXX compiler: c++
-- Check for working CXX compiler: c++ -- works
-- Check for working Fortran compiler: f95
-- Check for working Fortran compiler: f95 -- works
-- Checking whether f95 supports Fortran 90
-- Checking whether f95 supports Fortran 90 -- yes
-- Configuring done
-- Generating done
-- Build files have been written to: 
/home/software/plplot_cvs/HEAD/testbuild_dir
**********
**********cat make.out
/home/software/cmake/install/bin/cmake 
-H/home/software/plplot_cvs/HEAD/test_cmake 
-B/home/software/plplot_cvs/HEAD/testbuild_dir --check-build-system 
CMakeFiles/Makefile.cmake 0
/home/software/cmake/install/bin/cmake -E cmake_progress_start 
/home/software/plplot_cvs/HEAD/testbuild_dir/CMakeFiles 2
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/home/software/plplot_cvs/HEAD/testbuild_dir'
make -f CMakeFiles/hello.dir/build.make CMakeFiles/hello.dir/depend
make[2]: Entering directory `/home/software/plplot_cvs/HEAD/testbuild_dir'
Scanning dependencies of target hello
cd /home/software/plplot_cvs/HEAD/testbuild_dir && 
/home/software/cmake/install/bin/cmake -E cmake_depends "Unix Makefiles" 
/home/software/plplot_cvs/HEAD/test_cmake 
/home/software/plplot_cvs/HEAD/test_cmake 
/home/software/plplot_cvs/HEAD/testbuild_dir 
/home/software/plplot_cvs/HEAD/testbuild_dir 
/home/software/plplot_cvs/HEAD/testbuild_dir/CMakeFiles/hello.dir/DependInfo.cmake
make[2]: Leaving directory `/home/software/plplot_cvs/HEAD/testbuild_dir'
make -f CMakeFiles/hello.dir/build.make CMakeFiles/hello.dir/requires
make[2]: Entering directory `/home/software/plplot_cvs/HEAD/testbuild_dir'
make[2]: Nothing to be done for `CMakeFiles/hello.dir/requires'.
make[2]: Leaving directory `/home/software/plplot_cvs/HEAD/testbuild_dir'
make -f CMakeFiles/hello.dir/build.make CMakeFiles/hello.dir/build
make[2]: Entering directory `/home/software/plplot_cvs/HEAD/testbuild_dir'
/home/software/cmake/install/bin/cmake -E cmake_progress_report 
/home/software/plplot_cvs/HEAD/testbuild_dir/CMakeFiles 1
[ 50%] Building Fortran object CMakeFiles/hello.dir/hello.o
/usr/bin/f95  -o CMakeFiles/hello.dir/hello.o  -Dhello_EXPORTS   -fPIC   -c 
/home/software/plplot_cvs/HEAD/test_cmake/hello.f90
Linking Fortran shared library libhello.so
/home/software/cmake/install/bin/cmake -P 
CMakeFiles/hello.dir/cmake_clean_target.cmake
/home/software/cmake/install/bin/cmake -E cmake_link_script 
CMakeFiles/hello.dir/link.txt --verbose=1
/usr/bin/f95  -fPIC    -shared  -o libhello.so "CMakeFiles/hello.dir/hello.o" 
make[2]: Leaving directory `/home/software/plplot_cvs/HEAD/testbuild_dir'
/home/software/cmake/install/bin/cmake -E cmake_progress_report 
/home/software/plplot_cvs/HEAD/testbuild_dir/CMakeFiles  1
[ 50%] Built target hello
make -f CMakeFiles/hello_program.dir/build.make 
CMakeFiles/hello_program.dir/depend
make[2]: Entering directory `/home/software/plplot_cvs/HEAD/testbuild_dir'
Scanning dependencies of target hello_program
cd /home/software/plplot_cvs/HEAD/testbuild_dir && 
/home/software/cmake/install/bin/cmake -E cmake_depends "Unix Makefiles" 
/home/software/plplot_cvs/HEAD/test_cmake 
/home/software/plplot_cvs/HEAD/test_cmake 
/home/software/plplot_cvs/HEAD/testbuild_dir 
/home/software/plplot_cvs/HEAD/testbuild_dir 
/home/software/plplot_cvs/HEAD/testbuild_dir/CMakeFiles/hello_program.dir/DependInfo.cmake
make[2]: Leaving directory `/home/software/plplot_cvs/HEAD/testbuild_dir'
make -f CMakeFiles/hello_program.dir/build.make 
CMakeFiles/hello_program.dir/requires
make[2]: Entering directory `/home/software/plplot_cvs/HEAD/testbuild_dir'
make[2]: *** No rule to make target `hello_module.mod.proxy', needed by 
`CMakeFiles/hello_program.dir/hello_program.o.requires'.  Stop.
make[2]: Leaving directory `/home/software/plplot_cvs/HEAD/testbuild_dir'
make[1]: *** [CMakeFiles/hello_program.dir/all] Error 2
make[1]: Leaving directory `/home/software/plplot_cvs/HEAD/testbuild_dir'
make: *** [all] Error 2
**********

If you execute "touch hello_module.mod.proxy" before the make, the problem
goes away; make builds the hello and hello_program targets properly, and the
resulting hello_program executable works properly. Here is the build tree
after that workaround.

***********ls -l
total 64
-rw-r--r-- 1 software software 11681 2006-09-05 19:25 CMakeCache.txt
drwxr-xr-x 6 software software  4096 2006-09-05 19:25 CMakeFiles/
-rw-r--r-- 1 software software  4873 2006-09-05 19:25 Makefile
-rw-r--r-- 1 software software   534 2006-09-05 19:25 cmake.out
-rw-r--r-- 1 software software  1448 2006-09-05 19:25 cmake_install.cmake
-rw-r--r-- 1 software software   544 2006-09-05 19:25 hello_module.mod
-rw-r--r-- 1 software software     0 2006-09-05 19:25 hello_module.mod.proxy
-rwxr-xr-x 1 software software  7669 2006-09-05 19:25 hello_program*
-rwxr-xr-x 1 software software  6261 2006-09-05 19:25 libhello.so*
-rw-r--r-- 1 software software  4548 2006-09-05 19:25 make.out
-rw-r--r-- 1 software software    22 2006-09-05 19:25 progress.make

Note, there is a real module file there called hello_module.mod that is
generated by the hello target build by the g95 (gfortran) compiler while the
empty hello_module.mod.proxy file was created by the touch command as a
workaround to satisfy the Makefile dependency.

This fortran 95 module dependency issue should be extremely easy for the
CMake developers to verify since only the three short files above are
necessary.

Could this issue please be fixed before 2.4.4?  For CMake-2.4.3 we work
around this issue for our fortran 95 code by creating files called
MODULENAME.mod.proxy with arbitrary contents, but that is really ugly
so we would like to dispense with the workaround ASAP.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the Yorick front-end to PLplot (yplot.sf.net); the
Loads of Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________
_______________________________________________
CMake mailing list
CMake at cmake.org
http://www.cmake.org/mailman/listinfo/cmake


More information about the CMake mailing list