diff options
Diffstat (limited to 'mesonbuild/backend/vs2010backend.py')
-rw-r--r-- | mesonbuild/backend/vs2010backend.py | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py index ec10d4c..3afe3cd 100644 --- a/mesonbuild/backend/vs2010backend.py +++ b/mesonbuild/backend/vs2010backend.py @@ -16,6 +16,8 @@ import os, sys import pickle from mesonbuild import compilers +from mesonbuild.build import BuildTarget +from mesonbuild.mesonlib import File from . import backends from .. import build from .. import dependencies @@ -35,8 +37,35 @@ class Vs2010Backend(backends.Backend): def __init__(self, build): super().__init__(build) self.project_file_version = '10.0.30319.1' - # foo.c compiles to foo.obj, not foo.c.obj - self.source_suffix_in_objs = False + self.sources_conflicts = {} + + def object_filename_from_source(self, target, source): + basename = os.path.basename(source.fname) + filename_without_extension = '.'.join(basename.split('.')[:-1]) + if basename in self.sources_conflicts[target.get_id()]: + # If there are multiple source files with the same basename, we must resolve the conflict + # by giving each a unique object output file. + filename_without_extension = '.'.join(source.fname.split('.')[:-1]).replace('/', '_').replace('\\', '_') + return filename_without_extension + '.' + self.environment.get_object_suffix() + + def resolve_source_conflicts(self): + for name, target in self.build.targets.items(): + if not isinstance(target, BuildTarget): + continue + conflicts = {} + for s in target.get_sources(): + if hasattr(s, 'held_object'): + s = s.held_object + if not isinstance(s, File): + continue + basename = os.path.basename(s.fname) + conflicting_sources = conflicts.get(basename, None) + if conflicting_sources is None: + conflicting_sources = [] + conflicts[basename] = conflicting_sources + conflicting_sources.append(s) + self.sources_conflicts[target.get_id()] = {name: src_conflicts for name, src_conflicts in conflicts.items() + if len(src_conflicts) > 1} def generate_custom_generator_commands(self, target, parent_node): all_output_files = [] @@ -86,6 +115,7 @@ class Vs2010Backend(backends.Backend): return all_output_files def generate(self, interp): + self.resolve_source_conflicts() self.interpreter = interp self.platform = 'Win32' self.buildtype = self.environment.coredata.get_builtin_option('buildtype') @@ -525,7 +555,7 @@ class Vs2010Backend(backends.Backend): linkname = os.path.join(rel_path, lobj.get_import_filename()) additional_links.append(linkname) additional_objects = [] - for o in self.flatten_object_list(target, down, include_dir_names=False): + for o in self.flatten_object_list(target, down): assert(isinstance(o, str)) additional_objects.append(o) if len(additional_links) > 0: @@ -566,6 +596,9 @@ class Vs2010Backend(backends.Backend): inc_cl = ET.SubElement(inc_src, 'CLCompile', Include=relpath) self.add_pch(inc_cl, proj_to_src_dir, pch_sources, s) self.add_additional_options(s, inc_cl, extra_args, additional_options_set) + basename = os.path.basename(s.fname) + if basename in self.sources_conflicts[target.get_id()]: + ET.SubElement(inc_cl, 'ObjectFileName').text = "$(IntDir)" + self.object_filename_from_source(target, s) for s in gen_src: relpath = self.relpath(s, target.subdir) inc_cl = ET.SubElement(inc_src, 'CLCompile', Include=relpath) |