[CMake] Fortran 90 Module Issues in CMake

Brad King brad.king at kitware.com
Fri Mar 2 12:01:36 EST 2012


On 3/2/2012 10:28 AM, Matthew Schuchard wrote:
> That person also had an issue with one Fortran 90 file using a module built by another Fortran 90
> file in the same target and directory, and had the same error message from gnumake as I did.
> His solution was to manually add a dependency since in his case it appeared CMake missed it?

That was in a case involving circular dependencies among multiple static
libraries.  Dependencies are ill-defined in such cases so manual help
is needed.  The add_dependencies command only works across targets and
not within a single target so I do not think his trouble was within a
single target.

> Something that confuses me is:
>
>     1 INCLUDE_DIRECTORIES(${Library_MODDIR})
>
>     7 IF(CMAKE_Fortran_MODDIR_FLAG)
>     8   SET_TARGET_PROPERTIES(subdir_mods PROPERTIES
>     9     Fortran_MODULE_DIRECTORY modules
>    10     )
>    11 ENDIF(CMAKE_Fortran_MODDIR_FLAG)
>
> If a hardcoded directory "modules" is being specified as the output directory for modules built from
> a.f90 and b.f90 when the compiler supports a module output flag, why isn't "modules" in the include
> directories so that a.f90 can find B.mod?

One tells that specific target where to generate modules it provides.
The other says where to look for modules that it requires.  The two
sets may be disjoint so the interfaces for the two cases must be
orthogonal.

 > Or is "${Library_MODDIR}" an intrinsic CMake function which
> is assigned the local target's module output directory?

That variable is part of the test's own code.

> But this is not working for me.  I still have the error:
>
> *** No rule to make target `dir/CMakeFiles/target.a.dir/foo2.mod.stamp',
> needed by `dir/foo.tmp.f'.  Stop.

I can give you no additional help without a sample tarball that breaks.
Otherwise I cannot reproduce the problem.  The feature is implemented
and tested and works on every project I've ever seen.  If you cannot
post the real code then strip it down to a sanitized example and post
that instead.

-Brad


More information about the CMake mailing list