Thanks Jakub. Mixing your proposal and mistral codestral’s one I’m getting:
get_property(ImportedTargets DIRECTORY "${CMAKE_SOURCE_DIR}" PROPERTY IMPORTED_TARGETS)
list(FILTER ImportedTargets INCLUDE REGEX "^${PackName}::")
if(ImportedTargets)
# Creating the main component
add_library(${PackName}::${PackName} INTERFACE IMPORTED)
# Adding the found components as dependencies
if(ImportedTargets)
target_link_libraries(${PackName}::${PackName} INTERFACE ${ImportedTargets})
endif()
endif()