Helpers for `install(EXPORT)` for components

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:

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

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)

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?

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

Seems like a reasonable request. 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.

Forgot to open the issue. Here it is