[cmake-developers] Generating guards around add_library(... IMPORTED)

Alexander Neundorf neundorf at kde.org
Sun Dec 16 10:58:15 EST 2012


On Friday 30 November 2012, Stephen Kelly wrote:
> Brad King wrote:
> > On 11/29/2012 02:22 PM, David Cole wrote:
> >> But with the multiple "OR" technique, if there is a single target name
> >> clash, NONE of the targets will be included properly
> > 
> > Good catch.  I read it as "AND", which it should be:
> >   if(TARGET a AND TARGET b AND ...)
> >   
> >     return()
> >   
> >   endif()
> 
> I've pushed an implementation of 'all or none or warning' to next as the
> branch safe-target-file-import.

we'll hit that case if a Config file for the same package has already been 
loaded in a project.
Typically a FooConfig.cmake file will have something like:

include("${CMAKE_CURRENT_LIST_DIR}/FooTargets.cmake")

With the return() in the FooTargets.cmake file, this included file will simply 
do nothing, and we'll stay with the "old" imported targets and their 
properties.
But the FooConfig.cmake file which has just been executed may set a bunch of 
variables, which would fit to the targets which now have not been imported, 
and which do not fit to the previuosly imported targets.

Should the FooConfig.cmake fail in this case ?
Probably not.
Should it silently do nothing at all ?
Or should it set the variables it wants to set but not touch the imported 
targets ?

I'm not sure what the best way is.
Comments ?

Alex



More information about the cmake-developers mailing list