Allow CheckLib to search a list of libraries. (sam th)
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 4 Apr 2004 10:31:02 +0000 (10:31 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 4 Apr 2004 10:31:02 +0000 (10:31 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@947 fdb21ef1-2011-0410-befe-b5e4ea1792b1

doc/man/scons.1
src/CHANGES.txt
src/engine/SCons/Conftest.py
src/engine/SCons/SConf.py
src/engine/SCons/SConfTests.py

index da35784fc3d461af5f23f7e539c627521595f7fc..232048b54d71a694e98a828b155071dc80b00fd0 100644 (file)
@@ -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
index d2d933ba12932ec98f3973981253a3710a14195d..8b9c32a93e433b00ce4f590e43ba1a482003b566 100644 (file)
@@ -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
index a6bedf5a1c79ff6672c319c7df3d229a3d11a4b8..7260a5271776f9c91e2229725953344c8cdd5b0b 100644 (file)
@@ -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
 #
index 04955a4fa3dce176209bdbb608284584f1c49fb1..db4e375de4ccbc5845b2bbfac05c2927d9c5c567 100644 (file)
@@ -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
 
+    
index 918f4b93dce8e0aba436cffe2b90293f06ba143c..b17cbff0b57b826c02d44edf58c7ca5cd27fa5f1 100644 (file)
@@ -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"