[CMake] Testing for a Target

Alexander Neundorf a.neundorf-work at gmx.net
Thu Nov 27 15:27:47 EST 2008


On Wednesday 26 November 2008, Michael Jackson wrote:
> On Nov 26, 2008, at 4:34 PM, Eric Noulard wrote:
> > 2008/11/26 Michael Jackson <mike.jackson at bluequartz.net>:
> >> Is there a way to actually test to see if a target exists or has been
> >> created?
> >>
> >> I am working on the boost-cmake stuff and I would to implement a
> >> macro that
> >> takes in requirements for a target (regression test). As it checks
> >> those
> >> requirements the macro will need to check to see if one of its
> >> dependencies
> >> has already been created. For example say I have a regression test
> >> Foo and
> >> it depends on a static-multi_threaded-debug build of the boost_system
> >> library.
> >>  Now say the user has selected to NOT build static libraries. I
> >> need to
> >> check for the boost-system-static-multi-debug target and if it does
> >> not
> >> exists (which it will not in our example) add that target.
> >>
> >> Alternatively, what happens if I just add a new target and the new
> >> target
> >> already actually exists? Is that safe?
> >
> > Did you try
> > if(TARGET target-name)
> >
> > cf
> >
> > cmake --help-command if
> > --
> > Erk
>
> let me pull my head out of my ... thanks.. ;-O

That's new since I think 2.6.2, with older versions you can do 
get_target_property( ... TYPE )
This will return NOTFOUND if the target hasn't been created before.

Alex


More information about the CMake mailing list