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

Tyler Roscoe tyler at cryptio.net
Fri Aug 6 11:56:13 EDT 2010


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


More information about the CMake mailing list