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), .