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)
39 #pragma GCC diagnostic error "-Wall"
40 #pragma GCC diagnostic error "-Werror"
41 #pragma GCC diagnostic error "-pedantic"
43 """ + def_config._c99_test_program()
45 # -------------------------------------------------------------
46 # Get flags known to enable C99 support for GCC C compiler.
47 # -------------------------------------------------------------
49 # Favor flags that do not enable GNU extensions by default,
58 # ------------------------------------------------------------
59 # Return test program to be used when checking for basic C++11
61 # ------------------------------------------------------------
62 def _cxx11_test_program(self):
63 # Besides checking for a basic C++11 feature, this contrived
64 # test program is designed to trigger an issue in some older
65 # (pre-C++11) C library headers that causes functions like
66 # snprintf() to remain undeclared when -std=c++0x or -ansi,
67 # for example, is added to the g++ command line flags, and
68 # despite the fact the appropriate feature test macro to make
69 # the prototypes visible is defined.
71 # The recommended workaround is to instead of -std=c++0x use
72 # -std=gnu++0x to explicitly enable GNU extensions. Failure
73 # will force the configuration test to attempt the build with
74 # -std=gnu++0x, for example.
76 # For a more complete description of this issue, see:
77 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=34032
79 # Other compilers should be able to compile this code without
82 #define _POSIX_C_SOURCE 200112L
90 snprintf(buf, sizeof(buf) / sizeof(buf[0]), "%d", x);
98 # -------------------------------------------------------------
99 # Get flags known to enable C++11 support for GCC C++ compiler.
100 # -------------------------------------------------------------
101 def _cxx11_flags(self):
102 # Favor command line flags from more recent versions of the
103 # compiler over older/deprecated flags. Also, favor flags
104 # that do not enable GNU extensions by default,
106 return [ '-std=c++11',