[CMake] Build tree with common dependency - CMP-0002

Frank Gruman fgatwork at verizon.net
Fri Aug 6 15:27:26 EDT 2010


On Fri, 2010-08-06 at 08:56 -0700, Tyler Roscoe wrote:
> On Thu, Aug 05, 2010 at 09:26:05PM -0500, Frank Gruman wrote:
> > The problem - dependencies.  Each build is supposed to be independent
> > of any other. Soooo:
> > 
> > Build Project A-1
> >     Depends on B-1
> >         Depends on C-3
> > 
> > Build Project A-2
> >     Depends on B-3
> >         Depends on C-3
> > 
> > Build Project A-3
> >     Depends on A-1
> >     Depends on A-2
> > 
> > I cannot figure out how to prevent CMP-0002 errors on target C-3 when
> > trying to build A-3 (without first having to run a separate build of
> > C-3 prior to running any of them).
> > 
> > Here is a snippet of how I am loading the C-3 library in B-1 and B-3:
> > 
> > find_library(PLATFORM_LIB Platform ${CMAKE_BINARY_DIR}/../lib/$ENV{PLATFORM_NAME} )
> > 
> > if (NOT EXISTS ${PLATFORM_LIB})
> > 	message(STATUS "Platform library does not exist.  Adding source build.")
> > 	add_subdirectory( ${CMAKE_BINARY_DIR}/../source/n2ksdk/platform ${CMAKE_BINARY_DIR}/../buildPlatform )
> > endif (NOT EXISTS ${PLATFORM_LIB})
> 
> You're checking if your library exists as a file on disk. At CMake time,
> this will rarely be true, as you haven't built that library yet.
> 
> Instead, you should check for the existence of the CMake target that
> will cause the library to be built at compile time. You can do this with
> if (TARGET <targetname>).
> 
> tyler

Cool - hadn't seen that trick in the docs.  That works _GREAT!_  

I resolved the issue by wrapping my Platform add_library(Platform
blah_sources) and the accompanying install(TARGETS...) in an if(NOT
TARGET Platform)/endif so that the target only gets added to the build
tree once.  WOOT!  

At this point, I have projects with up to 22 dependent build projects
building without much of a hitch.  It's a little ugly, but it works.
Going to start cleaning them up, now.

Thanks!
Frank




More information about the CMake mailing list