[CMake] How to handle COMPONENT arguments to find_package in my Config file?
Stephen Kelly
steveire at gmail.com
Wed Jun 22 13:08:38 EDT 2011
Clinton Stimpson wrote:
> On Wednesday, June 22, 2011 10:01:37 am Stephen Kelly wrote:
>> Hi,
>>
>> In my GrantleeConfigVersion.cmake.in I can use ${PACKAGE_FIND_VERSION}
>> which I presume is filled from the find_package command (I just copied
>> the file from elsewhere).
>>
>> Is there an equivalent for COMPONENTS so that if someone does a
>>
>> find_package(Grantlee COMPONENTS Foo Bar)
>>
>> my config file would do something like:
>>
>> if (${PACKAGE_FIND_COMPONENTS} CONTAINS "Foo")
>> # Find the dependencies of Foo
>> endif()
>>
>> if (${PACKAGE_FIND_COMPONENTS} CONTAINS "Bar")
>> # Find the dependencies of Bar
>> endif()
>>
>
> You can use Grantlee_FIND_COMPONENTS which would contain the components
> passed in by the user.
>
> Here's an example of using it:
>
> ...
> # the Grantlee exports file to accompany this config auto generated by
> # cmake's export() if this config is used in the build tree,
> # or install(EXPORT ...) if used in the installation tree
> SET(GrantleeExportsFile "@GrantleeExportsFile@")
> ...
>
> include("${GrantleeExportsFile}")
>
> # check that the user requested components
> # are actually targets that are part of this build
> IF( Grantlee_FIND_COMPONENTS )
> FOREACH(comp ${Grantlee_FIND_COMPONENTS})
> if(NOT TARGET ${comp})
> SET(Grantlee_${comp}_FOUND 0)
> IF(Grantlee_FIND_REQUIRED_${comp})
> MESSAGE(FATAL_ERROR "Grantlee ${comp} not available.")
> ENDIF()
> ELSE()
> SET(Grantlee_${comp}_FOUND 1)
> ENDIF()
> ENDFOREACH()
> ENDIF()
>
Thanks, this looks like what I need alright.
Steve.
More information about the CMake
mailing list