Skip to content

Commit

Permalink
[SCons] Avoid unnecessary shared library linkage
Browse files Browse the repository at this point in the history
Applications do not need to link directly to Cantera's dependencies
when linking to the Cantera shared library
  • Loading branch information
speth committed Jun 21, 2023
1 parent d596347 commit 2eccea0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
15 changes: 9 additions & 6 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -2223,6 +2223,12 @@ if env['system_sundials'] == 'y':
else:
env['sundials_libs'] = []

# List of shared libraries needed to link to Cantera
if env["renamed_shared_libraries"]:
env["cantera_shared_libs"] = ["cantera_shared"]
else:
env["cantera_shared_libs"] = ["cantera"]

# External libraries to link to
env["external_libs"] = []
env["external_libs"].extend(env["sundials_libs"])
Expand All @@ -2235,6 +2241,9 @@ if env["use_hdf5"]:

if env["system_fmt"]:
env["external_libs"].append("fmt")
# Usually need to link to fmt directly because of templated/inlined code that calls
# fmt
env["cantera_shared_libs"].append("fmt")

if env["system_yamlcpp"]:
env["external_libs"].append("yaml-cpp")
Expand All @@ -2245,12 +2254,6 @@ if env["blas_lapack_libs"]:
# List of static libraries needed to link to Cantera
env["cantera_libs"] = ["cantera"] + env["external_libs"]

# List of shared libraries needed to link to Cantera
if env["renamed_shared_libraries"]:
env["cantera_shared_libs"] = ["cantera_shared"] + env["external_libs"]
else:
env["cantera_shared_libs"] = ["cantera"] + env["external_libs"]

# Add targets from the SConscript files in the various subdirectories
Export('env', 'build', 'libraryTargets', 'install', 'buildSample', "configh")

Expand Down
7 changes: 3 additions & 4 deletions samples/clib/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ samples = [('demo', ['demo.c'])]
for programName, sources in samples:
buildSample(localenv.Program, programName, sources,
CPPPATH=['#include'],
LIBS=env['cantera_shared_libs']+env['cantera_libs']+env['cxx_stdlib'],
LIBPATH=[localenv['sundials_libdir'], env['blas_lapack_dir'],
env['extra_lib_dirs'], env["hdf_libdir"], '#build/lib'])
LIBS=env['cantera_shared_libs'],
LIBPATH=env['extra_lib_dirs'] + ['#build/lib'])

# Generate SConstruct files to be installed
incdirs = [localenv["ct_incroot"]]
Expand All @@ -27,7 +26,7 @@ for programName, sources in samples:
libdirs.extend(localenv["extra_lib_dirs"])
libdirs = list(set(libdirs))

libs = localenv['cantera_shared_libs'] + localenv['cantera_libs'] + env['cxx_stdlib']
libs = localenv['cantera_shared_libs']
linkflags = ("-g", localenv["thread_flags"], f"-Wl,-rpath,{localenv['ct_libdir']}")
cc_flags = localenv["CCFLAGS"]

Expand Down
4 changes: 2 additions & 2 deletions src/fortran/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ if localenv['layout'] != 'debian':
shlib = build(localenv.SharedLibrary(target=sharedName, source=objects,
SPAWN=get_spawn(localenv),
SHLIBVERSION=localenv['cantera_pure_version'],
LIBS=list(env['cantera_libs'] + env['cxx_stdlib']),
LIBS=list(env['cantera_shared_libs'] + env['cxx_stdlib']),
LINK='$FORTRAN_LINK'))
install(localenv.InstallVersionedLib, '$inst_libdir', shlib)
else:
shlib = build(localenv.SharedLibrary(target=sharedName, source=objects,
SPAWN=get_spawn(localenv),
LIBS=list(env['cantera_libs'] + env['cxx_stdlib']),
LIBS=list(env['cantera_shared_libs'] + env['cxx_stdlib']),
LINK='$FORTRAN_LINK'))
install('$inst_libdir', shlib)
localenv.Depends(shlib, localenv['config_h_target'])
5 changes: 2 additions & 3 deletions test_problems/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Test(object):
if source_files:
self.program = localenv.Program(
pjoin(self.subdir, self.programName), source_files,
LIBS=self.libs or localenv['cantera_shared_libs'])
LIBS=localenv['cantera_shared_libs'])
else:
if isinstance(self.programName, str):
self.programName += '$PROGSUFFIX'
Expand Down Expand Up @@ -110,9 +110,8 @@ class Test(object):

class CompileAndTest(Test):
def __init__(self, testName, subdir=None, programName=None,
blessedName='output_blessed.txt', libs=(), extensions=('cpp',),
blessedName='output_blessed.txt', extensions=('cpp',),
**kwargs):
self.libs = list(libs)
sources = multi_glob(env, subdir or testName, *extensions)
Test.__init__(self, testName, subdir, programName, blessedName,
source_files=sources, **kwargs)
Expand Down

0 comments on commit 2eccea0

Please sign in to comment.