[CMake] build directories, subdirs and lib dependencies

Brad King brad.king at kitware.com
Mon Jan 3 11:35:01 EST 2005


Nick Arini wrote:
> I have a source directory structure with a root directory containing a 
> top level CMakeLists.txt file and some code to build a front end 
> executable. I also have a couple of sub directories which contain 
> libraries which are required to link to the executable in the top level 
> directory for the program to function correctly. I would like to step 
> into each of these subdirs in turn (the libraries themselves have 
> interdependencies) and build each library then build the front end 
> executable and link the libraries.
> 
> In my top level CMakeLists.txt file I first step into the subdirs for 
> each library in turn:
[snip]
> How do I get CMake to build the libraries first then link to the 
> executable (in actual fact if you ignor the error and build anyway it 
> does the right thing!)?

The make system generated by CMake does a pre-order traversal, so 
directories can depend on their parents and earlier siblings, but not on 
their children.  This was chosen so that test executables could be in 
subdirectories below the libraries they test.  It is a known limitation 
and will eventually be fixed.  For now you can put the executable in a 
subdirectory:

SUBDIRS(LibDir1 LibDir2 ExeDir)

-Brad


More information about the CMake mailing list