# Helpers for \`install(EXPORT)\` for components

**URL:** https://discourse.cmake.org/t/helpers-for-install-export-for-components/7705
**Category:** Development
**Created:** [March 17, 2023, 6:42pm UTC](https://discourse.cmake.org/t/helpers-for-install-export-for-components/7705 "2023-03-17T18:42:53Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Lecris](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lecris/32/3193_2.png) [@Lecris](https://discourse.cmake.org/u/Lecris)
#### Post date: [March 17, 2023, 6:42pm UTC](https://discourse.cmake.org/t/helpers-for-install-export-for-components/7705/1 "2023-03-17T18:42:53Z")

</div>

I understand that we need to write our own logic for how to load the components requested, but it would be nice if there were some ways to have more control over the generated `PackageTargets.cmake`. For example instead of:

```cmake
if(DEFINED ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)
  if(CMAKE_FIND_PACKAGE_NAME)
    set( ${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)
    set( ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "The following imported targets are referenced, but are missing: ${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets}")
  else()
    message(FATAL_ERROR "The following imported targets are referenced, but are missing: ${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets}")
  endif()
endif()

```

We could have

```cmake
if(DEFINED ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)
  if(CMAKE_FIND_PACKAGE_NAME)
    set( ${CMAKE_FIND_PACKAGE_NAME}_${CMAKE_FIND_COMPONENT_NAME}_FOUND FALSE)
    set( ${CMAKE_FIND_PACKAGE_NAME}_${CMAKE_FIND_COMPONENT_NAME}_NOT_FOUND_MESSAGE "The following imported targets are referenced, but are missing: ${${CMAKE_FIND_PACKAGE_NAME}_${CMAKE_FIND_COMPONENT_NAME}_NOT_FOUND_MESSAGE_targets}")
  else()
    message(FATAL_ERROR "The following imported targets are referenced, but are missing: ${${CMAKE_FIND_PACKAGE_NAME}_${CMAKE_FIND_COMPONENT_NAME}_NOT_FOUND_MESSAGE_targets}")
  endif()
endif()

```

(Note the additional `CMAKE_FIND_COMPONENT_NAME`)

---

<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: [March 17, 2023, 7:32pm UTC](https://discourse.cmake.org/t/helpers-for-install-export-for-components/7705/2 "2023-03-17T19:32:57Z")

</div>

That variable doesn’t exist; what would set it? Do you instead mean that `export(EXPORT)` and `install(EXPORT)` should take a `COMPONENT` argument to bake into this code?

---

<div class="post-metadata">

### Author: ![Lecris](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lecris/32/3193_2.png) [@Lecris](https://discourse.cmake.org/u/Lecris)
#### Post date: [March 17, 2023, 7:49pm UTC](https://discourse.cmake.org/t/helpers-for-install-export-for-components/7705/3 "2023-03-17T19:49:41Z")

</div>

Yes, the latter. More generally, more helper functions to be able to create components more easily. I have a so far functioning implementation on [an utility repo](https://github.com/LecrisUT/CmakeExtraUtils/blob/180604da50a3c3588f9d04e4ebc6abb4e5a0d234/cmake/PackageComps.md) that I am developing, but there is so much boilerplate involving trying to load a `PackageTargets_component.cmake` file that it makes it difficult to read and follow. It would be nice to have some equivalent functionalities backed in.

---

<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: [March 17, 2023, 9:58pm UTC](https://discourse.cmake.org/t/helpers-for-install-export-for-components/7705/4 "2023-03-17T21:58:56Z")

</div>

Seems like [a reasonable request](https://gitlab.kitware.com/cmake/cmake/-/issues). There’s still a lot of stuff around it, but associating an entire `EXPORT` set with a component seems like a reasonable place to start.

---

<div class="post-metadata">

### Author: ![Lecris](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lecris/32/3193_2.png) [@Lecris](https://discourse.cmake.org/u/Lecris)
#### Post date: [March 22, 2023, 3:31pm UTC](https://discourse.cmake.org/t/helpers-for-install-export-for-components/7705/5 "2023-03-22T15:31:14Z")

</div>

Forgot to open the issue. [Here](https://gitlab.kitware.com/cmake/cmake/-/issues/24628) it is
