llvm.org GIT mirror llvm / 71481ee
llvm-build: Factor out duplicate cmake export listing. Patch by Brad King. The write_cmake_fragment and write_cmake_exports_fragment methods share some logic for selecting libraries that CMake needs to know about. Factor it out into a helper to avoid duplication. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245716 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Liew 5 years ago
1 changed file(s) with 36 addition(s) and 27 deletion(s). Raw diff Collapse all Expand all
500500 if (path.startswith(self.source_root) and os.path.exists(path)):
501501 yield path
502502
503 def foreach_cmake_library(self, f,
504 enabled_optional_components,
505 skip_disabled):
506 for ci in self.ordered_component_infos:
507 # Skip optional components which are not enabled.
508 if ci.type_name == 'OptionalLibrary' \
509 and ci.name not in enabled_optional_components:
510 continue
511
512 # We only write the information for libraries currently.
513 if ci.type_name not in ('Library', 'OptionalLibrary'):
514 continue
515
516 # Skip disabled targets.
517 if skip_disabled:
518 tg = ci.get_parent_target_group()
519 if tg and not tg.enabled:
520 continue
521
522 f(ci)
523
524
503525 def write_cmake_fragment(self, output_path, enabled_optional_components):
504526 """
505527 write_cmake_fragment(output_path) -> None
568590 # The following property assignments effectively create a map from component
569591 # names to required libraries, in a way that is easily accessed from CMake.
570592 """)
571 for ci in self.ordered_component_infos:
572 # Skip optional components which are not enabled.
573 if ci.type_name == 'OptionalLibrary' \
574 and ci.name not in enabled_optional_components:
575 continue
576
577 # We only write the information for certain components currently.
578 if ci.type_name not in ('Library', 'OptionalLibrary'):
579 continue
580
581 f.write("""\
593 self.foreach_cmake_library(
594 lambda ci:
595 f.write("""\
582596 set_property(GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_%s %s)\n""" % (
583597 ci.get_prefixed_library_name(), " ".join(sorted(
584598 dep.get_prefixed_library_name()
585599 for dep in self.get_required_libraries_for_component(ci)))))
600 ,
601 enabled_optional_components,
602 skip_disabled = False
603 )
586604
587605 f.close()
588606
607625 # The following property assignments tell CMake about link
608626 # dependencies of libraries imported from LLVM.
609627 """)
610 for ci in self.ordered_component_infos:
611 # Skip optional components which are not enabled.
612 if ci.type_name == 'OptionalLibrary' \
613 and ci.name not in enabled_optional_components:
614 continue
615
616 # We only write the information for libraries currently.
617 if ci.type_name not in ('Library', 'OptionalLibrary'):
618 continue
619
620 # Skip disabled targets.
621 tg = ci.get_parent_target_group()
622 if tg and not tg.enabled:
623 continue
624
625 f.write("""\
628 self.foreach_cmake_library(
629 lambda ci:
630 f.write("""\
626631 set_property(TARGET %s PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES %s)\n""" % (
627632 ci.get_prefixed_library_name(), " ".join(sorted(
628633 dep.get_prefixed_library_name()
629634 for dep in self.get_required_libraries_for_component(ci)))))
635 ,
636 enabled_optional_components,
637 skip_disabled = True
638 )
630639
631640 f.close()
632641