I want to get the list of all dependency libraries and their versions of a target.
This should be possible for imported targets and for build targets.
For imported targets ist works, but I am wondering that the version is only available with non namespace target name
?
add_executable(main main.cpp)
target_link_libraries(
main dependency ns::namespaced_dependency transitive_dependency::transitive_dependency
)
enable_testing()
add_test(NAME test COMMAND main)
include(FeatureSummary.cmake)
feature_summary(
WHAT REQUIRED_PACKAGES_FOUND
QUIET_ON_EMPTY
DESCRIPTION ""
FILENAME ${CMAKE_CURRENT_SOURCE_DIR}/RequiredPackagesFound.log
)
# Claus-iMac:test clausklein$ cat RequiredPackagesFound.log
# * dependency (required version >= 1.2)
# * namespaced_dependency (required version >= 4.5.6)
# * transitive_dependency (required version >= 7.8.9)
set(current_targets main)
get_property(
_depends
TARGET ${current_targets}
PROPERTY INTERFACE_LINK_LIBRARIES
)
message(STATUS "${current_targets}: ${_depends}\n")
set(_property "PACKAGES_FOUND")
set(_currentFeatureText "")
get_property(_EnabledFeatures GLOBAL PROPERTY ${_property})
if(_EnabledFeatures)
list(REMOVE_DUPLICATES _EnabledFeatures)
endif()
message(STATUS "${_property}: ${_EnabledFeatures}")
set(_currentFeature PACKAGES_FOUND)
get_property(
_importedTargets
DIRECTORY ${CMAKE_CURRENT_SORUCE_DIR}
PROPERTY IMPORTED_TARGETS
)
foreach(_target ${_importedTargets})
list(FIND _depends ${_target} _indexInList)
if(NOT "${_indexInList}" STREQUAL "-1")
# NOTE: we need the unalias target name! CK
string(REGEX REPLACE "([^:]+::)" "" _targetName ${_target})
get_property(_version GLOBAL PROPERTY _CMAKE_${_targetName}_REQUIRED_VERSION)
message(STATUS "IMPORTED_TARGETS: ${_targetName} ${_version}")
endif()
endforeach()
# _CMAKE_dependency_REQUIRED_VERSION: >= 1.2
# _CMAKE_namespaced_dependency_REQUIRED_VERSION: >= 4.5.6
# _CMAKE_transitive_dependency_REQUIRED_VERSION: >= 7.8.9
# -- main: dependency;ns::namespaced_dependency;transitive_dependency::transitive_dependency
#
# -- PACKAGES_FOUND: dependency;namespaced_dependency;fmt;cxxopts;transitive_dependency
# -- IMPORTED_TARGETS: dependency >= 1.2
# -- IMPORTED_TARGETS: namespaced_dependency >= 4.5.6
# -- IMPORTED_TARGETS: transitive_dependency >= 7.8.9