From 5086de6f878187f4419351b2b24c766e0d0d25dc Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Tue, 29 Nov 2011 00:06:50 +0000 Subject: [PATCH] llvmbuild/CMake: Update CMake output fragment to include explicit library 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 | 17 +++++++ utils/llvm-build/llvmbuild/main.py | 49 +++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/utils/llvm-build/llvmbuild/componentinfo.py b/utils/llvm-build/llvmbuild/componentinfo.py index b9a2d4f1dce..079102f676a 100644 --- a/utils/llvm-build/llvmbuild/componentinfo.py +++ b/utils/llvm-build/llvmbuild/componentinfo.py @@ -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() diff --git a/utils/llvm-build/llvmbuild/main.py b/utils/llvm-build/llvmbuild/main.py index 21cf3928829..c77ffcd14b3 100644 --- a/utils/llvm-build/llvmbuild/main.py +++ b/utils/llvm-build/llvmbuild/main.py @@ -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):