pull/9667/head
GustavoLCR 3 years ago committed by Nirbheek Chauhan
parent 8b1e76c56f
commit f8a4e2a591
  1. 62
      mesonbuild/backend/vs2010backend.py

@ -31,6 +31,7 @@ from ..mesonlib import (
) )
from ..environment import Environment, build_filename from ..environment import Environment, build_filename
def autodetect_vs_version(build: T.Optional[build.Build], interpreter: T.Optional[Interpreter]) -> backends.Backend: def autodetect_vs_version(build: T.Optional[build.Build], interpreter: T.Optional[Interpreter]) -> backends.Backend:
vs_version = os.getenv('VisualStudioVersion', None) vs_version = os.getenv('VisualStudioVersion', None)
vs_install_dir = os.getenv('VSINSTALLDIR', None) vs_install_dir = os.getenv('VSINSTALLDIR', None)
@ -61,6 +62,7 @@ def autodetect_vs_version(build: T.Optional[build.Build], interpreter: T.Optiona
raise MesonException('Could not detect Visual Studio using VisualStudioVersion: {!r} or VSINSTALLDIR: {!r}!\n' raise MesonException('Could not detect Visual Studio using VisualStudioVersion: {!r} or VSINSTALLDIR: {!r}!\n'
'Please specify the exact backend to use.'.format(vs_version, vs_install_dir)) 'Please specify the exact backend to use.'.format(vs_version, vs_install_dir))
def split_o_flags_args(args): def split_o_flags_args(args):
""" """
Splits any /O args and returns them. Does not take care of flags overriding Splits any /O args and returns them. Does not take care of flags overriding
@ -82,9 +84,11 @@ def split_o_flags_args(args):
o_flags += ['/O' + f for f in flags] o_flags += ['/O' + f for f in flags]
return o_flags return o_flags
def generate_guid_from_path(path, path_type): def generate_guid_from_path(path, path_type):
return str(uuid.uuid5(uuid.NAMESPACE_URL, 'meson-vs-' + path_type + ':' + str(path))).upper() return str(uuid.uuid5(uuid.NAMESPACE_URL, 'meson-vs-' + path_type + ':' + str(path))).upper()
class Vs2010Backend(backends.Backend): class Vs2010Backend(backends.Backend):
def __init__(self, build: T.Optional[build.Build], interpreter: T.Optional[Interpreter]): def __init__(self, build: T.Optional[build.Build], interpreter: T.Optional[Interpreter]):
super().__init__(build, interpreter) super().__init__(build, interpreter)
@ -519,9 +523,9 @@ class Vs2010Backend(backends.Backend):
def create_basic_project(self, target_name, *, def create_basic_project(self, target_name, *,
temp_dir, temp_dir,
guid, guid,
conftype = 'Utility', conftype='Utility',
target_ext = None, target_ext=None,
target_platform = None): target_platform=None):
root = ET.Element('Project', {'DefaultTargets': "Build", root = ET.Element('Project', {'DefaultTargets': "Build",
'ToolsVersion': '4.0', 'ToolsVersion': '4.0',
'xmlns': 'http://schemas.microsoft.com/developer/msbuild/2003'}) 'xmlns': 'http://schemas.microsoft.com/developer/msbuild/2003'})
@ -587,8 +591,8 @@ class Vs2010Backend(backends.Backend):
def gen_run_target_vcxproj(self, target, ofname, guid): def gen_run_target_vcxproj(self, target, ofname, guid):
(root, type_config) = self.create_basic_project(target.name, (root, type_config) = self.create_basic_project(target.name,
temp_dir = target.get_id(), temp_dir=target.get_id(),
guid = guid) guid=guid)
depend_files = self.get_custom_target_depend_files(target) depend_files = self.get_custom_target_depend_files(target)
if not target.command: if not target.command:
@ -621,9 +625,9 @@ class Vs2010Backend(backends.Backend):
else: else:
platform = self.platform platform = self.platform
(root, type_config) = self.create_basic_project(target.name, (root, type_config) = self.create_basic_project(target.name,
temp_dir = target.get_id(), temp_dir=target.get_id(),
guid = guid, guid=guid,
target_platform = platform) target_platform=platform)
# We need to always use absolute paths because our invocation is always # We need to always use absolute paths because our invocation is always
# from the target dir, not the build root. # from the target dir, not the build root.
target.absolute_paths = True target.absolute_paths = True
@ -874,11 +878,11 @@ class Vs2010Backend(backends.Backend):
tfilename = os.path.splitext(target.get_filename()) tfilename = os.path.splitext(target.get_filename())
(root, type_config) = self.create_basic_project(tfilename[0], (root, type_config) = self.create_basic_project(tfilename[0],
temp_dir = target.get_id(), temp_dir=target.get_id(),
guid = guid, guid=guid,
conftype = conftype, conftype=conftype,
target_ext = tfilename[1], target_ext=tfilename[1],
target_platform = platform) target_platform=platform)
# FIXME: Should these just be set in create_basic_project(), even if # FIXME: Should these just be set in create_basic_project(), even if
# irrelevant for current target? # irrelevant for current target?
@ -952,9 +956,10 @@ class Vs2010Backend(backends.Backend):
ET.SubElement(clconf, 'ExceptionHandling').text = 'SyncCThrow' ET.SubElement(clconf, 'ExceptionHandling').text = 'SyncCThrow'
elif eh.value == 'none': elif eh.value == 'none':
ET.SubElement(clconf, 'ExceptionHandling').text = 'false' ET.SubElement(clconf, 'ExceptionHandling').text = 'false'
else: # 'sc' or 'default' else: # 'sc' or 'default'
ET.SubElement(clconf, 'ExceptionHandling').text = 'Sync' ET.SubElement(clconf, 'ExceptionHandling').text = 'Sync'
generated_files, custom_target_output_files, generated_files_include_dirs = self.generate_custom_generator_commands(target, root) generated_files, custom_target_output_files, generated_files_include_dirs = self.generate_custom_generator_commands(
target, root)
(gen_src, gen_hdrs, gen_objs, gen_langs) = self.split_sources(generated_files) (gen_src, gen_hdrs, gen_objs, gen_langs) = self.split_sources(generated_files)
(custom_src, custom_hdrs, custom_objs, custom_langs) = self.split_sources(custom_target_output_files) (custom_src, custom_hdrs, custom_objs, custom_langs) = self.split_sources(custom_target_output_files)
gen_src += custom_src gen_src += custom_src
@ -1020,8 +1025,8 @@ class Vs2010Backend(backends.Backend):
# reversed is used to keep order of includes # reversed is used to keep order of includes
for i in reversed(d.get_incdirs()): for i in reversed(d.get_incdirs()):
curdir = os.path.join(d.get_curdir(), i) curdir = os.path.join(d.get_curdir(), i)
args.append('-I' + self.relpath(curdir, target.subdir)) # build dir args.append('-I' + self.relpath(curdir, target.subdir)) # build dir
args.append('-I' + os.path.join(proj_to_src_root, curdir)) # src dir args.append('-I' + os.path.join(proj_to_src_root, curdir)) # src dir
for i in d.get_extra_build_dirs(): for i in d.get_extra_build_dirs():
curdir = os.path.join(d.get_curdir(), i) curdir = os.path.join(d.get_curdir(), i)
args.append('-I' + self.relpath(curdir, target.subdir)) # build dir args.append('-I' + self.relpath(curdir, target.subdir)) # build dir
@ -1175,7 +1180,8 @@ class Vs2010Backend(backends.Backend):
# Link args added from the env: LDFLAGS, or the cross file. We want # Link args added from the env: LDFLAGS, or the cross file. We want
# these to override all the defaults but not the per-target link # these to override all the defaults but not the per-target link
# args. # args.
extra_link_args += self.environment.coredata.get_external_link_args(target.for_machine, compiler.get_language()) extra_link_args += self.environment.coredata.get_external_link_args(
target.for_machine, compiler.get_language())
# Only non-static built targets need link args and link dependencies # Only non-static built targets need link args and link dependencies
extra_link_args += target.link_args extra_link_args += target.link_args
# External deps must be last because target link libraries may depend on them. # External deps must be last because target link libraries may depend on them.
@ -1353,7 +1359,8 @@ class Vs2010Backend(backends.Backend):
self.add_additional_options(lang, inc_cl, file_args) self.add_additional_options(lang, inc_cl, file_args)
self.add_preprocessor_defines(lang, inc_cl, file_defines) self.add_preprocessor_defines(lang, inc_cl, file_defines)
self.add_include_dirs(lang, inc_cl, file_inc_dirs) self.add_include_dirs(lang, inc_cl, file_inc_dirs)
ET.SubElement(inc_cl, 'ObjectFileName').text = "$(IntDir)" + self.object_filename_from_source(target, s) ET.SubElement(inc_cl, 'ObjectFileName').text = "$(IntDir)" + \
self.object_filename_from_source(target, s)
for s in gen_src: for s in gen_src:
if path_normalize_add(s, previous_sources): if path_normalize_add(s, previous_sources):
inc_cl = ET.SubElement(inc_src, 'CLCompile', Include=s) inc_cl = ET.SubElement(inc_src, 'CLCompile', Include=s)
@ -1363,7 +1370,8 @@ class Vs2010Backend(backends.Backend):
self.add_preprocessor_defines(lang, inc_cl, file_defines) self.add_preprocessor_defines(lang, inc_cl, file_defines)
self.add_include_dirs(lang, inc_cl, file_inc_dirs) self.add_include_dirs(lang, inc_cl, file_inc_dirs)
s = File.from_built_file(target.get_subdir(), s) s = File.from_built_file(target.get_subdir(), s)
ET.SubElement(inc_cl, 'ObjectFileName').text = "$(IntDir)" + self.object_filename_from_source(target, s) ET.SubElement(inc_cl, 'ObjectFileName').text = "$(IntDir)" + \
self.object_filename_from_source(target, s)
for lang in pch_sources: for lang in pch_sources:
impl = pch_sources[lang][1] impl = pch_sources[lang][1]
if impl and path_normalize_add(impl, previous_sources): if impl and path_normalize_add(impl, previous_sources):
@ -1378,7 +1386,7 @@ class Vs2010Backend(backends.Backend):
else: else:
inc_dirs = file_inc_dirs inc_dirs = file_inc_dirs
self.add_include_dirs(lang, inc_cl, inc_dirs) self.add_include_dirs(lang, inc_cl, inc_dirs)
#XXX: Do we need to set the object file name name here too? # XXX: Do we need to set the object file name name here too?
previous_objects = [] previous_objects = []
if self.has_objects(objects, additional_objects, gen_objs): if self.has_objects(objects, additional_objects, gen_objs):
@ -1400,8 +1408,8 @@ class Vs2010Backend(backends.Backend):
def gen_regenproj(self, project_name, ofname): def gen_regenproj(self, project_name, ofname):
guid = self.environment.coredata.regen_guid guid = self.environment.coredata.regen_guid
(root, type_config) = self.create_basic_project(project_name, (root, type_config) = self.create_basic_project(project_name,
temp_dir = 'regen-temp', temp_dir='regen-temp',
guid = guid) guid=guid)
action = ET.SubElement(root, 'ItemDefinitionGroup') action = ET.SubElement(root, 'ItemDefinitionGroup')
midl = ET.SubElement(action, 'Midl') midl = ET.SubElement(action, 'Midl')
@ -1426,8 +1434,8 @@ class Vs2010Backend(backends.Backend):
def gen_testproj(self, target_name, ofname): def gen_testproj(self, target_name, ofname):
guid = self.environment.coredata.test_guid guid = self.environment.coredata.test_guid
(root, type_config) = self.create_basic_project(target_name, (root, type_config) = self.create_basic_project(target_name,
temp_dir = 'test-temp', temp_dir='test-temp',
guid = guid) guid=guid)
action = ET.SubElement(root, 'ItemDefinitionGroup') action = ET.SubElement(root, 'ItemDefinitionGroup')
midl = ET.SubElement(action, 'Midl') midl = ET.SubElement(action, 'Midl')
@ -1454,8 +1462,8 @@ class Vs2010Backend(backends.Backend):
guid = self.environment.coredata.install_guid guid = self.environment.coredata.install_guid
(root, type_config) = self.create_basic_project(target_name, (root, type_config) = self.create_basic_project(target_name,
temp_dir = 'install-temp', temp_dir='install-temp',
guid = guid) guid=guid)
action = ET.SubElement(root, 'ItemDefinitionGroup') action = ET.SubElement(root, 'ItemDefinitionGroup')
midl = ET.SubElement(action, 'Midl') midl = ET.SubElement(action, 'Midl')

Loading…
Cancel
Save