llvmbuild/CMake: Update CMake output fragment to include explicit library
authorDaniel Dunbar <daniel@zuster.org>
Tue, 29 Nov 2011 00:06:50 +0000 (00:06 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Tue, 29 Nov 2011 00:06:50 +0000 (00:06 +0000)
dependency information.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@145328 91177308-0d34-0410-b5e6-96231b3b80d8

utils/llvm-build/llvmbuild/componentinfo.py
utils/llvm-build/llvmbuild/main.py

index b9a2d4f1dcedbbcddb7a0c8dad2597158e9f095e..079102f676ae53f07e1344ba2ba811a656178500 100644 (file)
@@ -138,6 +138,23 @@ class LibraryComponentInfo(ComponentInfo):
     def get_library_name(self):
         return self.library_name or self.name
 
+    def get_prefixed_library_name(self):
+        """
+        get_prefixed_library_name() -> str
+
+        Return the library name prefixed by the project name. This is generally
+        what the library name will be on disk.
+        """
+
+        basename = self.get_library_name()
+
+        # FIXME: We need to get the prefix information from an explicit project
+        # object, or something.
+        if basename in ('gtest', 'gtest_main'):
+            return basename
+
+        return 'LLVM%s' % basename
+
     def get_llvmconfig_component_name(self):
         return self.get_library_name().lower()
 
index 21cf39288299b8f87eebe3fa295df20dfaa51a6b..c77ffcd14b349e5671de9cf0248dee33193fe521 100644 (file)
@@ -354,6 +354,37 @@ class LLVMProjectInfo(object):
         print >>f, '};'
         f.close()
 
+    def get_required_libraries_for_component(self, ci, traverse_groups = False):
+        """
+        get_required_libraries_for_component(component_info) -> iter
+
+        Given a Library component info descriptor, return an iterator over all
+        of the directly required libraries for linking with this component. If
+        traverse_groups is True, then library and target groups will be
+        traversed to include their required libraries.
+        """
+
+        assert ci.type_name in ('Library', 'LibraryGroup', 'TargetGroup')
+
+        for name in ci.required_libraries:
+            # Get the dependency info.
+            dep = self.component_info_map[name]
+
+            # If it is a library, yield it.
+            if dep.type_name == 'Library':
+                yield dep
+                continue
+
+            # Otherwise if it is a group, yield or traverse depending on what
+            # was requested.
+            if dep.type_name in ('LibraryGroup', 'TargetGroup'):
+                if not traverse_groups:
+                    yield dep
+                    continue
+
+                for res in self.get_required_libraries_for_component(dep, True):
+                    yield res
+
     def get_fragment_dependencies(self):
         """
         get_fragment_dependencies() -> iter
@@ -447,6 +478,24 @@ configure_file(\"%s\"
                ${CMAKE_CURRENT_BINARY_DIR}/DummyConfigureOutput)""" % (
                 cmake_quote_path(dep),)
 
+        # Write the properties we use to encode the required library dependency
+        # information in a form CMake can easily use directly.
+        print >>f, """
+# Explicit library dependency information.
+#
+# The following property assignments effectively create a map from component
+# names to required libraries, in a way that is easily accessed from CMake."""
+        for ci in self.ordered_component_infos:
+            # We only write the information for libraries currently.
+            if ci.type_name != 'Library':
+                continue
+
+            print >>f, """\
+set_property(GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_%s %s)""" % (
+                ci.get_prefixed_library_name(), " ".join(sorted(
+                     dep.get_prefixed_library_name()
+                     for dep in self.get_required_libraries_for_component(ci))))
+
         f.close()
 
     def write_make_fragment(self, output_path):