[CMake] Fortran project directory stucture/layout advice

Zaak Beekman zbeekman at gmail.com
Tue Jun 11 12:11:26 EDT 2013


So this question is not 100% about cmake, but I am going to ask anyway.
What is a good project layout (for a CMake project) that will let me:

a) group related components
b) allow testing and building of individual components
c) without causing maintenance/debugging headaches, and having to update
duplicate information in CMakeLists files when something changes.

This last point is what I'm most concerned about, regarding my current
setup. I am writing a set of codes/libraries in Fortran. Right now, the
source all lives in in sub-directories under a top level source directory,
and there are dependencies between the different sub-directories. Each
sub-directory's CMakeLists.txt file defines it's own project that can be
built/tested to test that component, or if the entire project is to be
built, this is facilitated by the top level CMakeLists.txt file which
defines the master project and then uses add_subdirectory to add the
component directories.

Right now when one target in a sub-directory depends on files in another
(including Fortran modules which produce the awkward .mod files) I am
simply just adding the relative path to that file as a source dependency
when I add the target, which seems fragile to me, and will likely result in
such files being compiled multiple times when called from the top level
(i.e. complete project) CMakeLists.txt.

Is there a better way to accomplish this? Perhaps by building and linking
against a library for each sub-directory? How would I access the interface
information in the .mod files associated with a library built in one
sub-directory from another? Maybe I should just add_subdirectory the
dependency if the current CMakeLists.txt is the top level file. Or just
switch to a large but flat source file structure and say to heck with
considerations a) and b) above?

Any best-practices, or guidance from those more experienced than I am is
very very welcome.

-Zaak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130611/4f645991/attachment.htm>


More information about the CMake mailing list