CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkFunctionGetTargetDependencies.cmake
Go to the documentation of this file.
1 #!
2 #! \brief Stores all target dependencies (potentially also from external projects)
3 #! in the variable specified by the first argument.
4 #!
5 #! \param var_deps (required) A variable name containing the output.
6 #! \param TARGETS (required) A list of targets (library targets or plug-in targets/symbolic names)
7 #! for which the set of dependencies should be obtained.
8 #! \param ALL (option) Include external dependencies.
9 #! \ingroup CMakeUtilities
10 function(ctkFunctionGetTargetDependencies var_deps)
11 
12  ctkMacroParseArguments(MY "TARGETS" "ALL" ${ARGN})
13 
14  # Sanity checks
15  if(NOT var_deps)
16  message(FATAL_ERROR "Missing variable name as the first argument for storing the result")
17  endif()
18 
19  if(NOT MY_TARGETS)
20  message(FATAL_ERROR "Missing target names")
21  endif()
22 
23  set(_targets )
24  foreach(_target ${MY_TARGETS})
25  # convenience conversion for plug-in targets
26  string(REPLACE "." "_" _target ${_target})
27  # assume the variable ${_target}_DEPENDENCIES was set during
28  # a previous invocation of the ctkMacroValidateBuildOptions macro.
29  list(APPEND _targets ${${_target}_DEPENDENCIES})
30  endforeach()
31 
32  if (_targets)
33  list(REMOVE_DUPLICATES _targets)
34  if(NOT MY_ALL)
35  # remove external targets not belonging to the current project
36  ctkMacroGetAllProjectTargetLibraries("${_targets}" _targets)
37  endif()
38  endif()
39 
40  set(${var_deps} ${_targets} PARENT_SCOPE)
41 
42 endfunction()