[CMake] No rule to build mod file

Alain Miniussi alain.miniussi at oca.eu
Wed Dec 10 07:49:29 EST 2014


Hi,

I am experiencing a problem related with dependencies on fortran mod 
files. Basically, the "make -j" it's failing with:
make[2]: *** No rule to make target `dsfdm3d/inc/modacqui.mod', needed 
by `dsfdm3d/src/CMakeFiles/dsfdm_sp-exe.dir/main.f90.o'. Stop.


mod file are generated as a side effect of source file compilation, so a 
file A.f90 using a mod B.mod must be compiled after the file producing 
the module (say B.f90).

cmake seems to be able to convert those constraints in terms of build 
order (that is, B.f90 will be compiled before A.f90) and insert a 
dependency from A.f90 to B.mod. But sinces there are no specific rule to 
build B.mod, a full parallel build will fail on the dependencies.
That is, before building anything, make will detect that A.f90 depends 
on a non existing file (yet) and fail to see that the compilation of 
B.f90 would have produced the file.

  For some reason, the problem seems to appears only if I build an 
executable (from A.f90) and have many files suc a B.f90 used to build a 
library.
  When building with a simple 'make' everything is okay (I guess because 
the build order is good), the problem only appears with "make -j".

I have the problem with cmake  3.1.0-rc1 and 2.8.12.2

the CMakeLists.txt looks like:

add_library(somelib OBJECT
  [some 52 source files>.f90
   )

set_target_properties(somelib PROPERTIES Fortran_MODULE_DIRECTORY 
"${CMAKE_CURRENT_BINARY_DIR}/../inc")
set_target_properties(somelib PROPERTIES COMPILE_FLAGS "<compile flags>")

add_executable(exe main.f90 $<TARGET_OBJECTS:somelib>)
set_target_properties(exe PROPERTIES COMPILE_FLAGS "<compile flags>")


add_dependencies(exe somelib)

Is this something expected ?

Thanks



More information about the CMake mailing list