| 
 | 1 | +define_property(DIRECTORY PROPERTY LLDB_PLUGIN_KIND)  | 
 | 2 | +define_property(TARGET PROPERTY LLDB_PLUGIN_KIND INHERITED)  | 
 | 3 | + | 
 | 4 | +define_property(DIRECTORY PROPERTY LLDB_ACCEPTABLE_PLUGIN_DEPENDENCIES)  | 
 | 5 | +define_property(TARGET PROPERTY LLDB_ACCEPTABLE_PLUGIN_DEPENDENCIES INHERITED)  | 
 | 6 | + | 
 | 7 | +define_property(DIRECTORY PROPERTY LLDB_TOLERATED_PLUGIN_DEPENDENCIES)  | 
 | 8 | +define_property(TARGET PROPERTY LLDB_TOLERATED_PLUGIN_DEPENDENCIES INHERITED)  | 
 | 9 | + | 
 | 10 | +option(LLDB_GENERATE_PLUGIN_DEP_GRAPH OFF)  | 
 | 11 | + | 
 | 12 | +function(check_lldb_plugin_layering)  | 
 | 13 | +  get_property(plugins GLOBAL PROPERTY LLDB_PLUGINS)  | 
 | 14 | +  foreach(plugin ${plugins})  | 
 | 15 | +    get_property(plugin_kind TARGET ${plugin} PROPERTY LLDB_PLUGIN_KIND)  | 
 | 16 | +    get_property(acceptable_deps TARGET ${plugin}  | 
 | 17 | +      PROPERTY LLDB_ACCEPTABLE_PLUGIN_DEPENDENCIES)  | 
 | 18 | +    get_property(tolerated_deps TARGET ${plugin}  | 
 | 19 | +      PROPERTY LLDB_TOLERATED_PLUGIN_DEPENDENCIES)  | 
 | 20 | + | 
 | 21 | +    # A plugin is always permitted to depend on its own kind for the purposes  | 
 | 22 | +    # subclassing. Ideally the intra-kind dependencies should not form a loop,  | 
 | 23 | +    # but we're not checking that here.  | 
 | 24 | +    list(APPEND acceptable_deps ${plugin_kind})  | 
 | 25 | + | 
 | 26 | +    list(APPEND all_plugin_kinds ${plugin_kind})  | 
 | 27 | + | 
 | 28 | +    get_property(link_libs TARGET ${plugin} PROPERTY LINK_LIBRARIES)  | 
 | 29 | +    foreach(link_lib ${link_libs})  | 
 | 30 | +      if(link_lib IN_LIST plugins)  | 
 | 31 | +        get_property(lib_kind TARGET ${link_lib} PROPERTY LLDB_PLUGIN_KIND)  | 
 | 32 | +        if (lib_kind)  | 
 | 33 | +          if (lib_kind IN_LIST acceptable_deps)  | 
 | 34 | +            set(dep_kind green)  | 
 | 35 | +          elseif (lib_kind IN_LIST tolerated_deps)  | 
 | 36 | +            set(dep_kind yellow)  | 
 | 37 | +          else()  | 
 | 38 | +            set(dep_kind red)  | 
 | 39 | +            message(SEND_ERROR "Plugin ${plugin} cannot depend on ${lib_kind} "  | 
 | 40 | +              "plugin ${link_lib}")  | 
 | 41 | +          endif()  | 
 | 42 | +          list(APPEND dep_${dep_kind}_${plugin_kind}_${lib_kind} ${plugin})  | 
 | 43 | +        endif()  | 
 | 44 | +      endif()  | 
 | 45 | +    endforeach()  | 
 | 46 | +  endforeach()  | 
 | 47 | + | 
 | 48 | +  if (LLDB_GENERATE_PLUGIN_DEP_GRAPH)  | 
 | 49 | +    set(dep_graph "digraph Plugins {\n")  | 
 | 50 | +    list(REMOVE_DUPLICATES all_plugin_kinds)  | 
 | 51 | +    foreach (from ${all_plugin_kinds})  | 
 | 52 | +      foreach (to ${all_plugin_kinds})  | 
 | 53 | +        foreach (dep_kind green yellow red)  | 
 | 54 | +          if (dep_${dep_kind}_${from}_${to})  | 
 | 55 | +            list(REMOVE_DUPLICATES dep_${dep_kind}_${from}_${to})  | 
 | 56 | +            string(REGEX REPLACE "lldbPlugin|${from}" "" short_deps  | 
 | 57 | +              "${dep_${dep_kind}_${from}_${to}}")  | 
 | 58 | +            string(JOIN "\n" plugins ${short_deps})  | 
 | 59 | +            string(APPEND dep_graph  | 
 | 60 | +              "  ${from}->${to}[color=\"${dep_kind}\" label=\"${plugins}\"];\n")  | 
 | 61 | +          endif()  | 
 | 62 | +        endforeach()  | 
 | 63 | +      endforeach()  | 
 | 64 | +    endforeach()  | 
 | 65 | +    string(APPEND dep_graph "}\n")  | 
 | 66 | +    file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/lldb-plugin-deps.dot" "${dep_graph}")  | 
 | 67 | +  endif()  | 
 | 68 | +endfunction()  | 
0 commit comments