1 # Copyright (c) 2013, 2015-2020 ARM Limited
4 # The license below extends only to copyright in the software and shall
5 # not be construed as granting a license to any other intellectual
6 # property including but not limited to intellectual property relating
7 # to a hardware implementation of the functionality of the software
8 # licensed hereunder. You may use the software subject to the license
9 # terms below provided that you ensure that this notice is replicated
10 # unmodified and in its entirety in all distributions of the software,
11 # modified or unmodified, in source code or in binary form.
13 # Copyright (c) 2011 Advanced Micro Devices, Inc.
14 # Copyright (c) 2009 The Hewlett-Packard Development Company
15 # Copyright (c) 2004-2005 The Regents of The University of Michigan
16 # All rights reserved.
18 # Redistribution and use in source and binary forms, with or without
19 # modification, are permitted provided that the following conditions are
20 # met: redistributions of source code must retain the above copyright
21 # notice, this list of conditions and the following disclaimer;
22 # redistributions in binary form must reproduce the above copyright
23 # notice, this list of conditions and the following disclaimer in the
24 # documentation and/or other materials provided with the distribution;
25 # neither the name of the copyright holders nor the names of its
26 # contributors may be used to endorse or promote products derived from
27 # this software without specific prior written permission.
29 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 def CheckCxxFlag(context
, flag
, autoadd
=True):
47 context
.Message("Checking for compiler %s support... " % flag
)
48 last_cxxflags
= context
.env
['CXXFLAGS']
49 context
.env
.Append(CXXFLAGS
=[flag
])
50 ret
= context
.TryCompile('', '.cc')
51 if not (ret
and autoadd
):
52 context
.env
['CXXFLAGS'] = last_cxxflags
56 def CheckLinkFlag(context
, flag
, autoadd
=True, set_for_shared
=True):
57 context
.Message("Checking for linker %s support... " % flag
)
58 last_linkflags
= context
.env
['LINKFLAGS']
59 context
.env
.Append(LINKFLAGS
=[flag
])
60 ret
= context
.TryLink('int main(int, char *[]) { return 0; }', '.cc')
61 if not (ret
and autoadd
):
62 context
.env
['LINKFLAGS'] = last_linkflags
65 context
.env
.Append(SHLINKFLAGS
=[flag
])
69 # Add a custom Check function to test for structure members.
70 def CheckMember(context
, include
, decl
, member
, include_quotes
="<>"):
71 context
.Message("Checking for member %s in %s..." %
77 (void)test.%(member)s;
80 """ % { "header" : include_quotes
[0] + include
+ include_quotes
[1],
85 ret
= context
.TryCompile(text
, extension
=".cc")
89 def CheckPythonLib(context
):
90 context
.Message('Checking Python version... ')
91 ret
= context
.TryRun(r
"""
92 #include <pybind11/embed.h>
95 main(int argc, char **argv) {
96 pybind11::scoped_interpreter guard{};
99 "vi = sys.version_info\n"
100 "sys.stdout.write('%i.%i.%i' % (vi.major, vi.minor, vi.micro));\n");
103 """, extension
=".cc")
104 context
.Result(ret
[1] if ret
[0] == 1 else 0)
108 return tuple(map(int, ret
[1].split(".")))
110 def CheckPkgConfig(context
, pkgs
, *args
):
111 if not SCons
.Util
.is_List(pkgs
):
116 context
.Message('Checking for pkg-config package %s... ' % pkg
)
117 ret
= context
.TryAction('pkg-config %s' % pkg
)[0]
125 cmd
= ' '.join(['pkg-config'] + list(args
) + [pkg
])
127 context
.env
.ParseConfig(cmd
)
131 except Exception as e
:
137 def Configure(env
, *args
, **kwargs
):
138 kwargs
.setdefault('conf_dir',
139 os
.path
.join(env
['BUILDROOT'], '.scons_config'))
140 kwargs
.setdefault('log_file',
141 os
.path
.join(env
['BUILDROOT'], 'scons_config.log'))
142 kwargs
.setdefault('custom_tests', {})
143 kwargs
['custom_tests'].update({
144 'CheckCxxFlag' : CheckCxxFlag
,
145 'CheckLinkFlag' : CheckLinkFlag
,
146 'CheckMember' : CheckMember
,
147 'CheckPkgConfig' : CheckPkgConfig
,
148 'CheckPythonLib' : CheckPythonLib
,
150 conf
= SCons
.Script
.Configure(env
, *args
, **kwargs
)
152 # Recent versions of scons substitute a "Null" object for Configure()
153 # when configuration isn't necessary, e.g., if the "--help" option is
154 # present. Unfortuantely this Null object always returns false,
155 # breaking all our configuration checks. We replace it with our own
156 # more optimistic null object that returns True instead.
158 def NullCheck(*args
, **kwargs
):
162 def __init__(self
, env
):
166 def __getattr__(self
, mname
):
169 conf
= NullConf(main
)