extract_all_objects: Include PCH object with MSVC

This changes the object file name with ninja backend to match the
name used by vs backend and add it in outputs of the ninja rule.
pull/11742/head
Xavier Claessens 2 years ago
parent 25f4f77a3b
commit ff86e799a4
  1. 18
      mesonbuild/backend/backends.py
  2. 2
      mesonbuild/backend/ninjabackend.py
  3. 3
      mesonbuild/build.py
  4. 2
      mesonbuild/compilers/mixins/visualstudio.py

@ -842,6 +842,8 @@ class Backend:
def _determine_ext_objs(self, extobj: 'build.ExtractedObjects', proj_dir_to_build_root: str) -> T.List[str]:
result: T.List[str] = []
targetdir = self.get_target_private_dir(extobj.target)
# Merge sources and generated sources
raw_sources = list(extobj.srclist)
for gensrc in extobj.genlist:
@ -858,12 +860,18 @@ class Backend:
elif self.environment.is_object(s):
result.append(s.relative_name())
# MSVC generate an object file for PCH
if extobj.pch:
for lang, pch in extobj.target.pch.items():
compiler = extobj.target.compilers[lang]
if compiler.get_argument_syntax() == 'msvc':
objname = self.get_msvc_pch_objname(lang, pch)
result.append(os.path.join(proj_dir_to_build_root, targetdir, objname))
# extobj could contain only objects and no sources
if not sources:
return result
targetdir = self.get_target_private_dir(extobj.target)
# With unity builds, sources don't map directly to objects,
# we only support extracting all the objects in this mode,
# so just return all object files.
@ -898,6 +906,12 @@ class Backend:
args += compiler.get_pch_use_args(pchpath, p[0])
return includeargs + args
def get_msvc_pch_objname(self, lang: str, pch: T.List[str]) -> str:
if len(pch) == 1:
# Same name as in create_msvc_pch_implementation() below.
return f'meson_pch-{lang}.obj'
return os.path.splitext(pch[1])[0] + '.obj'
def create_msvc_pch_implementation(self, target: build.BuildTarget, lang: str, pch_header: str) -> str:
# We have to include the language in the file name, otherwise
# pch.c and pch.cpp will both end up as pch.obj in VS backends.

@ -3066,7 +3066,7 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
extradep = None
pch_objects += objs
rulename = self.compiler_to_pch_rule_name(compiler)
elem = NinjaBuildElement(self.all_outputs, dst, rulename, src)
elem = NinjaBuildElement(self.all_outputs, objs + [dst], rulename, src)
if extradep is not None:
elem.add_dep(extradep)
self.add_header_deps(target, elem, header_deps)

@ -412,6 +412,7 @@ class ExtractedObjects(HoldableObject):
genlist: T.List['GeneratedTypes'] = field(default_factory=list)
objlist: T.List[T.Union[str, 'File', 'ExtractedObjects']] = field(default_factory=list)
recursive: bool = True
pch: bool = False
def __post_init__(self) -> None:
if self.target.is_unity:
@ -1017,7 +1018,7 @@ class BuildTarget(Target):
def extract_all_objects(self, recursive: bool = True) -> ExtractedObjects:
return ExtractedObjects(self, self.sources, self.generated, self.objects,
recursive)
recursive, pch=True)
def get_all_link_deps(self) -> ImmutableListProtocol[BuildTargetTypes]:
return self.get_transitive_link_deps()

@ -213,7 +213,7 @@ class VisualStudioLikeCompiler(Compiler, metaclass=abc.ABCMeta):
return ['/DEF:' + defsfile]
def gen_pch_args(self, header: str, source: str, pchname: str) -> T.Tuple[str, T.List[str]]:
objname = os.path.splitext(pchname)[0] + '.obj'
objname = os.path.splitext(source)[0] + '.obj'
return objname, ['/Yc' + header, '/Fp' + pchname, '/Fo' + objname]
def openmp_flags(self) -> T.List[str]:

Loading…
Cancel
Save