How to determine which compiler was requested

My project uses SCons to control the build process. I want to support multiple compilers, so I decided to use AddOptionit so that the user can specify which compiler should be used on the command line (in this case, any current compiler is used by default).

AddOption('--compiler', dest = 'compiler', type = 'string', action = 'store', default = DefaultEnvironment()['CXX'], help = 'Name of the compiler to use.')

I want to have built-in compiler options for different compilers (including things like maximum warning levels for this particular compiler). Here is what my first attempt at solving currently looks like this:

if is_compiler('g++'):
    from build_scripts.gcc.std import cxx_std
    from build_scripts.gcc.warnings import warnings, warnings_debug, warnings_optimized
    from build_scripts.gcc.optimizations import optimizations, preprocessor_optimizations, linker_optimizations
elif is_compiler('clang++'):
    from build_scripts.clang.std import cxx_std
    from build_scripts.clang.warnings import warnings, warnings_debug, warnings_optimized
    from build_scripts.clang.optimizations import optimizations, preprocessor_optimizations, linker_optimizations

However, I'm not sure how to make the function is_compiler()look like. My first thought was to directly compare the name of the compiler (for example, "clang ++") with what the user is going through. However, this immediately failed when I tried to use scons --compiler=~/data/llvm-3.1-obj/Release+Asserts/bin/clang++.

So, I thought I would get a little smarter and use this function

cxx = GetOption('compiler')
def is_compiler (compiler):
    return cxx[-len(compiler):] == compiler

It only looks at the end of the compiler line, so it ignores directories. Unfortunately, "clang ++" ends in "g ++", so my compiler was considered g ++ instead of clang ++.

, ('\' '/'), , , . -, 'g++ - 4.7', g++.

, , ?

g++ clang++ ( ) - ++ 11, , , . - g++, clang++, icc msv++ ( ++ 11), .

+5
3

SCons, :

https://bitbucket.org/davidstone/scons-template/

build_scripts/compiler_settings.py. SCons SConstruct :

AddOption('--compiler', dest = 'compiler', type = 'string', action = 'store', help = 'Name of the compiler to use.')
AddOption('--compiler-command', dest = 'compiler_command', type = 'string', action = 'store', help = 'Command to launch the compiler.')

0, 1 2.

(scons), DefaultEnvironment.

(scons --compiler=g++). script , , , .

(scons --compiler-command=~/llvm-3.1-obj/Release+Asserts/bin/clang++). script , - ( , os.path.basename).

. : scons --compiler-command=/path/to/executable/that/is/not/clang++ --compiler=g++

, , / . , g++, gcc GcC , .

- , , , mingw , , x.y.z+. , - scons --compiler-command=/path/to/gcc-4.7.1 , gcc .

, . , Voo , .

+1

. , . Scons - Tool. from box , : SCons supports the following tool specifications out of the box:... scons, .

, . , , PATH ​​ . , msvc mingw , scons msvc. Tool ('name') (env). :

env = Environment()
Tool('mingw')(env)

env mingw.

, clang , from box scons. env vars, CC, CXX, scons .

+2

Python os.path.basename() os.path.split(), .

, , , , , 2 g++, g++, .

+1
source