At last! MSVC precompiles headers and can use them.

pull/15/head
Jussi Pakkanen 12 years ago
parent cbd4f58302
commit e967e5eb4b
  1. 14
      backends.py
  2. 19
      environment.py
  3. 5
      test cases/common/13 pch/prog.c

@ -182,8 +182,8 @@ class Backend():
if len(p) == 0:
continue
if compiler.can_compile(p[-1]):
args.append('-include')
args.append(os.path.split(p[0])[-1])
header = p[0]
args += compiler.get_pch_use_args(pchpath, header)
if len(args) > 0:
args = [includearg] + args
return args
@ -633,10 +633,8 @@ class NinjaBackend(Backend):
pch_dep = []
else:
arr = []
for pch in pchlist:
i = os.path.join(self.get_target_private_dir(target),
os.path.split(pch)[-1] + '.' + compiler.get_pch_suffix())
arr.append(i)
i = os.path.join(self.get_target_private_dir(target), compiler.get_pch_name(pchlist[0]))
arr.append(i)
pch_dep = arr
for i in target.get_include_dirs():
basedir = i.get_curdir()
@ -666,9 +664,7 @@ class NinjaBackend(Backend):
raise RuntimeError('MSVC requires one header and one source to produce precompiled headers.')
header = pch[0]
source = pch[1]
chopped = os.path.split(header)[-1].split('.')[:-1]
chopped.append(compiler.get_pch_suffix())
pchname = '.'.join(chopped)
pchname = compiler.get_pch_name(header)
dst = os.path.join(self.get_target_private_dir(target), pchname)
commands = []

@ -93,7 +93,13 @@ class CCompiler():
def name_string(self):
return ' '.join(self.exelist)
def get_pch_use_args(self, pch_dir, header):
return ['-include', os.path.split(header)[-1]]
def get_pch_name(self, header_name):
return os.path.split(header_name)[-1] + '.' + self.get_pch_suffix()
def sanity_check(self, work_dir):
source_name = os.path.join(work_dir, 'sanitycheckc.c')
binary_name = os.path.join(work_dir, 'sanitycheckc')
@ -251,6 +257,17 @@ class VisualStudioCCompiler(CCompiler):
def get_pch_suffix(self):
return 'pch'
def get_pch_name(self, header):
chopped = os.path.split(header)[-1].split('.')[:-1]
chopped.append(self.get_pch_suffix())
pchname = '.'.join(chopped)
return pchname
def get_pch_use_args(self, pch_dir, header):
base = os.path.split(header)[-1]
pchname = self.get_pch_name(header)
return ['/FI' + base, '/Yu' + base, '/Fp' + os.path.join(pch_dir, pchname)]
def get_debug_flags(self):
return ['/D_DEBUG', '/Zi', '/MDd', '/Ob0', '/RTC1']

@ -1,6 +1,4 @@
#if defined(_MSC_VER)
#include"prog.pch"
#endif
// No includes here, they need to come from the PCH
void func() {
fprintf(stdout, "This is a function that fails if stdio is not #included.\n");
@ -9,3 +7,4 @@ void func() {
int main(int argc, char **argv) {
return 0;
}

Loading…
Cancel
Save