Helpers for `install(EXPORT)` for components
This is related to this Discourse discussion.
In essence, it would be nice to have more helpers for exporting components to be used in find_package(COMPONENTS)
, and to make both exporting and importing 1-target 1-target-file 1-component easier. E.g. one might want to have:
install(EXPORT MyTargets
COMPONENT custom_component)
Or equivalently in configure_package_config_file()
or wherever, so that instead of generating a PackageConfigTargets.cmake
as:
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()
It could generate to:
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()
Notice the ${CMAKE_FIND_COMPONENT_NAME}
as a placeholder for custom_component
.
Any such macro/function heleprs/extensions are grateful, e.g.:
- Helper function to import
PackageConfigTargets_my_component.cmake
as a specific component, setting appropriate${CMAKE_FIND_PACKAGE_NAME}_${CMAKE_FIND_COMPONENT_NAME}_FOUND
- Helper function to handle
<PackageName>_FIND_REQUIRED_<c>
depending on file include results, etc.
Here's an example of how much boilerplate is needed to properly handle all of these, it would be nice to minimize this as much as possible
Edited by Cristian Le