The generator class for handling EXE and SHARED_LIB creation.
| 567 | |
| 568 | |
| 569 | class LinkingGenerator (generators.Generator): |
| 570 | """ The generator class for handling EXE and SHARED_LIB creation. |
| 571 | """ |
| 572 | def __init__ (self, id, composing, source_types, target_types_and_names, requirements): |
| 573 | generators.Generator.__init__ (self, id, composing, source_types, target_types_and_names, requirements) |
| 574 | |
| 575 | def run (self, project, name, prop_set, sources): |
| 576 | |
| 577 | sources.extend(prop_set.get('<library>')) |
| 578 | |
| 579 | # Add <library-path> properties for all searched libraries |
| 580 | extra = [] |
| 581 | for s in sources: |
| 582 | if s.type () == 'SEARCHED_LIB': |
| 583 | search = s.search() |
| 584 | extra.extend(property.Property('<library-path>', sp) for sp in search) |
| 585 | |
| 586 | # It's possible that we have libraries in sources which did not came |
| 587 | # from 'lib' target. For example, libraries which are specified |
| 588 | # just as filenames as sources. We don't have xdll-path properties |
| 589 | # for such target, but still need to add proper dll-path properties. |
| 590 | extra_xdll_path = [] |
| 591 | for s in sources: |
| 592 | if type.is_derived (s.type (), 'SHARED_LIB') and not s.action (): |
| 593 | # Unfortunately, we don't have a good way to find the path |
| 594 | # to a file, so use this nasty approach. |
| 595 | p = s.project() |
| 596 | location = path.root(s.name(), p.get('source-location')[0]) |
| 597 | extra_xdll_path.append(os.path.dirname(location)) |
| 598 | |
| 599 | # Hardcode DLL paths only when linking executables. |
| 600 | # Pros: do not need to relink libraries when installing. |
| 601 | # Cons: "standalone" libraries (plugins, python extensions) can not |
| 602 | # hardcode paths to dependent libraries. |
| 603 | if prop_set.get('<hardcode-dll-paths>') == ['true'] \ |
| 604 | and type.is_derived(self.target_types_ [0], 'EXE'): |
| 605 | xdll_path = prop_set.get('<xdll-path>') |
| 606 | extra.extend(property.Property('<dll-path>', sp) \ |
| 607 | for sp in extra_xdll_path) |
| 608 | extra.extend(property.Property('<dll-path>', sp) \ |
| 609 | for sp in xdll_path) |
| 610 | |
| 611 | if extra: |
| 612 | prop_set = prop_set.add_raw (extra) |
| 613 | result = generators.Generator.run(self, project, name, prop_set, sources) |
| 614 | |
| 615 | if result: |
| 616 | ur = self.extra_usage_requirements(result, prop_set) |
| 617 | ur = ur.add(property_set.create(['<xdll-path>' + p for p in extra_xdll_path])) |
| 618 | else: |
| 619 | return None |
| 620 | return (ur, result) |
| 621 | |
| 622 | def extra_usage_requirements (self, created_targets, prop_set): |
| 623 | |
| 624 | result = property_set.empty () |
| 625 | extra = [] |
| 626 |