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

**URL:** <https://discourse.cmake.org/t/components-must-be-defined-when-there-exist-multiple-utilities-in-find-modules/10128>\
**Category:** Code\
**Created:** [February 18, 2024, 3:07am UTC](https://discourse.cmake.org/t/components-must-be-defined-when-there-exist-multiple-utilities-in-find-modules/10128 "2024-02-18T03:07:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hwhsu1231](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hwhsu1231/32/5358_2.png) [@hwhsu1231](https://discourse.cmake.org/u/hwhsu1231)\
**Post date:** [February 18, 2024, 3:07am UTC](https://discourse.cmake.org/t/components-must-be-defined-when-there-exist-multiple-utilities-in-find-modules/10128/1 "2024-02-18T03:07:38Z")

</div>

Hello, CMake Team.

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [February 18, 2024, 3:57am UTC](https://discourse.cmake.org/t/components-must-be-defined-when-there-exist-multiple-utilities-in-find-modules/10128/2 "2024-02-18T03:57:27Z")

</div>

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](https://cmake.org/cmake/help/latest/module/FindPackageHandleStandardArgs.html) can set the overall `_FOUND` variable up based on `Pkg_Comp_FOUND` variables you set throughout the component searching process.

---

<div class="post-metadata">

**Author:** ![hwhsu1231](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hwhsu1231/32/5358_2.png) [@hwhsu1231](https://discourse.cmake.org/u/hwhsu1231)\
**Post date:** [February 18, 2024, 6:31am UTC](https://discourse.cmake.org/t/components-must-be-defined-when-there-exist-multiple-utilities-in-find-modules/10128/3 "2024-02-18T06:31:24Z")

</div>

> 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](https://cmake.org/cmake/help/latest/module/FindPackageHandleStandardArgs.html) 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`](https://github.com/Kitware/CMake/blob/v3.28.3/Modules/FindPython.cmake#L622-L625), 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?

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [February 19, 2024, 4:02am UTC](https://discourse.cmake.org/t/components-must-be-defined-when-there-exist-multiple-utilities-in-find-modules/10128/4 "2024-02-19T04:02:32Z")

</div>

> [@hwhsu1231](#):
>
> It’s **indeed** required to define COMPONENTS when there exist multiple utilities in Find modules.

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

> [@hwhsu1231](#):
>
> The only difference is that `FindGettext.cmake` should specify all of the known COMPONENTS as its `Gettext_FIND_COMPONENTS`.

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).

---

<div class="post-metadata">

**Author:** ![hwhsu1231](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hwhsu1231/32/5358_2.png) [@hwhsu1231](https://discourse.cmake.org/u/hwhsu1231)\
**Post date:** [February 22, 2024, 6:12pm UTC](https://discourse.cmake.org/t/components-must-be-defined-when-there-exist-multiple-utilities-in-find-modules/10128/5 "2024-02-22T18:12:22Z")

</div>

Hello, @ben.boeckel

> [@ben.boeckel](#):
>
> > [@hwhsu1231](#):
> >
> > It’s **indeed** required to define COMPONENTS when there exist multiple utilities in Find modules.
> 
> No. But if you support components and a component has an associated target, the names should match.

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

Additionally, referring to COMPONENTS in [FindDoxygen.cmake](https://cmake.org/cmake/help/v3.28/module/FindDoxygen.html), 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:

- `Intl`: Corresponds to [sphinx-intl](https://github.com/sphinx-doc/sphinx-intl)
- `Gherkindoc`: Corresponds to [sphinx-gherkindoc](https://github.com/jolly-good-toolbelt/sphinx_gherkindoc)

To specify components explicitly:

```cmake
# 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?

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [February 27, 2024, 2:05pm UTC](https://discourse.cmake.org/t/components-must-be-defined-when-there-exist-multiple-utilities-in-find-modules/10128/6 "2024-02-27T14:05:21Z")

</div>

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.
