Docs: Importing/Exporting Guide: Components example may break with transitive usage
In the Importing and Exporting Guide, the "Adding Components" section uses an example to set supported components as:
set(_supported_components Addition SquareRoot)
foreach(_comp ${MathFunctions_FIND_COMPONENTS})
if (NOT _comp IN_LIST _supported_components)
set(MathFunctions_FOUND False)
set(MathFunctions_NOT_FOUND_MESSAGE "Unsupported component: ${_comp}")
endif()
include("${CMAKE_CURRENT_LIST_DIR}/MathFunctions${_comp}Targets.cmake")
endforeach()
A more advanced version of this may have to search for component dependencies using find_package
prior to marking a component as found (e.g., setting MathFunctions_${_comp}_FOUND
) and including its Targets.cmake file.
However, if such a transitive dependency also implements a package helper with components like this example using _supported_components
, _supported_components
will be overridden and the if
check will likely fail to match requested components in later foreach
iterations.
It may be preferable to use a package-specific prefix, e.g., use _MathFunctions_supported_components
instead (then unset it at the end). Even more generally, ${CMAKE_FIND_PACKAGE_NAME}
might be used in place of the hardcoded MathFunctions
for easier copy/paste of the example.