[CMake] add_dependencies with an imported target

Brad King brad.king at kitware.com
Thu Mar 5 13:00:34 EST 2009


Joachim de Vries wrote:
> CMake version 2.7-20080708
> 
> Mac OSX 10.5
> XCode 3.0
> 
> I have a problem with add_dependencies.
> 
> If I add an imported static lib like this:
> add_library("mylib" STATIC IMPORTED)
> 
> and try to add a dependency to this target on another target like this:
> 
> add_dependencies(myapp "mylib")
> 
> I get the following error:
> CMake Error: Unknown Target referenced : mylib
> CMake Error: Target: myapp depends on unknown target: mylib
> 
> Is it not possible to add imported targets to dependency list?

The add_dependencies command controls the order in which targets in the project
build.  There is no need to enforce that myapp builds after mylib because mylib
is imported and therefore is already built.

If you want to *link* to mylib, use

   target_link_libraries(myapp mylib)

-Brad


More information about the CMake mailing list