Help with find module for package w/ components

Help with find module for package w/ components

I need some guidance. I am writing a find module for a package that defines multiple library archives, includes and Fortran module files. I would like to make a "best practices" and "modern" find module and define a target so that transitive properties are propagated correctly. I would like to define two components, the base package itself (multiple library files and Fortran module files) and then the C interface (additional library file and C include files).

The biggest point of confusion: Is there a way to define a single target that can be passed to target_link_libraries() that will cause the *multiple* (imported) library archives of the base package to linked in? Can I define it in such a way that it is namespaced like Foo::Foo?

For an optional component, then do I specify an additional target for that component?

Re: Help with find module for package w/ components

> Is there a way to define a single target
> that can be passed to target_link_libraries() that will cause the
> *multiple* (imported) library archives of the base package to linked in?

Hi Zaak:

Imported library targets are handled similarly to ordinary library
targets. So suppose you have a core library with the name core_fortran
and a c interface library with the name c_interface, then C code
should be linked to c_interface (which draws in core_fortran if you
are transitively linking but otherwise not) and fortran code should be linked
to core_fortran.

> For an optional component, then do I specify an additional target for that
> component?

CMake users can organize the export of CMake packages in essentially
any way they like. For example, the PLplot build system I am helping
to maintain uses a deprecated paradigm where there is just one
exported package containing a very large number of different targets.
But this approach is deprecated since it makes life too difficult for
software distribution maintainers who typically like to split up the
various libraries and dll's installed by a project into several
different interdependent binary packages. So it is very much on my
agenda to reorganize our single export of a CMake package into a
number of different exports with each of those CMake packages
containing a disjoint subset of our targets with appropriate
find_package commands in Config mode to import all CMake packages that
a given CMake package depends on.

So in your case, this new approach we intend to take would boil down
to you exporting a CMake package corresponding to your C interface library and a
CMake package corresponding to your core Fortran library. And the C interface
library CMake package should use find_package to find the fortran core
library package your C interface library depends on. So if user code
depends on your C interface, they should use find_package in Config
mode to find your C interface library package which in turn
automatically finds your core Fortran library. But if user code is
Fortran only they should just import your core Fortran library CMake
package. N.B. in both cases, the net effect is all targets are imported
that are needed. But once those targets are imported then the use of
those targets in target_link_library commands is completely orthogonal
to exactly how the targets are organized into separate packages.

Anyhow, I hope this discussion (especially the above URL reference to best
CMake practices) is a help to you.

Alan
__________________________
Alan W. Irwin

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