Imported Upstream version 0.9.1
[platform/upstream/iotivity.git] / build_common / iotivityconfig / __init__.py
1 # ------------------------------------------------------------------------
2 # Copyright 2015 Intel Corporation
3 #
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
7 #
8 #      http://www.apache.org/licenses/LICENSE-2.0
9 #
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 # ------------------------------------------------------------------------
16
17 # This file contains compiler tests for use in scons 'Configure'
18 # tests.
19
20 from compiler import factory
21
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.
28     #
29     # Returns 1 if the broken headers were detected, 0 otherwise.
30     #
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
33     # to CXXFLAGS.
34
35     context.Message('Checking for broken GCC C headers when C++11 is enabled... ')
36     ret = '-std=gnu++' in flag
37     context.Result(ret)
38
39     if ret:
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.')
43
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.
50
51         # Now verify that the compiler is actually GCC.
52         is_gcc = factory.check_for_gcc_cxx(context)
53         if is_gcc:
54             # This should only be called if the compiler is g++ and a
55             # flag was automatically appended to CXXFLAGS.
56             #
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)
61
62 def check_c99_flags(context):
63     """
64     Check if command line flag is required to enable C99 support.
65
66     Returns 1 if no flag is required, 0 if no flag was found, or the
67     actual flag if one was found.
68     """
69
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()
74     context.Result(ret)
75
76     return ret
77
78 def check_cxx11_flags(context):
79     """
80     Check if command line flag is required to enable C++11 support.
81
82     Returns 1 if no flag is required, 0 if no flag was found, or the
83     actual flag if one was found.
84     """
85
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()
90     context.Result(ret)
91
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)
95
96     return ret
97
98 def check_pthreads(context):
99     """
100     Check if pthreads are supported for this platform.
101
102     Sets POSIX_SUPPORTED based on the result.
103     """
104     context.Message('Checking for POSIX Thread Support...')
105     config = factory.make_c_compiler_config(context)
106
107     ret = config.has_pthreads_support()
108     context.env['POSIX_SUPPORTED'] = ret
109     context.Result(ret)
110     return ret