[Cmake] Problems with Library Dependencies

Brad King brad.king at kitware.com
Tue, 06 Apr 2004 12:50:37 -0400


Rainer Michael Schmid wrote:
>> CMake only depends on libraries that it can build.   You can
>> link other libraries, but right now it does not depend on them.
>> So, if there is not an ADD_LIBRARY in the project, the library
>> will not be in the DEPEND_LIBS.
> 
> 
> This reminds me of a problem I currently have -- actually, my problem is 
> unrelated to this one, but I had to think of it...
> 
> I have a directory "autotest" with the subdirectories "node" and 
> "parser". In the subdirectories "node" and "parser" I build static 
> libraries. The "autotest" directory also builds the executable.
> 
> So the CMakeLists.txt in "autotest" contains (among others):
> 
> SUBDIRS(node parser)
> LINK_LIBRARIES(node parser)
> ADD_EXECUTABLE(autotest  main.cpp)
> 
> The "autotest_DEPEND_LIBS" contain the right libraries. But if I change 
> something that rebuilds the "node" library, I need to runs of "make" to 
> get not only the library rebuilt, but also to relink the "autotest" 
> executable.
> 
> Is it correct that the problem is that make calculates the dependencies 
> for the "Makefile" in "autotest" before it goes into the subdirectories?
> 
> Is there a way to control this or do I have to create a dummy directory 
> with an extra "CMakeLists.txt" that builds the executable and the 
> "CMakeLists.txt" in "autotest" contains only SUBDIRS()?

Currently subdirectories can depend on parent directories, but not the 
other way around.  If you create a third directory for executables it 
will solve your problem.  Our convention has been to have test 
executables built in directories beneath the directories containing the 
library they test.  We also tend to put non-test (production) 
executables in the same directory as the library or in a sibling 
directory listed later by a higher SUBDIRS command.

-Brad