[cmake-developers] Adding automatic checks for required targets in target-export files ?

Alexander Neundorf neundorf at kde.org
Mon Feb 11 12:32:29 EST 2013


On Monday 11 February 2013, Brad King wrote:
> On 02/10/2013 10:14 AM, Alexander Neundorf wrote:
> > 1) either put a check for the required targets in the generated targets
> > file, and make find_package() fail by setting foo_FOUND to FALSE. This
> > should be relatively straightforward to implement, and needs only code
> > in the generated targets file. This is good.
> 
> I like this approach better than the second one also.
> 
> > On the downside, this will probably make the cmake
> > run fail for (some ?) projects where it currently succeeds, although they
> > do not take the dependency order into account when searching packages.
> 
> I think we can add a policy for this.  If not set, warn and use OLD.
> If OLD, silently accept the missing targets.  If NEW, error.

So the exported targets file should do something like the following ?

set(failWithError FALSE)
cmake_policy(GET CMP00xy POLICY_SET_TO_NEW)
if("${POLICY_SET_TO_NEW}" STREQUAL "NEW")
   set(Foo_FOUND FALSE);
   set(Foo_NOT_FOUND_MESSAGE "Foo not found because some target is missing")
else()
   message(STATUS "Foo may not work because some imported target is
                   currently still missing")
endif()

 
Alex



More information about the cmake-developers mailing list