print >>f, '};'
f.close()
- def write_make_fragment(self, output_path):
+ def get_fragment_dependencies(self):
"""
- write_make_fragment(output_path) -> None
+ get_fragment_dependencies() -> iter
- 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.
+ Compute the list of files (as absolute paths) on which the output
+ fragments depend (i.e., files for which a modification should trigger a
+ rebuild of the fragment).
"""
# Construct a list of all the dependencies of the Makefile fragment
# itself. These include all the LLVMBuild files themselves, as well as
# all of our own sources.
- dependencies = []
for ci in self.component_infos:
- dependencies.append(os.path.join(self.source_root, ci.subpath[1:]))
+ yield os.path.join(self.source_root, ci.subpath[1:],
+ 'LLVMBuild.txt')
# Gather the list of necessary sources by just finding all loaded
# modules that are inside the LLVM source tree.
# If the path exists and is in the source tree, consider it a
# dependency.
if (path.startswith(self.source_root) and os.path.exists(path)):
- dependencies.append(path)
+ yield path
+
+ def write_cmake_fragment(self, output_path):
+ """
+ write_cmake_fragment(output_path) -> None
+
+ Generate a CMake fragment which includes all of the collated LLVMBuild
+ information in a format that is easily digestible by a CMake. The exact
+ contents of this are closely tied to how the CMake configuration
+ integrates LLVMBuild, see CMakeLists.txt in the top-level.
+ """
+
+ dependencies = list(self.get_fragment_dependencies())
+
+ # Write out the CMake fragment.
+ f = open(output_path, 'w')
+
+ # Write the header.
+ header_fmt = '\
+#===-- %s - LLVMBuild Configuration for LLVM %s-*- CMake -*--===#'
+ header_name = os.path.basename(output_path)
+ header_pad = '-' * (80 - len(header_fmt % (header_name, '')))
+ header_string = header_fmt % (header_name, header_pad)
+ print >>f, """\
+%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 CMake based build system.
+#
+# This file is autogenerated by llvm-build, do not edit!
+#
+#===------------------------------------------------------------------------===#
+""" % header_string
+
+ # Write the dependency information in the best way we can.
+ print >>f, """
+# LLVMBuild CMake fragment dependencies.
+#
+# CMake has no builtin way to declare that the configuration depends on
+# a particular file. However, a side effect of configure_file is to add
+# said input file to CMake's internal dependency list. So, we use that
+# and a dummy output file to communicate the dependency information to
+# CMake.
+#
+# FIXME: File a CMake RFE to get a properly supported version of this
+# feature."""
+ for dep in dependencies:
+ print >>f, """\
+configure_file(\"%s\"
+ ${CMAKE_CURRENT_BINARY_DIR}/DummyConfigureOutput)""" % (dep,)
+
+ 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.
f = open(output_path, 'w')
dest="write_library_table", metavar="PATH",
help="Write the C++ library dependency table to PATH",
action="store", default=None)
+ parser.add_option("", "--write-cmake-fragment",
+ dest="write_cmake_fragment", metavar="PATH",
+ help="Write the CMake project information to PATH",
+ action="store", default=None)
parser.add_option("", "--write-make-fragment",
dest="write_make_fragment", metavar="PATH",
help="Write the Makefile project information to PATH",
if opts.write_llvmbuild:
project_info.write_components(opts.write_llvmbuild)
- # Write out the required librariy, if requested.
+ # Write out the required library table, if requested.
if opts.write_library_table:
project_info.write_library_table(opts.write_library_table)
- # Write out the required librariy, if requested.
+ # Write out the make fragment, if requested.
if opts.write_make_fragment:
project_info.write_make_fragment(opts.write_make_fragment)
+ # Write out the cmake fragment, if requested.
+ if opts.write_cmake_fragment:
+ project_info.write_cmake_fragment(opts.write_cmake_fragment)
+
if __name__=='__main__':
main()