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

Brad King brad.king at kitware.com
Mon Feb 11 12:57:53 EST 2013


On 02/11/2013 12:32 PM, Alexander Neundorf wrote:
> 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()

In order to make sure it (silently) works in older CMake versions
and that there is no warning for OLD behavior:

if(POLICY CMP00xy)
  cmake_policy(GET CMP00xy cmp00xy)
  if("${cmp00xy}" STREQUAL "NEW")
     set(Foo_FOUND FALSE)
     set(Foo_NOT_FOUND_MESSAGE "Foo not found because some target is missing")
  elseif(NOT "${cmp00xy}" STREQUAL "OLD")
     message(STATUS "Foo may not work because some imported target is
                     currently still missing")
  endif()
endif()

-Brad



More information about the cmake-developers mailing list