summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2004-04-04 10:31:02 (GMT)
committerSteven Knight <knight@baldmt.com>2004-04-04 10:31:02 (GMT)
commitf6bfff07364b42d404da9de529659722ec5a281d (patch)
tree5c8da26b597fef5f74c31741063eb4d20bb1b8fa
parent30f01a9a0339978e15115cd2ad8fd169d88e1ab1 (diff)
downloadSCons-f6bfff07364b42d404da9de529659722ec5a281d.zip
SCons-f6bfff07364b42d404da9de529659722ec5a281d.tar.gz
SCons-f6bfff07364b42d404da9de529659722ec5a281d.tar.bz2
Allow CheckLib to search a list of libraries. (sam th)
-rw-r--r--doc/man/scons.18
-rw-r--r--src/CHANGES.txt5
-rw-r--r--src/engine/SCons/Conftest.py51
-rw-r--r--src/engine/SCons/SConf.py19
-rw-r--r--src/engine/SCons/SConfTests.py104
5 files changed, 156 insertions, 31 deletions
diff --git a/doc/man/scons.1 b/doc/man/scons.1
index da35784..232048b 100644
--- a/doc/man/scons.1
+++ b/doc/man/scons.1
@@ -5614,7 +5614,11 @@ appends the library to the LIBS construction environment variable.
may also be None (the default),
in which case
.I symbol
-is checked with the current LIBS variable.
+is checked with the current LIBS variable,
+or a list of library names,
+in which case each library in the list
+will be checked for
+.IR symbol .
The default
.I symbol
is "main",
@@ -5643,7 +5647,7 @@ In contrast to the
call, this call provides a more sophisticated way to check against libraries.
Again,
.I library
-specifies the library to check.
+specifies the library or a list of libraries to check.
.I header
specifies a header to check for.
.I header
diff --git a/src/CHANGES.txt b/src/CHANGES.txt
index d2d933b..8b9c32a 100644
--- a/src/CHANGES.txt
+++ b/src/CHANGES.txt
@@ -72,6 +72,11 @@ RELEASE 0.96 - XXX
- Fix a bug introduced in building shared libraries under MinGW.
+ From sam th:
+
+ - Allow SConf.CheckLib() to search a list of libraries, like the
+ Autoconf AC_SEARCH_LIBS macro.
+
RELEASE 0.95 - Mon, 08 Mar 2004 06:43:20 -0600
diff --git a/src/engine/SCons/Conftest.py b/src/engine/SCons/Conftest.py
index a6bedf5..7260a52 100644
--- a/src/engine/SCons/Conftest.py
+++ b/src/engine/SCons/Conftest.py
@@ -305,10 +305,11 @@ def CheckType(context, type_name, fallback = None,
return ret
-def CheckLib(context, lib_name, func_name, header = None,
+def CheckLib(context, libs, func_name, header = None,
extra_libs = None, call = None, language = None, autoadd = 1):
"""
- Configure check for a C or C++ library "lib_name".
+ Configure check for a C or C++ libraries "libs". Searches through
+ the list of libraries, until one is found where the test succeeds.
Tests if "func_name" or "call" exists in the library. Note: if it exists
in another library the test succeeds anyway!
Optional "header" can be defined to include a header file. If not given a
@@ -333,11 +334,6 @@ def CheckLib(context, lib_name, func_name, header = None,
if not header:
header = ""
- lang, suffix, msg = _lang2suffix(language)
- if msg:
- context.Display("Cannot check for library %s: %s\n" % (lib_name, msg))
- return msg
-
text = """
%s
%s """ % (includetext, header)
@@ -369,27 +365,36 @@ def CheckLib(context, lib_name, func_name, header = None,
else:
calltext = call
- context.Display("Checking for %s in %s library %s... "
- % (calltext, lang, lib_name))
- if lib_name:
- l = [ lib_name ]
- if extra_libs:
- l.extend(extra_libs)
- oldLIBS = context.AppendLIBS(l)
- sym = "HAVE_LIB" + lib_name
- else:
- oldLIBS = -1
- sym = None
+ for lib_name in libs:
+
+ lang, suffix, msg = _lang2suffix(language)
+ if msg:
+ context.Display("Cannot check for library %s: %s\n" % (lib_name, msg))
+ return msg
+
+ context.Display("Checking for %s in %s library %s... "
+ % (calltext, lang, lib_name))
+ if lib_name:
+ l = [ lib_name ]
+ if extra_libs:
+ l.extend(extra_libs)
+ oldLIBS = context.AppendLIBS(l)
+ sym = "HAVE_LIB" + lib_name
+ else:
+ oldLIBS = -1
+ sym = None
- ret = context.BuildProg(text, suffix)
+ ret = context.BuildProg(text, suffix)
- _YesNoResult(context, ret, sym, text)
- if oldLIBS != -1 and (ret or not autoadd):
- context.SetLIBS(oldLIBS)
+ _YesNoResult(context, ret, sym, text)
+ if oldLIBS != -1 and (ret or not autoadd):
+ context.SetLIBS(oldLIBS)
+
+ if ret == "":
+ return ret
return ret
-
#
# END OF PUBLIC FUNCTIONS
#
diff --git a/src/engine/SCons/SConf.py b/src/engine/SCons/SConf.py
index 04955a4..db4e375 100644
--- a/src/engine/SCons/SConf.py
+++ b/src/engine/SCons/SConf.py
@@ -689,6 +689,13 @@ def CheckLib(context, library = None, symbol = "main", autoadd = 1,
Note that library may also be None to test whether the given symbol
compiles without flags.
"""
+
+ if library == []:
+ library = [None]
+
+ if not SCons.Util.is_List(library):
+ library = [library]
+
# ToDo: accept path for the library
res = SCons.Conftest.CheckLib(context, library, symbol, header = header,
language = language, autoadd = autoadd)
@@ -701,7 +708,7 @@ def CheckLib(context, library = None, symbol = "main", autoadd = 1,
# XXX
# Bram: Can only include one header and can't use #ifdef HAVE_HEADER_H.
-def CheckLibWithHeader(context, library, header, language,
+def CheckLibWithHeader(context, libs, header, language,
call = "main();", autoadd = 1):
# ToDo: accept path for library. Support system header files.
"""
@@ -718,10 +725,18 @@ def CheckLibWithHeader(context, library, header, language,
for s in header:
l.append('#include "%s"\n' % (s))
- res = SCons.Conftest.CheckLib(context, library, "main", string.join(l, ''),
+
+ if libs == []:
+ libs = [None]
+
+ if not SCons.Util.is_List(libs):
+ libs = [libs]
+
+ res = SCons.Conftest.CheckLib(context, libs, "main", string.join(l, ''),
call = call, language = language, autoadd = autoadd)
context.did_show_result = 1
if not res:
return 1 # Ok
return 0 # Failed
+
diff --git a/src/engine/SCons/SConfTests.py b/src/engine/SCons/SConfTests.py
index 918f4b9..b17cbff 100644
--- a/src/engine/SCons/SConfTests.py
+++ b/src/engine/SCons/SConfTests.py
@@ -257,11 +257,10 @@ int main() {
assert not ret and output == ""
finally:
sconf.Finish()
-
-
- def test_StandardTests(self):
- """Test standard checks
+
+ def test_CheckHeader(self):
+ """Test SConf.CheckHeader()
"""
self._resetSConfState()
sconf = self.SConf.SConf(self.scons_env,
@@ -278,6 +277,18 @@ int main() {
r = sconf.CheckHeader( "HopefullyNoHeader.noh", language="C++" )
assert not r, "unexpectedly found HopefullyNoHeader.noh"
+ finally:
+ sconf.Finish()
+
+ def test_CheckCHeader(self):
+ """Test SConf.CheckCHeader()
+ """
+ self._resetSConfState()
+ sconf = self.SConf.SConf(self.scons_env,
+ conf_dir=self.test.workpath('config.tests'),
+ log_file=self.test.workpath('config.log'))
+
+ try:
# CheckCHeader()
r = sconf.CheckCHeader( "stdio.h", include_quotes="<>" )
assert r, "did not find stdio.h"
@@ -286,6 +297,18 @@ int main() {
r = sconf.CheckCHeader( "HopefullyNoCHeader.noh" )
assert not r, "unexpectedly found HopefullyNoCHeader.noh"
+ finally:
+ sconf.Finish()
+
+ def test_CheckCXXHeader(self):
+ """Test SConf.CheckCXXHeader()
+ """
+ self._resetSConfState()
+ sconf = self.SConf.SConf(self.scons_env,
+ conf_dir=self.test.workpath('config.tests'),
+ log_file=self.test.workpath('config.log'))
+
+ try:
# CheckCXXHeader()
r = sconf.CheckCXXHeader( "vector", include_quotes="<>" )
assert r, "did not find vector"
@@ -294,12 +317,36 @@ int main() {
r = sconf.CheckCXXHeader( "HopefullyNoCXXHeader.noh" )
assert not r, "unexpectedly found HopefullyNoCXXHeader.noh"
+ finally:
+ sconf.Finish()
+
+ def test_CheckLib(self):
+ """Test SConf.CheckLib()
+ """
+ self._resetSConfState()
+ sconf = self.SConf.SConf(self.scons_env,
+ conf_dir=self.test.workpath('config.tests'),
+ log_file=self.test.workpath('config.log'))
+
+ try:
# CheckLib()
r = sconf.CheckLib( existing_lib, "main", autoadd=0 )
assert r, "did not find %s" % existing_lib
r = sconf.CheckLib( "hopefullynolib", "main", autoadd=0 )
assert not r, "unexpectedly found hopefullynolib"
+ # CheckLib() with list of libs
+ r = sconf.CheckLib( [existing_lib], "main", autoadd=0 )
+ assert r, "did not find %s" % existing_lib
+ r = sconf.CheckLib( ["hopefullynolib"], "main", autoadd=0 )
+ assert not r, "unexpectedly found hopefullynolib"
+ r = sconf.CheckLib( [], "sin", autoadd=0 )
+ assert not r, "unexpectedly found nonexistent library"
+ r = sconf.CheckLib( [existing_lib,"hopefullynolib"], "main", autoadd=0 )
+ assert r, "did not find %s,%s " % (existing_lib,r)
+ r = sconf.CheckLib( ["hopefullynolib",existing_lib], "main", autoadd=0 )
+ assert r, "did not find %s " % existing_lib
+
# CheckLib() with autoadd
def libs(env):
return env.get('LIBS', [])
@@ -322,6 +369,18 @@ int main() {
finally:
sconf.env = env
+ finally:
+ sconf.Finish()
+
+ def test_CheckLibWithHeader(self):
+ """Test SConf.CheckLibWithHeader()
+ """
+ self._resetSConfState()
+ sconf = self.SConf.SConf(self.scons_env,
+ conf_dir=self.test.workpath('config.tests'),
+ log_file=self.test.workpath('config.log'))
+
+ try:
# CheckLibWithHeader()
r = sconf.CheckLibWithHeader( existing_lib, "math.h", "C", autoadd=0 )
assert r, "did not find %s" % existing_lib
@@ -330,6 +389,20 @@ int main() {
r = sconf.CheckLibWithHeader( "hopefullynolib", "math.h", "C", autoadd=0 )
assert not r, "unexpectedly found hopefullynolib"
+ # CheckLibWithHeader() with lists of libs
+ r = sconf.CheckLibWithHeader( [existing_lib], "math.h", "C", autoadd=0 )
+ assert r, "did not find %s" % existing_lib
+ r = sconf.CheckLibWithHeader( [existing_lib], ["stdio.h", "math.h"], "C", autoadd=0 )
+ assert r, "did not find %s, #include stdio.h first" % existing_lib
+ r = sconf.CheckLibWithHeader( [], "math.h", "C", call="sin(3);", autoadd=0 )
+ assert not r, "unexpectedly found non-existent library"
+ r = sconf.CheckLibWithHeader( ["hopefullynolib"], "math.h", "C", autoadd=0 )
+ assert not r, "unexpectedly found hopefullynolib"
+ r = sconf.CheckLibWithHeader( ["hopefullynolib",existing_lib], ["stdio.h", "math.h"], "C", autoadd=0 )
+ assert r, "did not find %s, #include stdio.h first" % existing_lib
+ r = sconf.CheckLibWithHeader( [existing_lib,"hopefullynolib"], ["stdio.h", "math.h"], "C", autoadd=0 )
+ assert r, "did not find %s, #include stdio.h first" % existing_lib
+
# CheckLibWithHeader with autoadd
def libs(env):
return env.get('LIBS', [])
@@ -352,12 +425,35 @@ int main() {
finally:
sconf.env = env
+ finally:
+ sconf.Finish()
+
+ def test_CheckFunc(self):
+ """Test SConf.CheckFunc()
+ """
+ self._resetSConfState()
+ sconf = self.SConf.SConf(self.scons_env,
+ conf_dir=self.test.workpath('config.tests'),
+ log_file=self.test.workpath('config.log'))
+
+ try:
# CheckFunc()
r = sconf.CheckFunc('strcpy')
assert r, "did not find strcpy"
r = sconf.CheckFunc('hopefullynofunction')
assert not r, "unexpectedly found hopefullynofunction"
+ finally:
+ sconf.Finish()
+
+ def test_(self):
+ """Test SConf.CheckType()
+ """
+ self._resetSConfState()
+ sconf = self.SConf.SConf(self.scons_env,
+ conf_dir=self.test.workpath('config.tests'),
+ log_file=self.test.workpath('config.log'))
+ try:
# CheckType()
r = sconf.CheckType('off_t', '#include <sys/types.h>\n')
assert r, "did not find off_t"