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

Alan W. Irwin irwin at beluga.phys.uvic.ca
Fri Apr 24 15:33:50 EDT 2015


The Fedora packager of PLplot is having trouble splitting installed
results into separate binary packages because of the way that PLplot
currently exports its targets.  What steps do we have to do to make
life easier for him?

Here is the typical code we use now to export our targets.

# Done only once
install(EXPORT export_plplot DESTINATION ${LIB_DIR}/cmake/plplot)

# Done for each different PLplot library target we want to export
install(TARGETS <targetname>
   EXPORT export_plplot
   ARCHIVE DESTINATION ${LIB_DIR}
   LIBRARY DESTINATION ${LIB_DIR}
   RUNTIME DESTINATION ${BIN_DIR}
   )

# Done for each different PLplot executable target we want to export
install(TARGETS <targetname>
   EXPORT export_plplot
   DESTINATION ${BIN_DIR}
   )

As a result of these commands, $prefix/lib/cmake/plplot contains
three files:

export_plplot-noconfig.cmake,  export_plplot.cmake,  and plplotConfig.cmake

I can find no reference to the noconfig variant, but from the
documentation, find_package(plplot) in Config mode will find
plplotConfig.cmake which in turn includes export_plplot.cmake which
has CMake logic that loops over _every_ exported target.

For a completely separate build system (for our installed examples)
we import all these targets using

find_package(plplot)

and that works well for individual use of PLplot where nothing is
split out from the installation.

However, that command does not work well for binary packagers of
PLplot since those packagers generally split the installed files into
a bunch of different binary packages (typically a core package and
optional additional packages to add extra features to the core
package).  So if the Fedora packager, for example, splits out the
octave component of PLplot into a separate binary package, then when
that package is not installed, find_package(plplot) errors out (as a
result of that loop over all exported targets) with

CMake Error at /usr/lib64/cmake/plplot/export_plplot.cmake:163 (message):
   The imported target "plplot_octave" references the file

      "/usr/lib64/octave/site/oct/x86_64-redhat-linux-gnu/plplot_octave.oct"

   but this file does not exist.  [...]

What changes to the above export procedure and/or 
find_package(plplot ... ) command are recommended so that 
find_package(plplot ....) just works when some split PLplot 
binary packages are not installed?

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state
implementation for stellar interiors (freeeos.sf.net); the Time
Ephemerides project (timeephem.sf.net); PLplot scientific plotting
software package (plplot.sf.net); the libLASi project
(unifont.org/lasi); the Loads of Linux Links project (loll.sf.net);
and the Linux Brochure Project (lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list