From e4622ff1eebec393531d731cafa71334f900f121 Mon Sep 17 00:00:00 2001 From: Elliot <35050275+apache-hb@users.noreply.github.com> Date: Mon, 11 Mar 2024 14:23:33 -0400 Subject: [PATCH] Only link to generated pch object when using msvc. (#12957) backend: Only link to generated pch object when using msvc --- mesonbuild/backend/ninjabackend.py | 5 ++++- mesonbuild/compilers/compilers.py | 3 +++ mesonbuild/compilers/mixins/visualstudio.py | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index f665e610adc6..f7ba6468a495 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -3121,7 +3121,10 @@ def generate_msvc_pch_command(self, target, compiler, pch): commands += self._generate_single_compile(target, compiler) commands += self.get_compile_debugfile_args(compiler, target, objname) dep = dst + '.' + compiler.get_depfile_suffix() - return commands, dep, dst, [objname], source + + link_objects = [objname] if compiler.should_link_pch_object() else [] + + return commands, dep, dst, link_objects, source def generate_gcc_pch_command(self, target, compiler, pch): commands = self._generate_single_compile(target, compiler) diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index b59733745806..8bc1294f8ae7 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -843,6 +843,9 @@ def get_colorout_args(self, colortype: str) -> T.List[str]: def get_compile_debugfile_args(self, rel_obj: str, pch: bool = False) -> T.List[str]: return [] + def should_link_pch_object(self) -> bool: + return False + def get_link_debugfile_name(self, targetfile: str) -> T.Optional[str]: return self.linker.get_debugfile_name(targetfile) diff --git a/mesonbuild/compilers/mixins/visualstudio.py b/mesonbuild/compilers/mixins/visualstudio.py index 5dcebecef8ec..d6ebd6e0d3ab 100644 --- a/mesonbuild/compilers/mixins/visualstudio.py +++ b/mesonbuild/compilers/mixins/visualstudio.py @@ -425,6 +425,10 @@ def get_instruction_set_args(self, instruction_set: str) -> T.Optional[T.List[st def get_pch_base_name(self, header: str) -> str: return os.path.basename(header) + # MSVC requires linking to the generated object file when linking a build target + # that uses a precompiled header + def should_link_pch_object(self) -> bool: + return True class ClangClCompiler(VisualStudioLikeCompiler):