<div dir="ltr">Dear Brad,<br><br>              Thanks for your thorough explanation, I wasn&#39;t aware that the dependency scanning only worked within a single target, it makes sense now.<br><br>Currently I am using a UNIX Make files for building but we&#39;re moving to CMake to have the application run on Windows as well. I have a python script that I feed Fortran files and it spits it out file dependencies (similar to what your  &quot;output_required_files&quot; command should do for C files). I tweaked it a bit and I got it to generate CMake ADD_DEPENDENCIES statements which I append to a file and then include that file in my main CMakeLists.txt file after adding the subdirectories. For the time being it&#39;s working fine.<br>
<br>I also like your suggestion of having all source files in one directory 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?<br>
<br>Thanks again for all of your help, I really appreciate it!<br><br>M. Sindi<br><br><br><br><div class="gmail_quote">On Tue, May 24, 2011 at 3:44 PM, Brad King <span dir="ltr">&lt;<a href="mailto:brad.king@kitware.com">brad.king@kitware.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im">On 5/23/2011 2:15 PM, <a href="mailto:sindimo@gmail.com">sindimo@gmail.com</a> wrote:<br>

&gt; I have the below directory structure for Fortran code which has very<br>
&gt; basic dependencies, I am not able to get CMake to recognize the<br>
&gt; dependencies automatically without me explicitly having to specify it<br>
&gt; using add_dependencies or target_link_libraries:<br>
<br>
</div>What documentation did you read that led you to believe CMake can<br>
find library link dependencies?  The problem is ill-defined in<br>
general because it is possible for two source files in the project<br>
to provide the same symbol.  If those sources go in different<br>
libraries then how can any tool possibly know which one the author<br>
intends to be used?<br>
<div class="im"><br>
&gt; To my understanding CMake should be able to handle such simple Fortran<br>
&gt; dependencies (as I recall, it uses similar intelligence to that of<br>
&gt; makedepf90 to detect dependencies), am I doing something wrong here?<br>
<br>
</div>CMake&#39;s dependency scanning picks up dependencies within a single<br>
target.  The scanning is purely for rebuilding when preprocessor<br>
dependencies change, and in the case of Fortran for ordering the<br>
build of object files *within* a target correctly to satisfy the<br>
module provider/user dependencies.<br>
<br>
CMake will also hook up cross-target F90 .mod dependencies but<br>
it will only look at the targets *linked* into the current target<br>
to satisfy those dependencies.<br>
<div class="im"><br>
&gt; If I add the below explicit dependency statements manually to the top<br>
&gt; level CMakeLists.txt file, things go well:<br>
&gt; ADD_DEPENDENCIES(lib2 lib1)<br>
&gt; ADD_DEPENDENCIES(lib3 lib2)<br>
<br>
</div>This is expected, but you should use<br>
<br>
  target_link_libraries(lib2 lib1)<br>
  target_link_libraries(lib3 lib2)<br>
<br>
instead.  This tells CMake that whenever something links to lib2<br>
it needs lib1 also, and similarly that lib3 needs lib2 at link<br>
time.  After expressing these link-time dependencies you can then<br>
link your executable with just<br>
<br>
  target_link_libraries(myMain lib3)<br>
<br>
to express that direct dependency.  The other lines above tell<br>
CMake to follow the dependencies transitively.<br>
<div class="im"><br>
&gt; Also if I sort the ADD_SUBDIRECTORY commands in the correct build<br>
&gt; sequence, that obviously solves the problem as well.<br>
<br>
</div>This might make it build the first time but it won&#39;t hook up the<br>
cross-target .mod dependencies correctly so that objects rebuild<br>
when their modules change.<br>
<div class="im"><br>
&gt; However our actual application that we need to use CMake with consists<br>
&gt; of hundreds of libraries, so adding these dependencies manually or<br>
&gt; sorting them in the correct build sequence is not feasible.<br>
<br>
</div>How are you building the application now?  Your current build<br>
system must know the link dependencies.  Alternatively, if you<br>
do not actually need the separate libraries you can just list<br>
all your source files in one giant target.  CMake does not care<br>
if the files lie in different directories.  Within the single<br>
target it will compute the correct order to build your object<br>
files.<br>
<font color="#888888"><br>
-Brad<br>
</font></blockquote></div><br></div>