[CMake] What is the proper way to export targets that will be split into separate binary packages?

Nils Gladitz nilsgladitz at gmail.com
Tue Apr 28 05:57:08 EDT 2015


On 04/28/2015 11:43 AM, Alan W. Irwin wrote:
> @Nils: the origin of the code right below "If COMPONENTS..." is not
> clear.  Is that code that should be supplied by a package creator or
> code that
> should be implemented by every find_package user?  And if it should be
> supplied by a package creator, does the install(EXPORT...) signature
> generate that code automatically, does one of the helper functions
> that are available generate that code, or do I (as package creator)
> have to supply that code some other way?

The package configuration file is normally handwritten (or 
handgenerated) by the package creator. I assume you already have one? 
e.g. plplotConfig.cmake.


>> http://www.cmake.org/cmake/help/v3.2/manual/cmake-packages.7.html#creating-packages
>>
>
> @Alex: Sorry I missed your reply until now.
>
> @Alex or Nils:
>
> The problem with the URL provided by Nils is only one library is used
> in the example so I don't understand exactly what you guys are
> suggesting for the multiple library/component case.
>
> For example, are you recommending
>
> install(TARGETS plplot1 EXPORT export_plplot ...)
> [...]
> install(TARGETS plplotN EXPORT export_plplot ...)
>
> for N installed libraries followed by
>
> install(EXPORT export_plplot DESTINATION ${LIB_DIR}/cmake/plplot)
>
> ?  That is the current pattern I am using with one overall export name
> called "export_plplot".   Or would you recommend this different pattern
>
> install(TARGETS plplot1 EXPORT export_plplot1 ...)
> install(EXPORT export_plplot1 DESTINATION ${LIB_DIR}/cmake/plplot)
> [...]
> install(TARGETS plplotN EXPORT export_plplotN ...)
> install(EXPORT export_plplotN DESTINATION ${LIB_DIR}/cmake/plplot)
>
> (i.e., N pairs of install(TARGETS...) install(EXPORT...) signatures
> with each pair having a unique export name)?

Yes, unique/distinct export names and export files.

That way the target export files can go into the respective distribution 
package that they represent.

The "umbrella" package configuration file would be installed by your 
"core" package and would then be able to pick up the currently available 
target export files.

Nils


More information about the CMake mailing list