Skip to content

Commit

Permalink
Only link to generated pch object when using msvc. (#12957)
Browse files Browse the repository at this point in the history
backend: Only link to generated pch object when using msvc
  • Loading branch information
apache-hb committed Mar 11, 2024
1 parent 675c323 commit e4622ff
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions mesonbuild/compilers/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions mesonbuild/compilers/mixins/visualstudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down

0 comments on commit e4622ff

Please sign in to comment.