+ def write_cmake_exports_fragment(self, output_path, enabled_optional_components):
+ """
+ write_cmake_exports_fragment(output_path) -> None
+
+ Generate a CMake fragment which includes LLVMBuild library
+ dependencies expressed similarly to how CMake would write
+ them via install(EXPORT).
+ """
+
+ dependencies = list(self.get_fragment_dependencies())
+
+ # Write out the CMake exports fragment.
+ make_install_dir(os.path.dirname(output_path))
+ f = open(output_path, 'w')
+
+ f.write("""\
+# Explicit library dependency information.
+#
+# The following property assignments tell CMake about link
+# dependencies of libraries imported from LLVM.
+""")
+ for ci in self.ordered_component_infos:
+ # Skip optional components which are not enabled.
+ if ci.type_name == 'OptionalLibrary' \
+ and ci.name not in enabled_optional_components:
+ continue
+
+ # We only write the information for libraries currently.
+ if ci.type_name not in ('Library', 'OptionalLibrary'):
+ continue
+
+ # Skip disabled targets.
+ tg = ci.get_parent_target_group()
+ if tg and not tg.enabled:
+ continue
+
+ f.write("""\
+set_property(TARGET %s PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES %s)\n""" % (
+ 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):
+ """
+ write_make_fragment(output_path) -> None
+
+ Generate a Makefile fragment which includes all of the collated
+ LLVMBuild information in a format that is easily digestible by a
+ Makefile. The exact contents of this are closely tied to how the LLVM
+ Makefiles integrate LLVMBuild, see Makefile.rules in the top-level.
+ """
+
+ dependencies = list(self.get_fragment_dependencies())
+
+ # Write out the Makefile fragment.
+ make_install_dir(os.path.dirname(output_path))
+ f = open(output_path, 'w')
+
+ # Write the header.
+ header_fmt = '\
+#===-- %s - LLVMBuild Configuration for LLVM %s-*- Makefile -*--===#'
+ header_name = os.path.basename(output_path)
+ header_pad = '-' * (80 - len(header_fmt % (header_name, '')))
+ header_string = header_fmt % (header_name, header_pad)
+ f.write("""\
+%s
+#
+# The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+#===------------------------------------------------------------------------===#
+#
+# This file contains the LLVMBuild project information in a format easily
+# consumed by the Makefile based build system.
+#
+# This file is autogenerated by llvm-build, do not edit!
+#
+#===------------------------------------------------------------------------===#
+
+""" % header_string)
+
+ # Write the dependencies for the fragment.
+ #
+ # FIXME: Technically, we need to properly quote for Make here.
+ f.write("""\
+# Clients must explicitly enable LLVMBUILD_INCLUDE_DEPENDENCIES to get
+# these dependencies. This is a compromise to help improve the
+# performance of recursive Make systems.
+""")
+ f.write('ifeq ($(LLVMBUILD_INCLUDE_DEPENDENCIES),1)\n')
+ f.write("# The dependencies for this Makefile fragment itself.\n")
+ f.write("%s: \\\n" % (mk_quote_string_for_target(output_path),))
+ for dep in dependencies:
+ f.write("\t%s \\\n" % (dep,))
+ f.write('\n')
+
+ # Generate dummy rules for each of the dependencies, so that things
+ # continue to work correctly if any of those files are moved or removed.
+ f.write("""\
+# The dummy targets to allow proper regeneration even when files are moved or
+# removed.
+""")
+ for dep in dependencies:
+ f.write("%s:\n" % (mk_quote_string_for_target(dep),))
+ f.write('endif\n')
+
+ f.close()
+
+def add_magic_target_components(parser, project, opts):
+ """add_magic_target_components(project, opts) -> None
+
+ Add the "magic" target based components to the project, which can only be
+ determined based on the target configuration options.
+
+ This currently is responsible for populating the required_libraries list of
+ the "all-targets", "Native", "NativeCodeGen", and "Engine" components.
+ """
+
+ # Determine the available targets.
+ available_targets = dict((ci.name,ci)
+ for ci in project.component_infos
+ if ci.type_name == 'TargetGroup')
+
+ # Find the configured native target.
+
+ # We handle a few special cases of target names here for historical
+ # reasons, as these are the names configure currently comes up with.
+ native_target_name = { 'x86' : 'X86',
+ 'x86_64' : 'X86',
+ 'Unknown' : None }.get(opts.native_target,
+ opts.native_target)
+ if native_target_name is None:
+ native_target = None
+ else:
+ native_target = available_targets.get(native_target_name)
+ if native_target is None:
+ parser.error("invalid native target: %r (not in project)" % (
+ opts.native_target,))
+ if native_target.type_name != 'TargetGroup':
+ parser.error("invalid native target: %r (not a target)" % (
+ opts.native_target,))
+
+ # Find the list of targets to enable.
+ if opts.enable_targets is None:
+ enable_targets = available_targets.values()
+ else:
+ # We support both space separated and semi-colon separated lists.
+ if opts.enable_targets == '':
+ enable_target_names = []
+ elif ' ' in opts.enable_targets:
+ enable_target_names = opts.enable_targets.split()
+ else:
+ enable_target_names = opts.enable_targets.split(';')
+
+ enable_targets = []
+ for name in enable_target_names:
+ target = available_targets.get(name)
+ if target is None:
+ parser.error("invalid target to enable: %r (not in project)" % (
+ name,))
+ if target.type_name != 'TargetGroup':
+ parser.error("invalid target to enable: %r (not a target)" % (
+ name,))
+ enable_targets.append(target)
+
+ # Find the special library groups we are going to populate. We enforce that
+ # these appear in the project (instead of just adding them) so that they at
+ # least have an explicit representation in the project LLVMBuild files (and
+ # comments explaining how they are populated).
+ def find_special_group(name):
+ info = info_map.get(name)
+ if info is None:
+ fatal("expected project to contain special %r component" % (
+ name,))
+
+ if info.type_name != 'LibraryGroup':
+ fatal("special component %r should be a LibraryGroup" % (
+ name,))
+
+ if info.required_libraries:
+ fatal("special component %r must have empty %r list" % (
+ name, 'required_libraries'))
+ if info.add_to_library_groups:
+ fatal("special component %r must have empty %r list" % (
+ name, 'add_to_library_groups'))
+
+ info._is_special_group = True
+ return info
+
+ info_map = dict((ci.name, ci) for ci in project.component_infos)
+ all_targets = find_special_group('all-targets')
+ native_group = find_special_group('Native')
+ native_codegen_group = find_special_group('NativeCodeGen')
+ engine_group = find_special_group('Engine')
+
+ # Set the enabled bit in all the target groups, and append to the
+ # all-targets list.
+ for ci in enable_targets:
+ all_targets.required_libraries.append(ci.name)
+ ci.enabled = True
+
+ # If we have a native target, then that defines the native and
+ # native_codegen libraries.
+ if native_target and native_target.enabled:
+ native_group.required_libraries.append(native_target.name)
+ native_codegen_group.required_libraries.append(
+ '%sCodeGen' % native_target.name)
+
+ # If we have a native target with a JIT, use that for the engine. Otherwise,
+ # use the interpreter.
+ if native_target and native_target.enabled and native_target.has_jit:
+ engine_group.required_libraries.append('MCJIT')
+ engine_group.required_libraries.append(native_group.name)
+ else:
+ engine_group.required_libraries.append('Interpreter')
+