[CMake] Dependency on library in a separate branch

Michael Hertling mhertling at online.de
Mon Jun 27 02:04:11 EDT 2011


On 06/27/2011 12:43 AM, Klaim - Joël Lamotte wrote:
> 2011/6/26 David Cole <david.cole at kitware.com>
> 
>> In your top level CMakeLists.txt:
>>
>> add_subdirectory(B)
>> add_subdirectory(A)
>> add_subdirectory(C)
>>
>> A & C must come after B since they both depend on B.
>>
>> Does that help?
>>
>>
> Thanks for your answer. It don't seem so, but let me explain you the full
> context:
> 
> in the root directory I have
> 
> add_subdirectory( tools )
> 
> 
> in the tools directory i have
> 
> add_subdirectory(B)
> add_subdirectory(A)
> 
> I suppose I already thought that there was some kind of order in dependency
> declaration, so it looks like the same you tell me, but to be complete:
> 
> In directory A I have the CMakeLists.txt file to define the executable A, no
> add_subdirectory().
> In directory B I have the CMakeLists.txt file to define the library B, with
> 
> add_subdirectory(C)
> 
> So it seems that your suggestion don't work but the difference remains in
> the tree structure so I'm not sure what is impacted.
> Maybe I did something wrong somewhere else.
> 
> The full repostory is up to date now there:
> http://code.google.com/p/art-of-sequence/source/browse/
> In tools directory, project A is aosdesigner, project B is aoslcpp, project
> C is the test project under aoslcpp.
> 
> I feel really dumb, I'm sure it's obvious but can't find why it don't work
> with aosdesigner project that now requires aoslcpp....

With the directory structure

/myrepo/tools/aosdesigner
/myrepo/tools/aoslcpp
/myrepo/tools/aoslcpp/test

aosdesigner must be informed about aoslcpp's include directory because
it is not inherited by aosdesigner as it is inherited by aoslcpp/test
since the latter is entered after aoslcpp issued INCLUDE_DIRECTORIES().
Include directories have directory scope whereas regular targets are
global, so you can refer to aoslcpp from aosdesigner's CMakeLists.txt
although the aoslcpp target has been defined in a sibling directory
next to aosdesigner's one, but the same does not work for include
directories. In aosdesigner's CMakeLists.txt, you should use

INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/tools/aoslcpp/include)

or

INCLUDE_DIRECTORIES(../aoslcpp/include)

to make aoslcpp's include directory available for aosdesigner. Note
that if aosdesigner also needs XSD, you should move FIND_PACKAGE(XSD)
to a higher-level CMakeLists.txt file, probably tools/CMakeLists.txt.

'hope that helps.

Regards,

Michael


More information about the CMake mailing list