diff --git a/CHANGES.txt b/CHANGES.txt index 97f7be2431..79037244ad 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -12,6 +12,10 @@ NOTE: Python 3.6 support is deprecated and will be dropped in a future release. RELEASE VERSION/DATE TO BE FILLED IN LATER + From Ruben Di Battista: + - Expose `extra_libs` kwarg in the `CheckLibWithHeader` and forward it downstream + to `CheckLib` + From Joseph Brill: - Added error handling when creating MSVC detection debug log file specified by SCONS_MSCOMMON_DEBUG. diff --git a/RELEASE.txt b/RELEASE.txt index 1b823b91d1..c4f9fe5481 100644 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -25,6 +25,7 @@ DEPRECATED FUNCTIONALITY CHANGED/ENHANCED EXISTING FUNCTIONALITY --------------------------------------- +- Expose the `extra_libs` keyword argument in `CheckLibWithHeader` - List modifications to existing features, where the previous behavior wouldn't actually be considered a bug diff --git a/SCons/SConf.py b/SCons/SConf.py index c22355665c..7d3d4843b0 100644 --- a/SCons/SConf.py +++ b/SCons/SConf.py @@ -1126,7 +1126,7 @@ def CheckLib(context, library = None, symbol: str = "main", # Bram: Can only include one header and can't use #ifdef HAVE_HEADER_H. def CheckLibWithHeader(context, libs, header, language, - call = None, autoadd: bool=True, append: bool=True, unique: bool=False) -> bool: + extra_libs = None, call = None, autoadd: bool=True, append: bool=True, unique: bool=False) -> bool: # ToDo: accept path for library. Support system header files. """ Another (more sophisticated) test for a library. @@ -1143,8 +1143,8 @@ def CheckLibWithHeader(context, libs, header, language, libs = [libs] res = SCons.Conftest.CheckLib(context, libs, None, prog_prefix, - call = call, language = language, autoadd=autoadd, - append=append, unique=unique) + extra_libs = extra_libs, call = call, language = language, + autoadd=autoadd, append=append, unique=unique) context.did_show_result = 1 return not res diff --git a/doc/man/scons.xml b/doc/man/scons.xml index 979f67d38f..4119a45578 100644 --- a/doc/man/scons.xml +++ b/doc/man/scons.xml @@ -4244,6 +4244,7 @@ to serve as the test can be supplied in if not supplied, the default checks the ability to link against the specified library. +extra_libs can be used to add additional libraries to link against. If autoadd is true (the default), the first library that passes the check is added to the &cv-link-LIBS; &consvar; in the context diff --git a/test/Configure/CheckLibWithHeader_extra_libs.py b/test/Configure/CheckLibWithHeader_extra_libs.py new file mode 100644 index 0000000000..9d5f30033e --- /dev/null +++ b/test/Configure/CheckLibWithHeader_extra_libs.py @@ -0,0 +1,94 @@ +""" +Verify that a program which depends on library which in turns depend on another library +can be built correctly using CheckLibWithHeader +""" + +from pathlib import Path + +from TestSCons import TestSCons + +test = TestSCons(match=TestSCons.match_re_dotall) + + +libA_dir = Path(test.workdir) / "libA" +libA_dir.mkdir() +test.write( + str(libA_dir / "libA.h"), + """\ +void libA(); +""", +) +test.write( + str(libA_dir / "libA.c"), + """\ +#include +#include "libA.h" + +void libA() { + printf("libA\\n"); +} +""", +) +test.write( + str(libA_dir / "SConstruct"), + """\ +SharedLibrary('libA', source=['libA.c']) +""", +) +test.run(chdir=libA_dir) + + +libB_dir = Path(test.workdir) / "libB" +libB_dir.mkdir() +test.write( + str(libB_dir / "libB.h"), + """\ +void libB(); +""", +) +test.write( + str(libB_dir / "libB.c"), + """\ +#include +#include "libA.h" +#include "libB.h" + +void libB () { + libA(); +} +""", +) +test.write( + str(libB_dir / "SConstruct"), + """\ +SharedLibrary( + 'libB', + source=['libB.c'], + LIBS=['A'], + LIBPATH='../libA', + CPPPATH='../libA', +) +""", +) +test.run(chdir=libB_dir) + +test.write( + "SConstruct", + """\ +import os +env = Environment(ENV=os.environ, CPPPATH=['libB', 'libA'], LIBPATH=['libB', 'libA']) +conf = Configure(env) + +ret = conf.CheckLibWithHeader( + ['B'], + header="libB.h", + language='C', + extra_libs=['A'], + call='libB();', + autoadd=False, +) +assert ret +""", +) +test.run() +test.pass_test()