scons: Create a Configure checker for pkg-config.

This will check if a pkg-config package exists at all, and then if it
does will attempt to use the supplied pkg-config arguments and
ParseConfig to set up the environment as needed.

Change-Id: I1495e5370b60dcebb1c9ce38517e84d727abc2fd
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/40866
Tested-by: kokoro <noreply+kokoro@google.com>
Maintainer: Gabe Black <gabe.black@gmail.com>
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
This commit is contained in:
Gabe Black
2021-02-07 02:58:47 -08:00
parent 7ebcb83ac3
commit d7df1ebabb
2 changed files with 34 additions and 22 deletions

View File

@@ -41,6 +41,7 @@
import os
import SCons.Script
import SCons.Util
def CheckCxxFlag(context, flag, autoadd=True):
context.Message("Checking for compiler %s support... " % flag)
@@ -106,6 +107,33 @@ main(int argc, char **argv) {
else:
return tuple(map(int, ret[1].split(".")))
def CheckPkgConfig(context, pkgs, *args):
if not SCons.Util.is_List(pkgs):
pkgs = [pkgs]
assert(pkgs)
for pkg in pkgs:
context.Message('Checking for pkg-config package %s... ' % pkg)
ret = context.TryAction('pkg-config %s' % pkg)[0]
if not ret:
context.Result(ret)
continue
if len(args) == 0:
break
cmd = ' '.join(['pkg-config'] + list(args) + [pkg])
try:
context.env.ParseConfig(cmd)
ret = 1
context.Result(ret)
break
except Exception as e:
ret = 0
context.Result(ret)
return ret
def Configure(env, *args, **kwargs):
kwargs.setdefault('conf_dir',
os.path.join(env['BUILDROOT'], '.scons_config'))
@@ -113,10 +141,11 @@ def Configure(env, *args, **kwargs):
os.path.join(env['BUILDROOT'], 'scons_config.log'))
kwargs.setdefault('custom_tests', {})
kwargs['custom_tests'].update({
'CheckMember' : CheckMember,
'CheckPythonLib' : CheckPythonLib,
'CheckCxxFlag' : CheckCxxFlag,
'CheckLinkFlag' : CheckLinkFlag,
'CheckMember' : CheckMember,
'CheckPkgConfig' : CheckPkgConfig,
'CheckPythonLib' : CheckPythonLib,
})
conf = SCons.Script.Configure(env, *args, **kwargs)