diff --git a/cmake/opentelemetry-cpp-config.cmake.in b/cmake/opentelemetry-cpp-config.cmake.in index d0fe97e0d4..2b4c655f67 100644 --- a/cmake/opentelemetry-cpp-config.cmake.in +++ b/cmake/opentelemetry-cpp-config.cmake.in @@ -158,9 +158,20 @@ set(_OPENTELEMETRY_CPP_TARGETS set(_FIND_ALL_COMPONENTS TRUE) +set(_OPENTELEMETRY_CPP_REQUESTED_COMPONENTS) + if(NOT DEFINED opentelemetry-cpp_FIND_COMPONENTS OR opentelemetry-cpp_FIND_COMPONENTS STREQUAL "") # if no components are requested then find all installed components - set(_OPENTELEMETRY_CPP_REQUESTED_COMPONENTS ${_OPENTELEMETRY_CPP_COMPONENTS}) + + set(_TARGET_FILES_DIR "${CMAKE_CURRENT_LIST_DIR}") + + foreach(_COMPONENT IN LISTS _OPENTELEMETRY_CPP_COMPONENTS) + set(_COMPONENT_TARGET_FILE "${_TARGET_FILES_DIR}/opentelemetry-cpp-${_COMPONENT}-target.cmake") + if(EXISTS "${_COMPONENT_TARGET_FILE}") + list(APPEND _OPENTELEMETRY_CPP_REQUESTED_COMPONENTS ${_COMPONENT}) + endif() + endforeach() + else() set(_FIND_ALL_COMPONENTS FALSE) # check that the requested components are valid and installed