[CMake] Automatically Detecting Basic Fortran Dependencies

Brad King brad.king at kitware.com
Wed May 25 08:46:33 EDT 2011


On 05/25/2011 08:18 AM, sindimo at gmail.com wrote:
> I also like your suggestion of having all source files in one directory

They don't actually have to be in one directory.  You only need to name
them from one directory.  For example:

  add_executable(myMain
    exe/mymain.f90
    lib1/lib1.f90
    lib2/lib2.f90
    lib3/lib3.f90
  )

> and just build a giant target and let CMake figure out the dependencies
> within that target, I tried it with this simple example and it worked
> fine as well. I wonder if this approach has any drawbacks though?

If you want to build more than one executable that shares the same
libraries then it is better to build the individual libraries and
link to them from each executable.  Otherwise each source file will
compile separately for each executable.  In C this is just slower, but
in Fortran the .mod files might conflict.  If you're building exactly
one executable then the approach has no significant drawbacks, at
least of which I can think now.

-Brad


More information about the CMake mailing list