Bladeren bron

ENH: PluginDependencies: Use "DGraph -sort label" in ctkMacroValidateBuildOptions
and store the result in project-specific variables. These variables are
used in ctkMacroBuildPlugin to set up transitive include dircetories for
plugin dependencies.

The macro ctkMacroTargetLibraries now parses the target_libraries.cmake
file as well as manifest_headers.cmake to include plugin dependencies.
Libraries starting with CTK* or org_commontk_* are now treated equally.

Sascha Zelzer 15 jaren geleden
bovenliggende
commit
1e9e0d4e4b
3 gewijzigde bestanden met toevoegingen van 121 en 68 verwijderingen
  1. 7 8
      CMake/ctkMacroBuildPlugin.cmake
  2. 90 40
      CMake/ctkMacroTargetLibraries.cmake
  3. 24 20
      CMake/ctkMacroValidateBuildOptions.cmake

+ 7 - 8
CMake/ctkMacroBuildPlugin.cmake

@@ -87,10 +87,6 @@ MACRO(ctkMacroBuildPlugin)
 
   STRING(REPLACE "_" "." Plugin-SymbolicName ${lib_name})
 
-  # Create a list of plugin dependencies
-  STRING(REPLACE "." "_" require_plugin "${Require-Plugin}")
-  MESSAGE("require_plugin: ${require_plugin}")
-
   # --------------------------------------------------------------------------
   # Include dirs
   SET(my_includes
@@ -101,13 +97,17 @@ MACRO(ctkMacroBuildPlugin)
     )
 
   # Add the include directories from the plugin dependencies
-  FOREACH(plugin ${require_plugin})
+  # The variable ${lib_name}_DEPENDENCIES is set in the
+  # macro ctkMacroValidateBuildOptions
+  FOREACH(dep ${${lib_name}_DEPENDENCIES})
     LIST(APPEND my_includes
-         ${${plugin}_SOURCE_DIR}
-         ${${plugin}_BINARY_DIR}
+         ${${dep}_SOURCE_DIR}
+         ${${dep}_BINARY_DIR}
          )
   ENDFOREACH()
 
+  LIST(REMOVE_DUPLICATES my_includes)
+
   INCLUDE_DIRECTORIES(
     ${my_includes}
     )
@@ -205,7 +205,6 @@ MACRO(ctkMacroBuildPlugin)
   
   SET(my_libs
     ${MY_TARGET_LIBRARIES}
-    ${require_plugin}
     )
   TARGET_LINK_LIBRARIES(${lib_name} ${my_libs})
   

+ 90 - 40
CMake/ctkMacroTargetLibraries.cmake

@@ -24,34 +24,57 @@
 MACRO(ctkMacroGetTargetLibraries varname)
 
   SET(filepath ${CMAKE_CURRENT_SOURCE_DIR}/target_libraries.cmake)
+  SET(manifestpath ${CMAKE_CURRENT_SOURCE_DIR}/manifest_headers.cmake)
 
-  # Check if "target_libraries.cmake" file exists
-  IF(NOT EXISTS ${filepath})
-    MESSAGE(FATAL_ERROR "${filepath} doesn't exists !")
+  # Check if "target_libraries.cmake" or "manifest_headers.cmake" file exists
+  IF(NOT EXISTS ${filepath} AND NOT EXISTS ${manifestpath})
+    MESSAGE(FATAL_ERROR "${filepath} or ${manifestpath} doesn't exists !")
   ENDIF()
 
   # Make sure the variable is cleared
   SET(target_libraries )
+  SET(Require-Plugin )
+
+  IF(EXISTS ${filepath})
+    # Let's make sure target_libraries contains only strings
+    FILE(STRINGS "${filepath}" stringtocheck) # read content of 'filepath' into 'stringtocheck'
+    STRING(REGEX MATCHALL "[^\\#]\\$\\{.*\\}" incorrect_elements ${stringtocheck})
+    FOREACH(incorrect_element ${incorrect_elements})
+      STRING(REGEX REPLACE "\\$|\\{|\\}" "" correct_element ${incorrect_element})
+      MESSAGE(FATAL_ERROR "In ${filepath}, ${incorrect_element} should be replaced by ${correct_element}")
+    ENDFOREACH()
+
+    INCLUDE(${filepath})
+
+    # Loop over all target library, if it does *NOT* start with "CTK",
+    # let's resolve the variable to access its content
+    FOREACH(target_library ${target_libraries})
+      IF(${target_library} MATCHES "^CTK[a-zA-Z0-9]+$")
+        LIST(APPEND ${varname} ${target_library})
+      ELSE()
+        LIST(APPEND ${varname} "${${target_library}}")
+      ENDIF()
+    ENDFOREACH()
+  ENDIF()
 
-  # Let's make sure target_libraries contains only strings
-  FILE(STRINGS "${filepath}" stringtocheck) # read content of 'filepath' into 'stringtocheck'
-  STRING(REGEX MATCHALL "[^\\#]\\$\\{.*\\}" incorrect_elements ${stringtocheck})
-  FOREACH(incorrect_element ${incorrect_elements})
-    STRING(REGEX REPLACE "\\$|\\{|\\}" "" correct_element ${incorrect_element})
-    MESSAGE(FATAL_ERROR "In ${filepath}, ${incorrect_element} should be replaced by ${correct_element}")
-  ENDFOREACH()
-
-  INCLUDE(${filepath})
+  IF(EXISTS ${manifestpath})
+    # Let's make sure Require-Plugins contains only strings
+    FILE(STRINGS "${manifestpath}" stringtocheck) # read content of 'manifestpath' into 'stringtocheck'
+    STRING(REGEX MATCHALL "[^\\#]\\$\\{.*\\}" incorrect_elements ${stringtocheck})
+    FOREACH(incorrect_element ${incorrect_elements})
+      STRING(REGEX REPLACE "\\$|\\{|\\}" "" correct_element ${incorrect_element})
+      MESSAGE(FATAL_ERROR "In ${manifestpath}, ${incorrect_element} should be replaced by ${correct_element}")
+    ENDFOREACH()
+
+    INCLUDE(${manifestpath})
+
+    # Loop over all plugin dependencies,
+    FOREACH(plugin_symbolicname ${Require-Plugin})
+      STRING(REPLACE "." "_" plugin_library ${plugin_symbolicname})
+      LIST(APPEND ${varname} ${plugin_library})
+    ENDFOREACH()
+  ENDIF()
 
-  # Loop over all target library, if it does *NOT* start with "CTK",
-  # let's resolve the variable to access its content
-  FOREACH(target_library ${target_libraries})
-    IF(${target_library} MATCHES "^CTK[a-zA-Z0-9]+$")
-      LIST(APPEND ${varname} ${target_library})
-    ELSE()
-      LIST(APPEND ${varname} "${${target_library}}")
-    ENDIF()
-  ENDFOREACH()
 ENDMACRO()
 
 #
@@ -63,27 +86,49 @@ MACRO(ctkMacroCollectTargetLibraryNames target_dir varname)
   SET(lib_targets)
 
   SET(filepath ${target_dir}/target_libraries.cmake)
-  #MESSAGE(STATUS filepath:${filepath})
+  SET(manifestpath ${target_dir}/manifest_headers.cmake)
 
-  # Check if "target_libraries.cmake" file exists
-  IF(NOT EXISTS ${filepath})
-    MESSAGE(FATAL_ERROR "${filepath} doesn't exists !")
+  # Check if "target_libraries.cmake" or "manifest_headers.cmake" file exists
+  IF(NOT EXISTS ${filepath} AND NOT EXISTS ${manifestpath})
+    MESSAGE(FATAL_ERROR "${filepath} or ${manifestpath} doesn't exists !")
   ENDIF()
 
-  # Let's make sure target_libraries contains only strings
-  FILE(STRINGS "${filepath}" stringtocheck)
-  STRING(REGEX MATCHALL "[^#]\\$\\{.*\\}" incorrect_elements ${stringtocheck})
-  FOREACH(incorrect_element ${incorrect_elements})
-    STRING(REGEX REPLACE "\\$|\\{|\\}" "" correct_element ${incorrect_element})
-    MESSAGE(FATAL_ERROR "In ${filepath}, ${incorrect_element} should be replaced by ${correct_element}")
-  ENDFOREACH()
-
   # Make sure the variable is cleared
-  SET(target_libraries)
+  SET(target_libraries )
+  SET(Require-Plugin )
 
-  INCLUDE(${filepath})
+  IF(EXISTS ${filepath})
+    # Let's make sure target_libraries contains only strings
+    FILE(STRINGS "${filepath}" stringtocheck) # read content of 'filepath' into 'stringtocheck'
+    STRING(REGEX MATCHALL "[^\\#]\\$\\{.*\\}" incorrect_elements ${stringtocheck})
+    FOREACH(incorrect_element ${incorrect_elements})
+      STRING(REGEX REPLACE "\\$|\\{|\\}" "" correct_element ${incorrect_element})
+      MESSAGE(FATAL_ERROR "In ${filepath}, ${incorrect_element} should be replaced by ${correct_element}")
+    ENDFOREACH()
+
+    INCLUDE(${filepath})
+
+    LIST(APPEND ${varname} ${target_libraries})
+  ENDIF()
+
+  IF(EXISTS ${manifestpath})
+    # Let's make sure Require-Plugins contains only strings
+    FILE(STRINGS "${manifestpath}" stringtocheck) # read content of 'manifestpath' into 'stringtocheck'
+    STRING(REGEX MATCHALL "[^\\#]\\$\\{.*\\}" incorrect_elements ${stringtocheck})
+    FOREACH(incorrect_element ${incorrect_elements})
+      STRING(REGEX REPLACE "\\$|\\{|\\}" "" correct_element ${incorrect_element})
+      MESSAGE(FATAL_ERROR "In ${manifestpath}, ${incorrect_element} should be replaced by ${correct_element}")
+    ENDFOREACH()
+
+    INCLUDE(${manifestpath})
+
+    # Loop over all plugin dependencies
+    FOREACH(plugin_symbolicname ${Require-Plugin})
+      STRING(REPLACE "." "_" plugin_library ${plugin_symbolicname})
+      LIST(APPEND ${varname} ${plugin_library})
+    ENDFOREACH()
+  ENDIF()
 
-  LIST(APPEND ${varname} ${target_libraries})
   LIST(REMOVE_DUPLICATES ${varname})
 ENDMACRO()
 
@@ -121,25 +166,30 @@ MACRO(ctkMacroCollectAllTargetLibraries targets subdir varname)
       ctkMacroCollectTargetLibraryNames(${target_dir} target_libraries)
     ENDIF()
 
-    LIST(APPEND ${varname} ${target_libraries})
-    LIST(REMOVE_DUPLICATES ${varname})
+    IF(target_libraries)
+      LIST(APPEND ${varname} ${target_libraries})
+      LIST(REMOVE_DUPLICATES ${varname})
+    ENDIF()
   ENDFOREACH()
   
 ENDMACRO()
 
 #
-# Extract all library names starting with CTK uppercase
+# Extract all library names starting with CTK uppercase or org_commontk_
 #
 MACRO(ctkMacroGetAllCTKTargetLibraries all_target_libraries varname)
   SET(re_ctklib "^(c|C)(t|T)(k|K)[a-zA-Z0-9]+$")
+  SET(re_ctkplugin "^org_commontk_[a-zA-Z0-9]+$")
   SET(_tmp_list)
   LIST(APPEND _tmp_list ${all_target_libraries})
   ctkMacroListFilter(_tmp_list re_ctklib OUTPUT_VARIABLE ${varname})
+  ctkMacroListFilter(_tmp_list re_ctkplugin)
+  LIST(APPEND ${varname} ${_tmp_list})
   #MESSAGE(STATUS varname:${varname}:${${varname}})
 ENDMACRO()
 
 #
-# Extract all library names *NOT* starting with CTK uppercase
+# Extract all library names *NOT* starting with CTK uppercase or org_commontk_
 #
 MACRO(ctkMacroGetAllNonCTKTargetLibraries all_target_libraries varname)
   ctkMacroGetAllCTKTargetLibraries("${all_target_libraries}" all_ctk_libraries)

+ 24 - 20
CMake/ctkMacroValidateBuildOptions.cmake

@@ -114,11 +114,11 @@ MACRO(ctkMacroValidateBuildOptions dir executable target_directories)
     IF(${${option_name}})
       # Obtain dependency path
       ctkFunctionExecuteProcess(
-        COMMAND "${executable}" "${CTK_BINARY_DIR}/DGraphInput-alldep.txt" -paths ${target_project_name}
+        COMMAND "${executable}" "${CTK_BINARY_DIR}/DGraphInput-alldep.txt" -sort ${target_project_name}
         PATH_LIST \"${QT_INSTALLED_LIBRARY_DIR}\"
         WORKING_DIRECTORY ${CTK_BINARY_DIR}
         RESULT_VARIABLE RESULT_VAR
-        OUTPUT_VARIABLE dep_paths
+        OUTPUT_VARIABLE dep_path
         ERROR_VARIABLE error
         OUTPUT_STRIP_TRAILING_WHITESPACE
         )
@@ -126,27 +126,31 @@ MACRO(ctkMacroValidateBuildOptions dir executable target_directories)
         MESSAGE(FATAL_ERROR "Failed to obtain dependence path of ${subir}.\n${RESULT_VAR}\n${CTK_BINARY_DIR}\n${error}")
       ENDIF()
 
-      FOREACH(dep_path ${dep_paths})
-
-        # Convert 'dep_path' to a list
-        STRING(REPLACE " " "\\;" dep_path_list ${dep_path})
-        SET(dep_path_list ${dep_path_list})
-
-        #MESSAGE("path for ${target_project_name} is: ${dep_path}")
-        
-        # Check if all target included in the dependency path are enabled
-        FOREACH(dep ${dep_path_list})
-          ctkMacroGetOptionName("${target_directories_with_target_name}" ${dep} dep_option)
-          IF(NOT ${${dep_option}})
-            # Enable option
-            MESSAGE(STATUS "Enabling option [${dep_option}] required by [${target_project_name}]")
-            SET(${dep_option} ON CACHE BOOL "Enable ${target_project_name} library" FORCE)
-          ENDIF()
-        ENDFOREACH()
+
+      # Set a variable for each target containing its dependencies
+      # Needed for setting individual include directories for plugins,
+      # depending on other plugins.
+      SET(${target_project_name}_DEPENDENCIES )
+
+      # Convert 'dep_path' to a list
+      SET(dep_path_list ${dep_path})
+      LIST(REMOVE_ITEM dep_path_list ${target_project_name})
+      LIST(APPEND ${target_project_name}_DEPENDENCIES ${dep_path_list})
+
+      #MESSAGE("path for ${target_project_name} is: ${dep_path_list}")
+
+      # Check if all target included in the dependency path are enabled
+      FOREACH(dep ${dep_path_list})
+        ctkMacroGetOptionName("${target_directories_with_target_name}" ${dep} dep_option)
+        IF(NOT ${${dep_option}})
+          # Enable option
+          MESSAGE(STATUS "Enabling option [${dep_option}] required by [${target_project_name}]")
+          SET(${dep_option} ON CACHE BOOL "Enable ${target_project_name} library" FORCE)
+        ENDIF()
       ENDFOREACH()
     ENDIF()
     
   ENDFOREACH()
 
   #MESSAGE(STATUS "Validated: CTK_LIB_*, CTK_PLUGIN_*, CTK_APP_*")
-ENDMACRO()
+ENDMACRO()