[SCons] Use precompiled header to speed up compilation with MSVC

Update Appveyor config to turn off debug info so PCH can be used
This commit is contained in:
Ray Speth 2016-10-27 23:39:59 -04:00
parent cbcce07981
commit e3dfc35ca1
4 changed files with 33 additions and 17 deletions

View file

@ -61,6 +61,8 @@ if 'clean' in COMMAND_LINE_TARGETS:
removeFile('.sconsign.dblite')
removeFile('include/cantera/base/config.h')
removeFile('include/cantera/base/system.h.gch')
removeFile('include/cantera/base/system.pch')
removeFile('include/cantera/base/system.obj')
removeDirectory('include/cantera/ext')
removeFile('interfaces/cython/cantera/_cantera.cpp')
removeFile('interfaces/cython/cantera/_cantera.h')
@ -268,6 +270,8 @@ elif env['CC'] == 'cl': # Visual Studio
defaults.optimizeCcFlags = '/O2'
defaults.debugLinkFlags = '/DEBUG'
defaults.warningFlags = '/W3'
defaults.buildPch = True
env['pch_flags'] = ['/FIcantera/base/system.h']
elif 'icc' in env.subst('$CC'):
defaults.cxxFlags = '-std=c++0x'
@ -1407,15 +1411,6 @@ env['cantera_shared_libs'] = linkSharedLibs
if not env['renamed_shared_libraries']:
env['cantera_shared_libs'] = linkLibs
if env['use_pch']:
env['precompiled_header'] = File('include/cantera/base/system.h')
pch = build(env.GchSh('include/cantera/base/system.h.gch', env['precompiled_header']))
# To force early compilaton of the precompiled header
env.Depends(config_h, pch)
else:
removeFile('include/cantera/base/system.h.gch')
env['pch_flags'] = []
# Add targets from the SConscript files in the various subdirectories
Export('env', 'build', 'libraryTargets', 'install', 'buildSample')

View file

@ -6,7 +6,7 @@ install:
C:\Python27-x64\Scripts\pip.exe install cython
build_script:
- cmd: C:\Python27-x64\scons build boost_inc_dir=C:\Libraries\boost_1_62_0
- cmd: C:\Python27-x64\scons build boost_inc_dir=C:\Libraries\boost_1_62_0 debug=n
test_script:
- ps: |

View file

@ -0,0 +1 @@
#include "cantera/base/system.h"

View file

@ -24,18 +24,38 @@ libs = [('base', ['cpp'], baseSetup),
('clib', ['cpp'], defaultSetup),
]
localenv = env.Clone()
localenv.Prepend(CPPPATH=[Dir('#include'), Dir('#include/cantera/ext'), Dir('.')])
localenv.Append(CCFLAGS=env['warning_flags'])
if env['CC'] == 'cl' and env['debug']:
env['use_pch'] = False # PCH doesn't work with per-file PDB
if env['use_pch']:
if env['CC'] == 'cl':
localenv['PCH'], pchobj = localenv.PCH('#include/cantera/base/system.cpp')
libraryTargets.append(pchobj)
localenv['PCHSTOP'] = 'cantera/base/system.h'
else:
localenv['precompiled_header'] = File('#include/cantera/base/system.h')
pch = build(localenv.GchSh('#include/cantera/base/system.h.gch',
localenv['precompiled_header']))
# To force early compilaton of the precompiled header
localenv.Depends(env['config_h_target'], pch)
else:
removeFile('include/cantera/base/system.h.gch')
env['pch_flags'] = []
for subdir, extensions, setup in libs:
localenv = env.Clone()
localenv.Prepend(CPPPATH=[Dir('#include'), Dir('#include/cantera/ext')])
localenv.Append(CCFLAGS=env['warning_flags'])
source = setup(localenv, subdir, extensions)
objects = localenv.SharedObject(source)
localenv.Depends(objects, localenv['config_h_target'])
env2 = localenv.Clone()
source = setup(env2, subdir, extensions)
objects = env2.SharedObject(source)
env2.Depends(objects, env2['config_h_target'])
libraryTargets.extend(objects)
# build the Cantera static library
localenv = env.Clone()
lib = build(localenv.StaticLibrary('../lib/cantera', libraryTargets,
SPAWN=getSpawn(localenv)))
localenv.Depends(lib, localenv['config_h_target'])