[CMake] COMPONENTS for export files
Nico Schlömer
nico.schloemer at gmail.com
Tue Apr 9 18:45:25 EDT 2013
Sounds pretty good!
One question remains:
Suppose I have components A, B, C, where both A and B depend on C.
The link line that I'd pull in with
FIND_PACKAGE(Mypackage COMPONENTS A B)
Would be
<A libs>, <C libs>, <B libs>, <C libs>
where all of those could be sets. Is there a way to avoid including
C's libs twice? (Is that desirable at all?)
--Nico
On Mon, Apr 8, 2013 at 6:09 PM, Alexander Neundorf
<a.neundorf-work at gmx.net> wrote:
> On Monday 08 April 2013, Nico Schlömer wrote:
>> Hi all,
>>
>> I have a software project that I build and install with CMake. For
>> others to link against the software project, I have a
>> "MypackageConfig.cmake.in" from which I create "MypackageConfig.cmake"
>> using CONFIGURE_PACKAGE_CONFIG_FILE(). Others can then invoke
>> FIND_PACKAGE(Mypackage) in their own CMake files. -- Nice.
>>
>> Now, the software breaks down into logical units, and it would make
>> sense for other users to be able for import it with the COMPONENTS
>> keyword, e.g.,
>>
>> FIND_PACKAGE(Mypackage COMPONENTS reader writer parser)
>>
>> Is there a recommended way of generating the package files such that
>> this syntax becomes applicable?
>
> You can export the targets into separate export sets, one for each component
> (since CMake 2.8.9 I think).
> In your Config.cmake file you can then check which components have been
> requested and include() the respective target-files.
> The requested components can be queried via Mypackage_FIND_COMPONENTS.
> This is from readme.txt:
>
> "Those components can be listed after the COMPONENTS (or REQUIRED)
> or OPTIONAL_COMPONENTS keywords. The set of all listed components will be
> specified in a XXX_FIND_COMPONENTS variable.
> For each package-specific component, say Yyy, a variable XXX_FIND_REQUIRED_Yyy
> will be set to true if it listed after COMPONENTS and it will be set to false
> if it was listed after OPTIONAL_COMPONENTS."
>
> It would probably make sense to name the target-files similar to the
> components, so that you can do something like
>
> foreach(comp ${Mypackage_FIND_COMPONENTS})
> include($CMAKE_CURRENT_LIST_DIR}/${comp}Targets.cmake)
> endforeach()
>
> You should additionally use the OPTIONAL and RESULT_VARIABLE options for
> include() and check whether the component was required, and set
> Mypackage_FOUND to FALSE if a required component could not be included.
>
> Alex
More information about the CMake
mailing list