<div dir="ltr"><div><div><div>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:<br><br>a) group related components<br>b) allow testing and building of individual components<br>

c) without causing maintenance/debugging headaches, and having to update duplicate information in CMakeLists files when something changes.<br><br>This last point is what I&#39;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&#39;s CMakeLists.txt file defines it&#39;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.<br>

<br></div>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.<br>

<br></div>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?<br>

<br></div>Any best-practices, or guidance from those more experienced than I am is very very welcome.<br><div><br><div><div><div><div><div><div><div><div>-Zaak<br></div>


</div></div></div></div></div></div></div></div></div>