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 configuration import Configuration
19 # GCC compiler-specific configuration
20 class GccConfiguration(Configuration):
21 def __init__(self, context):
22 Configuration.__init__(self, context)
24 # ------------------------------------------------------------
25 # Return test program to be used when checking for basic C99
27 # ------------------------------------------------------------
28 def _c99_test_program(self):
29 # Use the default C99 test program but enable pedantic
30 # diagnostics specific to GCC to force errors to occur if a
31 # flag is required to compile C99 code without warning or
34 from default_configuration import DefaultConfiguration
35 def_config = DefaultConfiguration(self._context)
38 #pragma GCC diagnostic error "-Wall"
39 #pragma GCC diagnostic error "-Werror"
40 #pragma GCC diagnostic error "-pedantic"
41 """ + def_config._c99_test_program()
43 # -------------------------------------------------------------
44 # Get flags known to enable C99 support for GCC C compiler.
45 # -------------------------------------------------------------
47 # Favor flags that do not enable GNU extensions by default,
56 # ------------------------------------------------------------
57 # Return test program to be used when checking for basic C++11
59 # ------------------------------------------------------------
60 def _cxx11_test_program(self):
61 # Besides checking for a basic C++11 feature, this contrived
62 # test program is designed to trigger an issue in some older
63 # (pre-C++11) C library headers that causes functions like
64 # snprintf() to remain undeclared when -std=c++0x or -ansi,
65 # for example, is added to the g++ command line flags, and
66 # despite the fact the appropriate feature test macro to make
67 # the prototypes visible is defined.
69 # The recommended workaround is to instead of -std=c++0x use
70 # -std=gnu++0x to explicitly enable GNU extensions. Failure
71 # will force the configuration test to attempt the build with
72 # -std=gnu++0x, for example.
74 # For a more complete description of this issue, see:
75 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=34032
77 # Other compilers should be able to compile this code without
80 #define _POSIX_C_SOURCE 200112L
88 snprintf(buf, sizeof(buf) / sizeof(buf[0]), "%d", x);
96 # -------------------------------------------------------------
97 # Get flags known to enable C++11 support for GCC C++ compiler.
98 # -------------------------------------------------------------
99 def _cxx11_flags(self):
100 # Favor command line flags from more recent versions of the
101 # compiler over older/deprecated flags. Also, favor flags
102 # that do not enable GNU extensions by default,
104 return [ '-std=c++11',