Skip to content

Commit

Permalink
[SCons] Clean up generated build scripts for clib demo
Browse files Browse the repository at this point in the history
  • Loading branch information
speth authored and ischoegl committed Aug 21, 2023
1 parent 8360ad9 commit 8e2ab16
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions samples/clib/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,45 @@ for programName, sources in samples:
LIBPATH=env['extra_lib_dirs'] + ['#build/lib'])

# Generate SConstruct files to be installed
linkflags = ["-g", localenv["thread_flags"]]
linkflags = [localenv["thread_flags"]]
flag_excludes = [r"\$\(", "/TP", r"\$\)", "/nologo"]
incdirs = [localenv["ct_incroot"]]
libdirs = [localenv["ct_libdir"]] + localenv["extra_lib_dirs"]
if not localenv["package_build"]:
linkflags.append(f"-Wl,-rpath,{localenv['ct_shlibdir']}")
libdirs.extend(localenv["extra_lib_dirs"])
libdirs = [localenv["ct_libdir"]]

if env["OS"] == "Darwin" and env["use_rpath_linkage"] and not env.subst("$__RPATH"):
# SCons fails to specify RPATH on macOS, so circumvent that behavior by
# specifying this directly as part of LINKFLAGS
linkflags.extend(env.subst(f'$RPATHPREFIX{d}$RPATHSUFFIX') for d in libdirs)

localenv["tmpl_compiler_flags"] = repr(localenv["CCFLAGS"])
localenv['tmpl_cantera_incdirs'] = repr([x for x in incdirs if x])
localenv['tmpl_cantera_libs'] = repr(localenv['cantera_shared_libs'])
localenv['tmpl_cantera_libdirs'] = repr([x for x in libdirs if x])
localenv['tmpl_cantera_linkflags'] = repr([x for x in linkflags if x])
localenv['tmpl_cantera_frameworks'] = repr(localenv['FRAMEWORKS'])

localenv['tmpl_progname'] = programName
localenv['tmpl_sourcename'] = programName + '.c'

if localenv['package_build']:
# For package builds, use environment variables or rely on SCons to find the
# default compiler
localenv['tmpl_cc'] = "env['CC'] = os.environ.get('CC', env['CC'])"

# Remove flags that are specific to the build host. Users should compile against
# their local SDKs, which should be backwards compatible with the SDK used for
# building.
flag_excludes.extend(["-isysroot", "-mmacosx", "-march", "-mtune",
"-fdebug-prefix-map", ".*/_build_env/"])
else:
linkflags.append(f"-Wl,-rpath,{localenv['ct_shlibdir']}")
libdirs.extend(localenv["extra_lib_dirs"])
# Otherwise, use the same compiler that was used to build Cantera, with the
# environment variables optionally overriding
localenv['tmpl_cc'] = env.subst("env['CC'] = os.environ.get('CC', '$CC')")

linkflags = compiler_flag_list(linkflags, env["CC"], flag_excludes)
localenv["tmpl_compiler_flags"] = repr(
compiler_flag_list(localenv["CCFLAGS"], env["CC"], flag_excludes))
localenv['tmpl_cantera_incdirs'] = repr([x for x in incdirs if x])
localenv['tmpl_cantera_libs'] = repr(localenv['cantera_shared_libs'])
localenv['tmpl_cantera_libdirs'] = repr([x for x in libdirs if x])
localenv['tmpl_cantera_linkflags'] = repr([x for x in linkflags if x])
localenv['tmpl_cantera_frameworks'] = repr(localenv['FRAMEWORKS'])

localenv['tmpl_progname'] = programName
localenv['tmpl_sourcename'] = programName + '.c'

sconstruct = localenv.SubstFile('SConstruct', 'SConstruct.in')
install("$inst_sampledir/clib", sconstruct)

Expand Down

0 comments on commit 8e2ab16

Please sign in to comment.