Skip to content

Commit e4622ff

Browse files
authored
Only link to generated pch object when using msvc. (mesonbuild#12957)
backend: Only link to generated pch object when using msvc
1 parent 675c323 commit e4622ff

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

mesonbuild/backend/ninjabackend.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3121,7 +3121,10 @@ def generate_msvc_pch_command(self, target, compiler, pch):
31213121
commands += self._generate_single_compile(target, compiler)
31223122
commands += self.get_compile_debugfile_args(compiler, target, objname)
31233123
dep = dst + '.' + compiler.get_depfile_suffix()
3124-
return commands, dep, dst, [objname], source
3124+
3125+
link_objects = [objname] if compiler.should_link_pch_object() else []
3126+
3127+
return commands, dep, dst, link_objects, source
31253128

31263129
def generate_gcc_pch_command(self, target, compiler, pch):
31273130
commands = self._generate_single_compile(target, compiler)

mesonbuild/compilers/compilers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,9 @@ def get_colorout_args(self, colortype: str) -> T.List[str]:
843843
def get_compile_debugfile_args(self, rel_obj: str, pch: bool = False) -> T.List[str]:
844844
return []
845845

846+
def should_link_pch_object(self) -> bool:
847+
return False
848+
846849
def get_link_debugfile_name(self, targetfile: str) -> T.Optional[str]:
847850
return self.linker.get_debugfile_name(targetfile)
848851

mesonbuild/compilers/mixins/visualstudio.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,10 @@ def get_instruction_set_args(self, instruction_set: str) -> T.Optional[T.List[st
425425
def get_pch_base_name(self, header: str) -> str:
426426
return os.path.basename(header)
427427

428+
# MSVC requires linking to the generated object file when linking a build target
429+
# that uses a precompiled header
430+
def should_link_pch_object(self) -> bool:
431+
return True
428432

429433
class ClangClCompiler(VisualStudioLikeCompiler):
430434

0 commit comments

Comments
 (0)