[Numpy-svn] r4520 - in branches/numpy.scons/numpy/distutils: command scons/core
numpy-svn at scipy.org
numpy-svn at scipy.org
Sun Dec 2 04:43:10 EST 2007
Author: cdavid
Date: 2007-12-02 03:43:04 -0600 (Sun, 02 Dec 2007)
New Revision: 4520
Modified:
branches/numpy.scons/numpy/distutils/command/scons.py
branches/numpy.scons/numpy/distutils/scons/core/numpyenv.py
Log:
Handle c++ compiler for distutils scons
Modified: branches/numpy.scons/numpy/distutils/command/scons.py
===================================================================
--- branches/numpy.scons/numpy/distutils/command/scons.py 2007-12-02 09:34:07 UTC (rev 4519)
+++ branches/numpy.scons/numpy/distutils/command/scons.py 2007-12-02 09:43:04 UTC (rev 4520)
@@ -69,6 +69,15 @@
# XXX: Just give up for now, and use generic fortran compiler
return 'fortran'
+def dist2sconscxx(compiler):
+ """This converts the name passed to distutils to scons name convention
+ (C++ compiler). The argument should be a Compiler instance."""
+ if compiler.compiler_type == 'gnu':
+ return 'g++'
+ else:
+ return 'c++'
+ return compiler.compiler_cxx[0]
+
def get_compiler_executable(compiler):
"""For any give CCompiler instance, this gives us the name of C compiler
(the actual executable).
@@ -92,6 +101,24 @@
(the actual executable)."""
return compiler.compiler_f77[0]
+def get_cxxcompiler_executable(compiler):
+ """For any give CCompiler instance, this gives us the name of CXX compiler
+ (the actual executable).
+
+ NOTE: does NOT work with FCompiler instances."""
+ # Geez, why does distutils has no common way to get the compiler name...
+ if compiler.compiler_type == 'msvc':
+ # this is harcoded in distutils... A bit cleaner way would be to
+ # initialize the compiler instance and then get compiler.cc, but this
+ # may be costly: we really just want a string.
+ # XXX: we need to initialize the compiler anyway, so do not use
+ # hardcoded string
+ #compiler.initialize()
+ #print compiler.cc
+ return 'cl.exe'
+ else:
+ return compiler.compiler_cxx[0]
+
def get_tool_path(compiler):
"""Given a distutils.ccompiler.CCompiler class, returns the path of the
toolset related to C compilation."""
@@ -113,6 +140,16 @@
"info for scons")
return fullpath
+def get_cxx_tool_path(compiler):
+ """Given a distutils.ccompiler.CCompiler class, returns the path of the
+ toolset related to C compilation."""
+ fullpath_exec = find_executable(get_cxxcompiler_executable(compiler))
+ if fullpath_exec:
+ fullpath = pdirname(fullpath_exec)
+ else:
+ raise DistutilsSetupError("Could not find compiler executable info for scons")
+ return fullpath
+
def protect_path(path):
"""Convert path (given as a string) to something the shell will have no
problem to understand (space, etc... problems)."""
@@ -246,6 +283,10 @@
cmd.append('f77_opt=%s' % dist2sconsfc(self.fcompiler))
cmd.append('f77_opt_path=%s' % protect_path(get_f77_tool_path(self.fcompiler)))
+ if self.cxxcompiler:
+ cmd.append('cxx_opt=%s' % dist2sconscxx(self.cxxcompiler))
+ cmd.append('cxx_opt_path=%s' % protect_path(get_cxx_tool_path(self.cxxcompiler)))
+
cmd.append('include_bootstrap=%s' % dirl_to_str(get_numpy_include_dirs()))
if self.silent:
if int(self.silent) == 1:
Modified: branches/numpy.scons/numpy/distutils/scons/core/numpyenv.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/core/numpyenv.py 2007-12-02 09:34:07 UTC (rev 4519)
+++ branches/numpy.scons/numpy/distutils/scons/core/numpyenv.py 2007-12-02 09:43:04 UTC (rev 4520)
@@ -99,6 +99,9 @@
opts.Add('f77_opt', 'name of F77 compiler', '')
opts.Add('f77_opt_path', 'path of the F77 compiler set in cc_opt', '')
+ opts.Add('cxx_opt', 'name of C compiler', '')
+ opts.Add('cxx_opt_path', 'path of the C compiler set in cc_opt', '')
+
return opts
def customize_cc(name, env):
@@ -197,6 +200,27 @@
env.AppendUnique(SHF77FLAGS = ['-fno-second-underscore'])
env.AppendUnique(SHF77FLAGS = ['-fPIC'])
+def initialize_cxx(env, path_list):
+ from SCons.Tool import Tool, FindTool
+
+ if len(env['cxx_opt']) > 0:
+ try:
+ if len(env['cxx_opt_path']) > 0:
+ t = Tool(env['cxx_opt'], toolpath = [os.path.dirname(numpy.distutils.scons.tools.__file__)])
+ t(env)
+ path_list.append(env['cxx_opt_path'])
+ except EnvironmentError, e:
+ # scons could not understand cxx_opt (bad name ?)
+ raise AssertionError("SCONS: Could not initialize tool ? Error is %s" % \
+ str(e))
+ else:
+ def_fcompiler = FindTool(DEF_FORTRAN_COMPILERS, env)
+ if def_fcompiler:
+ t = Tool(def_fcompiler)
+ t(env)
+ else:
+ print "========== NO CXX COMPILER FOUND ==========="
+
def _GetNumpyEnvironment(args):
"""Call this with args = ARGUMENTS."""
from SCons.Environment import Environment
@@ -241,6 +265,9 @@
# Initialize F77 tool from distutils info
initialize_f77(env, path_list)
+ # Initialize CXX tool from distutils info
+ initialize_cxx(env, path_list)
+
# Adding default tools for the one we do not customize: mingw is special
# according to scons, don't ask me why, but this does not work as expected
# for this tool.
More information about the Numpy-svn
mailing list