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 # This file contains compiler tests for use in scons 'Configure'
20 from compiler import factory
22 def _check_for_broken_gcc_headers(context, flag):
23 # Check for issue in some older (pre-C++11) C library headers that
24 # causes functions like snprintf() to remain undeclared when
25 # -std=c++0x or -ansi, for example, is added to the g++ command
26 # line flags, and despite the fact the appropriate feature test
27 # macro to make the prototypes visible is defined.
29 # Returns 1 if the broken headers were detected, 0 otherwise.
31 # This should only be called if the compiler is g++ (which it
32 # should be if we are here) and a flag was automatically appended
35 context.Message('Checking for broken GCC C headers when C++11 is enabled... ')
36 ret = '-std=gnu++' in flag
40 print('Warning: detected pre-C++11 GCC C header bugs. See:')
41 print(' https://gcc.gnu.org/bugzilla/show_bug.cgi?id=34032')
42 print(' for related details.')
44 def _inform_user_of_broken_gcc_headers(context, flag):
45 # Informative tests used to inform the user of broken GCC headers.
46 # They are unnecessary for actual builds.
47 if flag is not 1 and flag is not 0:
48 # The flag is neither 1 nor 0, meaning it contains the
49 # automatically detected C++11 flag.
51 # Now verify that the compiler is actually GCC.
52 is_gcc = factory.check_for_gcc_cxx(context)
54 # This should only be called if the compiler is g++ and a
55 # flag was automatically appended to CXXFLAGS.
57 # We do not care if the user added a flag that triggers
58 # the header bug. It's the user's responsibility to
59 # handle the issue in that case.
60 _check_for_broken_gcc_headers(context, flag)
62 def check_c99_flags(context):
64 Check if command line flag is required to enable C99 support.
66 Returns 1 if no flag is required, 0 if no flag was found, or the
67 actual flag if one was found.
70 cc = context.env['CC']
71 context.Message('Checking for C99 flag for ' + cc + '... ')
72 config = factory.make_c_compiler_config(context)
73 ret = config.check_c99_flags()
78 def check_cxx11_flags(context):
80 Check if command line flag is required to enable C++11 support.
82 Returns 1 if no flag is required, 0 if no flag was found, or the
83 actual flag if one was found.
86 cxx = context.env['CXX']
87 context.Message('Checking for C++11 flag for ' + cxx + '... ')
88 config = factory.make_cxx_compiler_config(context)
89 ret = config.check_cxx11_flags()
92 # Let the user know if a workaround was enabled for broken GCC C
93 # headers when C++11 is enabled.
94 _inform_user_of_broken_gcc_headers(context, ret)
98 def check_pthreads(context):
100 Check if pthreads are supported for this platform.
102 Sets POSIX_SUPPORTED based on the result.
104 context.Message('Checking for POSIX Thread Support...')
105 config = factory.make_c_compiler_config(context)
107 ret = config.has_pthreads_support()
108 context.env['POSIX_SUPPORTED'] = ret