From 508b71fecd78544961bda50370516c40b49273ff Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Wed, 14 Dec 2011 19:34:48 +0000 Subject: [PATCH] Improved compiler configuration when using Visual Studio --- SConstruct | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/SConstruct b/SConstruct index 0c1668a6c..30de6e127 100644 --- a/SConstruct +++ b/SConstruct @@ -24,7 +24,26 @@ if not COMMAND_LINE_TARGETS: print __doc__ sys.exit(0) -env = Environment(tools = ['default', 'textfile']) +extraEnvArgs = {} + +if os.name == 'nt': + # On Windows, use the same version of Visual Studio that was used + # to compile Python, and target the same architecture. + pycomp = platform.python_compiler() + if pycomp.startswith('MSC v.1400'): + extraEnvArgs['MSVC_VERSION'] = '8.0' # Visual Studio 2005 + elif pycomp.startswith('MSC v.1500'): + extraEnvArgs['MSVC_VERSION'] = '9.0' # Visual Studio 2008 + elif pycomp.startswith('MSC v.1600'): + extraEnvArgs['MSVC_VERSION'] = '10.0' # Visual Studio 2010 + + if '64 bit' in pycomp: + extraEnvArgs['TARGET_ARCH'] = 'amd64' + else: + extraEnvArgs['TARGET_ARCH'] = 'x86' + +env = Environment(tools=['default', 'textfile'], + **extraEnvArgs) env.AddMethod(RecursiveInstall) subst.TOOL_SUBST(env) add_RegressionTest(env) @@ -47,10 +66,12 @@ else: sys.exit(1) if env['CC'] == 'gcc': - defaults.cxxFlags = '-O3 -Wall' + defaults.cxxFlags = '' + defaults.ccFlags = '-O3 -Wall' defaults.fPIC = ['-fPIC'] elif env['CC'] == 'cl': # Visual Studio defaults.cxxFlags = '/EHsc' + defaults.ccFlags = ['/MD','/nologo'] defaults.fPIC = [] else: print "Error: Unrecognized C compiler '%s'" % env['CC'] @@ -309,8 +330,11 @@ opts.AddVariables( the Python extension module.""", env['CC']), ('CXXFLAGS', - 'C++ Compiler flags.', + 'Compiler flags passed to the C++ compiler only.', defaults.cxxFlags), + ('CCFLAGS', + 'Compiler flags passed to both the C and C++ compilers', + defaults.ccFlags), BoolVariable( 'build_thread_safe', """Cantera can be built so that it is thread safe. Doing so