Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically detect target dependencies #3

Open
TheLartians opened this issue Apr 27, 2020 · 3 comments
Open

Automatically detect target dependencies #3

TheLartians opened this issue Apr 27, 2020 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@TheLartians
Copy link
Owner

Perhaps this is possible using FeatureSummary as suggested on the CMake slack.

@TheLartians TheLartians added the enhancement New feature or request label Apr 27, 2020
@TheLartians TheLartians added the help wanted Extra attention is needed label Dec 18, 2020
@ClausKlein
Copy link
Contributor

Great idea!

with this code appended to test/CMakeLists.txt

include(FeatureSummary)
feature_summary(
  WHAT ALL
  FILENAME ${CMAKE_CURRENT_SOURCE_DIR}/FeatureSummary.log)

I will get his file contents:

The following REQUIRED packages have been found:

 * dependency (required version >= 1.2)
 * namespaced_dependency (required version >= 4.5.6)
 * transitive_dependency (required version >= 7.8.9)

@ClausKlein
Copy link
Contributor

This version seems better to parse and get only the list of required packages found:

include(FeatureSummary)
feature_summary(
  WHAT REQUIRED_PACKAGES_FOUND
  QUIET_ON_EMPTY
  DESCRIPTION ""
  FILENAME ${CMAKE_CURRENT_SOURCE_DIR}/RequiredPackagesFound.log)

@ClausKlein
Copy link
Contributor

@TheLartians This seems a good starting point:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants