Просмотр исходного кода

Added to utility CMake functions to obtain target dependencies.

Sascha Zelzer лет назад: 13
Родитель
Сommit
6857f57250

+ 39 - 0
CMake/ctkFunctionGetPluginDependencies.cmake

@@ -0,0 +1,39 @@
+#!
+#! \brief Stores all known plug-in dependencies (potentially also from external projects)
+#! in the variable specified by the first argument.
+#!
+#! \param var_deps (required) A variable name containing the output.
+#! \param PLUGINS (required) A list of plug-ins (target names or symbolic names) for which the
+#!        set of dependencies should be obtained.
+#! \param ALL (option) Include external dependencies.
+#! \ingroup CMakeUtilities
+function(ctkFunctionGetPluginDependencies var_deps)
+
+  ctkMacroParseArguments(MY "PLUGINS" "ALL" ${ARGN})
+
+  # Sanity checks
+  if(NOT var_deps)
+    message(FATAL_ERROR "Missing variable name as the first argument for storing the result")
+  endif()
+  
+  if(NOT MY_PLUGINS)
+    message(FATAL_ERROR "Missing plug-in names")
+  endif()
+  
+  if(MY_ALL)
+    ctkFunctionGetTargetDependencies(_targets TARGETS ${MY_PLUGINS} ALL)
+  else()
+    ctkFunctionGetTargetDependencies(_targets TARGETS ${MY_PLUGINS})
+  endif()
+  
+  set(_plugins )
+  foreach(_target ${_targets})
+    if(_target MATCHES _)
+      list(APPEND _plugins ${_target})
+    endif()
+  endforeach()
+
+  message("[${MY_PLUGINS}] deps: ${_plugins}")
+  set(${var_deps} ${_plugins} PARENT_SCOPE)
+
+endfunction()

+ 42 - 0
CMake/ctkFunctionGetTargetDependencies.cmake

@@ -0,0 +1,42 @@
+#!
+#! \brief Stores all target dependencies (potentially also from external projects)
+#! in the variable specified by the first argument.
+#!
+#! \param var_deps (required) A variable name containing the output.
+#! \param TARGETS (required) A list of targets (library targets or plug-in targets/symbolic names)
+#!                for which the set of dependencies should be obtained.
+#! \param ALL (option) Include external dependencies.
+#! \ingroup CMakeUtilities
+function(ctkFunctionGetTargetDependencies var_deps)
+
+  ctkMacroParseArguments(MY "TARGETS" "ALL" ${ARGN})
+
+  # Sanity checks
+  if(NOT var_deps)
+    message(FATAL_ERROR "Missing variable name as the first argument for storing the result")
+  endif()
+  
+  if(NOT MY_TARGETS)
+    message(FATAL_ERROR "Missing target names")
+  endif()
+
+  set(_targets )
+  foreach(_target ${MY_TARGETS})
+    # convenience conversion for plug-in targets
+    string(REPLACE "." "_" _target ${_target})
+    # assume the variable ${_target}_DEPENDENCIES was set during
+    # a previous invocation of the ctkMacroValidateBuildOptions macro.
+    list(APPEND _targets ${${_target}_DEPENDENCIES})
+  endforeach()
+  
+  if (_targets)
+    list(REMOVE_DUPLICATES _targets)
+    if(NOT MY_ALL)
+      # remove external targets not belonging to the current project
+      ctkMacroGetAllProjectTargetLibraries("${_targets}" _targets)
+    endif()
+  endif()
+message("[${MY_TARGETS}] deps: ${_targets}")
+  set(${var_deps} ${_targets} PARENT_SCOPE)
+
+endfunction()

+ 2 - 0
CTKConfig.cmake.in

@@ -64,6 +64,8 @@ INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionGetIncludeDirs.cmake")
 INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionGetLibraryDirs.cmake")
 INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionGetLibraryDirs.cmake")
 INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionExtractPluginTargets.cmake")
 INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionExtractPluginTargets.cmake")
 INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionGetAllPluginTargets.cmake")
 INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionGetAllPluginTargets.cmake")
+INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionGetTargetDependencies.cmake")
+INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionGetPluginDependencies.cmake")
 INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkMacroSetupPlugins.cmake")
 INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkMacroSetupPlugins.cmake")
 
 
 SET(CTK_EXPORT_HEADER_TEMPLATE "@CTK_EXPORT_HEADER_TEMPLATE@")
 SET(CTK_EXPORT_HEADER_TEMPLATE "@CTK_EXPORT_HEADER_TEMPLATE@")