1 # ------------------------------------------------------------------------
2 # Copyright 2015 Intel Corporation
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 # ------------------------------------------------------------------------
17 from default_configuration import *
18 from gcc_configuration import *
20 # Canonicalize the C or C++ compiler name to "gcc" if gcc is being
21 # used to simplify mapping to the GCC compiler configuration since GCC
22 # may be installed under a different name. This will be used when
23 # mapping compiler name to configuration in the factory submodule.
26 # Update this dictionary with new compiler configurations as needed.
27 _CONFIG_MAP = { _GCC : GccConfiguration }
29 _c_compiler_config = None
30 _cxx_compiler_config = None
32 def check_for_gcc_c(context):
34 Check if the C compiler is GCC
36 Returns 1 if gcc, 0 otherwise
40 #if !defined(__GNUC__)
41 # error "Not the GCC C compiler."
50 return context.TryCompile(test_program, '.c')
52 def check_for_gcc_cxx(context):
54 Check if the C++ compiler is GCC
56 Returns 1 if gcc, 0 otherwise
60 #if !defined(__GNUC__) || !defined(__cplusplus)
61 # error "Not the GCC C++ compiler."
68 int x() const { return x_; }
74 return context.TryCompile(test_program, '.cpp')
76 def make_c_compiler_config(context):
78 Create C compiler-specific configuration object.
81 context -- the scons configure context
83 The 'CC' key in the SCons environment will be mapped to the
84 appropriate supported compiler configuration. If no match is
85 found compiler configuration operations will simply be no-ops.
88 global _c_compiler_config
90 if _c_compiler_config is None:
91 cc = context.env['CC']
93 if check_for_gcc_c(context):
96 config = _CONFIG_MAP.get(cc, DefaultConfiguration)
98 _c_compiler_config = config(context)
100 return _c_compiler_config
102 def make_cxx_compiler_config(context):
104 Create C++ compiler-specific configuration object.
107 context -- the scons configure context
109 The 'CXX' key in the SCons environment will be mapped to the
110 appropriate supported compiler configuration. If no match is
111 found compiler configuration operations will simply be no-ops.
114 global _cxx_compiler_config
116 if _cxx_compiler_config is None:
117 cxx = context.env['CXX']
119 if check_for_gcc_cxx(context):
122 config = _CONFIG_MAP.get(cxx, DefaultConfiguration)
124 _cxx_compiler_config = config(context)
126 return _cxx_compiler_config