@@ -152,6 +152,18 @@ include(FetchContent)
152152# to build the dependency. This argument can optionally be used to
153153# specify a file which deviates from the convention.
154154#
155+ # [multiValueArgs]
156+ #
157+ # DEPENDENCY_LINK_TARGETS:
158+ # A list of target names that should be registered as link targets when
159+ # consuming the dependency. This argument is optional. When specified,
160+ # the provided names represent CMake targets that are made available to
161+ # the underlying project by the dependency. These target names are then
162+ # appended to the global variable ${PROJECT}_DEPENDENCIES_LINK_TARGETS
163+ # where ${PROJECT} is the name in all caps of the underlying project as
164+ # given to the CMake project() function. A dependency with "TEST" scope
165+ # is never added to that list.
166+ #
155167# [options]
156168#
157169# DEPENDENCY_QUIET:
@@ -201,7 +213,9 @@ function(dependency)
201213 DEPENDENCY_CONFIG_FILE
202214 DEPENDENCY_BUILD_FILE
203215 )
204- set (multiValueArgs "" )
216+ set (multiValueArgs
217+ DEPENDENCY_LINK_TARGETS
218+ )
205219
206220 cmake_parse_arguments (
207221 DEP_ARGS
@@ -465,6 +479,7 @@ function(dependency)
465479
466480 FetchContent_MakeAvailable(${DEP_ARGS_DEPENDENCY_NAME} )
467481
482+ # Check if a build file needs to be included
468483 if (DEFINED DEP_ARGS_DEPENDENCY_BUILD_FILE)
469484 set (
470485 DEPENDENCY_BUILD_FILE
@@ -487,8 +502,9 @@ function(dependency)
487502 endif ()
488503 endif ()
489504
490- # Append dependency name to a tracked global cached list
505+ # Check tracked identifiers
491506 if (DEPENDENCY_SCOPE IN_LIST DEP_TRACKED_SCOPES)
507+ # Append dependency name to a tracked global cached list
492508 set (PROJECT_DEPENDENCIES_LIST ${PROJECT_NAME_UPPER} _DEPENDENCIES_LIST)
493509 set (_dep_list "${${PROJECT_DEPENDENCIES_LIST} }" )
494510 list (FIND _dep_list "${DEP_ARGS_DEPENDENCY_NAME} " _dep_idx)
@@ -502,5 +518,26 @@ function(dependency)
502518 FORCE
503519 )
504520 endif ()
521+
522+ # Append dependency link targets to a tracked global cached list
523+ if (DEP_ARGS_DEPENDENCY_LINK_TARGETS)
524+ set (PROJECT_DEPENDENCIES_LINK_TARGETS
525+ ${PROJECT_NAME_UPPER} _DEPENDENCIES_LINK_TARGETS
526+ )
527+ set (_dep_link_list "${${PROJECT_DEPENDENCIES_LINK_TARGETS} }" )
528+ foreach (_link_item IN ITEMS ${DEP_ARGS_DEPENDENCY_LINK_TARGETS} )
529+ list (FIND _dep_link_list "${_link_item} " _dep_idx)
530+ if (_dep_idx EQUAL -1)
531+ list (APPEND _dep_link_list "${_link_item} " )
532+ endif ()
533+ endforeach ()
534+ set (${PROJECT_DEPENDENCIES_LINK_TARGETS}
535+ ${_dep_link_list}
536+ CACHE STRING
537+ "List of link targets of all dependencies"
538+ FORCE
539+ )
540+ endif ()
505541 endif ()
542+
506543endfunction ()
0 commit comments