aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2022-10-13 14:09:40 -0400
committerXavier Claessens <xavier.claessens@collabora.com>2022-10-23 12:21:46 +0200
commit42a7f8e8efe1753bafe535a0be9acb7ed93a4dbb (patch)
treefe4b57f81d4444c4720c80531e1289ad5abdddb2
parent65590e6e4b59e08d0c1a16067524479ed822ad27 (diff)
downloadmeson-42a7f8e8efe1753bafe535a0be9acb7ed93a4dbb.zip
meson-42a7f8e8efe1753bafe535a0be9acb7ed93a4dbb.tar.gz
meson-42a7f8e8efe1753bafe535a0be9acb7ed93a4dbb.tar.bz2
vs backend: Add support for CompileTarget
Since vs backend only support the C compiler, everything else are custom targets. Convert CompileTarget into a Generator to reuse existing code. This will be useful in the future to support transpilers, and assemblers.
-rw-r--r--mesonbuild/backend/backends.py27
-rw-r--r--mesonbuild/backend/vs2010backend.py19
2 files changed, 46 insertions, 0 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
index 9776642..32f24e9 100644
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -50,6 +50,8 @@ if T.TYPE_CHECKING:
from typing_extensions import TypedDict
+ _ALL_SOURCES_TYPE = T.List[T.Union[File, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList]]
+
class TargetIntrospectionData(TypedDict):
language: str
@@ -1864,3 +1866,28 @@ class Backend:
else:
env.prepend('PATH', list(extra_paths))
return env
+
+ def compiler_to_generator(self, target: build.BuildTarget,
+ compiler: 'Compiler',
+ sources: _ALL_SOURCES_TYPE,
+ output_templ: str) -> build.GeneratedList:
+ '''
+ Some backends don't support custom compilers. This is a convenience
+ method to convert a Compiler to a Generator.
+ '''
+ exelist = compiler.get_exelist()
+ exe = programs.ExternalProgram(exelist[0])
+ args = exelist[1:]
+ # FIXME: There are many other args missing
+ commands = self.generate_basic_compiler_args(target, compiler)
+ commands += compiler.get_dependency_gen_args('@OUTPUT@', '@DEPFILE@')
+ commands += compiler.get_output_args('@OUTPUT@')
+ commands += compiler.get_compile_only_args() + ['@INPUT@']
+ commands += self.get_source_dir_include_args(target, compiler)
+ commands += self.get_build_dir_include_args(target, compiler)
+ generator = build.Generator(exe, args + commands.to_native(), [output_templ], depfile='@PLAINNAME@.d')
+ return generator.process_files(sources, self.interpreter)
+
+ def compile_target_to_generator(self, target: build.CompileTarget) -> build.GeneratedList:
+ all_sources = T.cast('_ALL_SOURCES_TYPE', target.sources) + T.cast('_ALL_SOURCES_TYPE', target.generated)
+ return self.compiler_to_generator(target, target.compiler, all_sources, target.output_templ)
diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py
index 98d69e7..f81e878 100644
--- a/mesonbuild/backend/vs2010backend.py
+++ b/mesonbuild/backend/vs2010backend.py
@@ -683,6 +683,23 @@ class Vs2010Backend(backends.Backend):
self.add_target_deps(root, target)
self._prettyprint_vcxproj_xml(ET.ElementTree(root), ofname)
+ def gen_compile_target_vcxproj(self, target, ofname, guid):
+ if target.for_machine is MachineChoice.BUILD:
+ platform = self.build_platform
+ else:
+ platform = self.platform
+ (root, type_config) = self.create_basic_project(target.name,
+ temp_dir=target.get_id(),
+ guid=guid,
+ target_platform=platform)
+ ET.SubElement(root, 'Import', Project=r'$(VCTargetsPath)\Microsoft.Cpp.targets')
+ target.generated = [self.compile_target_to_generator(target)]
+ target.sources = []
+ self.generate_custom_generator_commands(target, root)
+ self.add_regen_dependency(root)
+ self.add_target_deps(root, target)
+ self._prettyprint_vcxproj_xml(ET.ElementTree(root), ofname)
+
@classmethod
def lang_from_source_file(cls, src):
ext = src.split('.')[-1]
@@ -876,6 +893,8 @@ class Vs2010Backend(backends.Backend):
return self.gen_custom_target_vcxproj(target, ofname, guid)
elif isinstance(target, build.RunTarget):
return self.gen_run_target_vcxproj(target, ofname, guid)
+ elif isinstance(target, build.CompileTarget):
+ return self.gen_compile_target_vcxproj(target, ofname, guid)
else:
raise MesonException(f'Unknown target type for {target.get_basename()}')
# Prefix to use to access the build root from the vcxproj dir