COMPONENTS must be defined when there exist multiple utilities in Find modules?

Hello, CMake Team.

Let’s take FindGettext.cmake as an example. We know that Gettext has many utilities:

xgettext
msgattrib
msgcat
msginit
msgmerge
...etc

If today I were to write my own FindGettext.cmake, should I necessarily (or is it advisable to) design a COMPONENTS filtering mechanism to allow users to specify which components they want to use when calling find_package?

Or should users simply need to call find_package(Gettext REQUIRED) to be able to use all of Gettext’s utilities?

For something like gettext where these tools are almost always shipped together, I think the default can be to find and provide all discovered components. If components are requested, then FPHSA can set the overall _FOUND variable up based on Pkg_Comp_FOUND variables you set throughout the component searching process.

For something like gettext where these tools are almost always shipped together, I think the default can be to find and provide all discovered components. If components are requested, then FPHSA can set the overall _FOUND variable up based on Pkg_Comp_FOUND variables you set throughout the component searching process.

Do you mean that:

  1. It’s indeed required to define COMPONENTS when there exist multiple utilities in Find modules.
  2. But for Gettext such module, if users don’t specify any COMPONENT in argument, then this module should specify all of the known COMPONENTS by default.

Similar to FindPython.cmake, it will specify Interpreter as its Python_FIND_COMPONENTS if users don’t specify any COMPONENT in argument. The only difference is that FindGettext.cmake should specify all of the known COMPONENTS as its Gettext_FIND_COMPONENTS.

Correct?

No. But if you support components and a component has an associated target, the names should match.

Yes, if gettext is almost always shipped as a single unit (not like Python which tends to have separate packages for the interpreter, the stdlib, its library, and its SDK).

Hello, @ben.boeckel

So under what circumstances, even if a Find module has multiple targets, will COMPONENTS not be defined?

Additionally, referring to COMPONENTS in FindDoxygen.cmake, if FindSphinx.cmake is to define COMPONENTS, besides defining Build, Quickstart, Apidoc, and Autogen as the default components to be used, Intl and Gherkindoc components can also be added:

To specify components explicitly:

# Require Build QuickStart Autogen Apidoc, 
# Treat the other components as optional.
find_package(Doxygen REQUIRED 
    COMPONENTS Build QuickStart Autogen Apidoc
    OPTIONAL_COMPONENTS Intl Gherkindoc)

What do you think?

Component support is currently always a hand-coded thing; there’s no mechanism in CMake for generating COMPONENT-aware config file. Whether it is worth it or not really depends on the package in question.