Filter libraries that are not installed out of CMake exports (currently
[oota-llvm.git] / utils / llvm-build / llvmbuild / main.py
index 5742b05d4f965cff790027718dddce282576c9ed..78bd7967ad01010ba040303373930c4f4e511041 100644 (file)
@@ -503,7 +503,8 @@ subdirectories = %s
 
     def foreach_cmake_library(self, f,
                               enabled_optional_components,
-                              skip_disabled):
+                              skip_disabled,
+                              skip_not_installed):
         for ci in self.ordered_component_infos:
             # Skip optional components which are not enabled.
             if ci.type_name == 'OptionalLibrary' \
@@ -520,6 +521,10 @@ subdirectories = %s
                 if tg and not tg.enabled:
                     continue
 
+            # Skip targets that will not be installed
+            if skip_not_installed and not ci.installed:
+                continue
+
             f(ci)
 
 
@@ -600,7 +605,8 @@ set_property(GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_%s %s)\n""" % (
                      for dep in self.get_required_libraries_for_component(ci)))))
             ,
             enabled_optional_components,
-            skip_disabled = False
+            skip_disabled = False,
+            skip_not_installed = False # Dependency info must be emitted for internals libs too
             )
 
         f.close()
@@ -635,12 +641,13 @@ set_property(TARGET %s PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES %s)\n""" % (
                      for dep in self.get_required_libraries_for_component(ci)))))
             ,
             enabled_optional_components,
-            skip_disabled = True
+            skip_disabled = True,
+            skip_not_installed = True # Do not export internal libraries like gtest
             )
 
         f.close()
 
-    def write_make_fragment(self, output_path):
+    def write_make_fragment(self, output_path, enabled_optional_components):
         """
         write_make_fragment(output_path) -> None
 
@@ -706,6 +713,19 @@ set_property(TARGET %s PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES %s)\n""" % (
             f.write("%s:\n" % (mk_quote_string_for_target(dep),))
         f.write('endif\n')
 
+        f.write("""
+# List of libraries to be exported for use by applications.
+# See 'cmake/modules/Makefile'.
+LLVM_LIBS_TO_EXPORT :=""")
+        self.foreach_cmake_library(
+            lambda ci:
+                f.write(' \\\n  %s' % ci.get_prefixed_library_name())
+            ,
+            enabled_optional_components,
+            skip_disabled = True,
+            skip_not_installed = True # Do not export internal libraries like gtest
+            )
+        f.write('\n')
         f.close()
 
 def add_magic_target_components(parser, project, opts):
@@ -929,7 +949,8 @@ given by --build-root) at the same SUBPATH""",
 
     # Write out the make fragment, if requested.
     if opts.write_make_fragment:
-        project_info.write_make_fragment(opts.write_make_fragment)
+        project_info.write_make_fragment(opts.write_make_fragment,
+                                         opts.optional_components)
 
     # Write out the cmake fragment, if requested.
     if opts.write_cmake_fragment: