Skip to content

Commit

Permalink
[SCons] Simplify Cantera.mak and cantera.pc for packaged builds
Browse files Browse the repository at this point in the history
Do not include folders outside of package environment
  • Loading branch information
ischoegl committed Aug 25, 2022
1 parent b61c2fb commit 8c18c01
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 45 deletions.
37 changes: 19 additions & 18 deletions platform/posix/Cantera.mak.in
@@ -1,35 +1,36 @@
###############################################################################
# Include Snippet for Makefiles
#
# To create Cantera C++ applications from the install environment
# include this file into your Makefile environment by putting
# the line "include Cantera.mak" in your Makefile.
# To create Cantera C++ applications from the install environment
# include this file into your Makefile environment by putting
# the line "include Cantera.mak" in your Makefile.
#
# Main Variables:
# Main Variables:
#
# CANTERA_INCLUDES = Variable containing the include path
# CANTERA_LIBS = List of libraries to include on the link line
# CANTERA_INCLUDES = Variable containing the include path
# CANTERA_LIBS = List of libraries to include on the link line
#
# CANTERA_FORTRAN_LIBS = list of libraries to link for Fortran programs
# CANTERA_FORTRAN_MODS = Directory containing the F90 .mod files
# CANTERA_FORTRAN_LIBS = list of libraries to link for Fortran programs
# CANTERA_FORTRAN_MODS = Directory containing the F90 .mod files
#

CANTERA_VERSION=@cantera_version@

###############################################################################
# CANTERA CORE
# CANTERA CORE
###############################################################################

# The directory where Cantera include files may be found.
# Include files in application programs should start with:
# #include "cantera/thermo.h"
# #include "cantera/kernel/HMWSoln.h"
#
# Include files in application programs should start with:
# #include "cantera/core.h"
# #include "cantera/onedim.h"

CANTERA_INSTALL_ROOT=@ct_installroot@

CANTERA_CORE_INCLUDES=-I$(CANTERA_INSTALL_ROOT)/include

CANTERA_EXTRA_INCLUDES=@mak_extra_includes@
CANTERA_EXTRA_INCLUDES=@mak_extra_includes@

# Required Cantera libraries
CANTERA_CORE_LIBS=@mak_threadflags@ -L@ct_libdir@ @mak_corelibs@ -Wl,-rpath,@ct_libdir@
Expand All @@ -45,26 +46,26 @@ CANTERA_FORTRAN_MODS=$(CANTERA_INSTALL_ROOT)/include/cantera
CANTERA_FORTRAN_SYSLIBS=@mak_fort_threadflags@ @mak_stdlib@

###############################################################################
# BOOST
# BOOST
###############################################################################

CANTERA_BOOST_INCLUDES=@mak_boost_include@

###############################################################################
# CVODE/SUNDIALS LINKAGE
# CVODE/SUNDIALS LINKAGE
###############################################################################

CANTERA_SUNDIALS_INCLUDE=@mak_sundials_include@
CANTERA_SUNDIALS_LIBS=@mak_sundials_libdir@ @mak_sundials_libs@

###############################################################################
# BLAS LAPACK LINKAGE
# BLAS LAPACK LINKAGE
###############################################################################

CANTERA_BLAS_LAPACK_LIBS=@mak_blas_lapack_libs@

###############################################################################
# COMBINATIONS OF INCLUDES AND LIBS
# COMBINATIONS OF INCLUDES AND LIBS
###############################################################################

CANTERA_INCLUDES=$(CANTERA_CORE_INCLUDES) $(CANTERA_SUNDIALS_INCLUDE) \
Expand All @@ -89,5 +90,5 @@ CANTERA_FORTRAN_LIBS=$(CANTERA_CORE_FTN) \
$(CANTERA_BLAS_LAPACK_LIBS) $(CANTERA_FORTRAN_SYSLIBS)

###############################################################################
# END
# END
###############################################################################
73 changes: 47 additions & 26 deletions platform/posix/SConscript
@@ -1,4 +1,4 @@
import sys
import os

from buildutils import *

Expand All @@ -19,45 +19,50 @@ pc_libdirs = []
pc_incdirs = []
pc_cflags = list(localenv['CXXFLAGS'])

localenv['mak_corelibs'] = ' '.join('-l' + lib for lib in localenv['cantera_libs'])
localenv["mak_corelibs"] = " ".join(f"-l{lib}" for lib in localenv["cantera_libs"])

localenv["mak_extra_includes"] = " ".join(
f"-I{dir}" for dir in localenv["extra_inc_dirs"])
pc_incdirs.extend(localenv["extra_inc_dirs"])
if localenv["package_build"]:
# folders outside of conda environment are not transferable
localenv["mak_extra_includes"] = ""
localenv["mak_extra_libdirs"] = ""
else:
localenv["mak_extra_includes"] = " ".join(
f"-I{dir}" for dir in localenv["extra_inc_dirs"])
pc_incdirs.extend(localenv["extra_inc_dirs"])

localenv["mak_extra_libdirs"] = " ".join(
f"-L{dir} -Wl,-rpath,{dir}" for dir in localenv["extra_lib_dirs"])
pc_libdirs.extend(localenv["extra_lib_dirs"])
localenv["mak_extra_libdirs"] = " ".join(
f"-L{dir} -Wl,-rpath,{dir}" for dir in localenv["extra_lib_dirs"])
pc_libdirs.extend(localenv["extra_lib_dirs"])

localenv['mak_stdlib'] = ''.join('-l' + lib for lib in env['cxx_stdlib'])
localenv["mak_stdlib"] = " ".join(f"-l{lib}" for lib in env["cxx_stdlib"])

if localenv['system_sundials']:
# Add links to the sundials environment
localenv["mak_sundials_libs"] = " ".join(
f"-l{lib}" for lib in localenv["sundials_libs"])
if localenv['sundials_libdir']:
localenv['mak_sundials_libdir'] = '-L' + localenv['sundials_libdir']
if localenv["sundials_libdir"] and not localenv["package_build"]:
localenv["mak_sundials_libdir"] = f"-L{localenv['sundials_libdir']}"
pc_libdirs.append(localenv['sundials_libdir'])
else:
localenv['mak_sundials_libdir'] = ''

if localenv['sundials_include']:
localenv['mak_sundials_include'] = '-I' + localenv['sundials_include']
if localenv["sundials_include"] and not localenv["package_build"]:
localenv["mak_sundials_include"] = f"-I{localenv['sundials_include']}"
pc_incdirs.append(localenv['sundials_include'])
else:
localenv['mak_sundials_include'] = ''

if localenv['boost_inc_dir']:
localenv['mak_boost_include'] = '-I' + localenv['boost_inc_dir']
if localenv["boost_inc_dir"] and not localenv["package_build"]:
localenv["mak_boost_include"] = f"-I{localenv['boost_inc_dir']}"
pc_incdirs.append(localenv['boost_inc_dir'])
else:
localenv['mak_boost_include'] = ''

# Handle BLAS/LAPACK linkage
blas_lapack_libs = " ".join(f"-l{lib}" for lib in localenv["blas_lapack_libs"])
if localenv['blas_lapack_dir']:
localenv['mak_blas_lapack_libs'] = '-L{} {}'.format(localenv['blas_lapack_dir'],
blas_lapack_libs)
if localenv["blas_lapack_dir"] and not localenv["package_build"]:
localenv["mak_blas_lapack_libs"] = (
f"-L{localenv['blas_lapack_dir']} {blas_lapack_libs}")
else:
localenv['mak_blas_lapack_libs'] = blas_lapack_libs

Expand All @@ -73,15 +78,31 @@ if '-pthread' in localenv['thread_flags']:
else:
localenv['mak_fort_threadflags'] = ''

if localenv["package_build"]:
# Remove sysroot flags in templated output files. This only applies to the
# conda package for now.
# Users should compile against their local SDKs, which should be backwards
# compatible with the SDK used for building.
cc_flags = []
for flag in localenv["CCFLAGS"]:
if not flag.startswith(("-isysroot", "-mmacosx", "/App")):
cc_flags.append(flag)
localenv["CCFLAGS"] = cc_flags
cc_flags = []
for flag in localenv["CXXFLAGS"]:
if not flag.startswith(("-isysroot", "-mmacosx", "/App")):
cc_flags.append(flag)
localenv["CXXFLAGS"] = cc_flags

mak = build(localenv.SubstFile('Cantera.mak', 'Cantera.mak.in'))
install('$inst_incdir', mak)

# Generate cantera.pc for use with pkg-config
localenv['pc_prefix'] = localenv['prefix']
localenv['pc_libdirs'] = ' '.join('-L' + d for d in pc_libdirs)
localenv['pc_libs'] = ' '.join('-l' + lib for lib in pc_libs)
localenv['pc_incdirs'] = ' '.join('-I' + d for d in pc_incdirs)
localenv['pc_cflags'] = ' '.join(pc_cflags)

pc = build(localenv.SubstFile('cantera.pc', 'cantera.pc.in'))
install('$inst_libdir/pkgconfig', pc)
localenv["pc_prefix"] = localenv["prefix"]
localenv["pc_libdirs"] = " ".join(f"-L{dir}" for dir in pc_libdirs)
localenv["pc_libs"] = " ".join(f"-l{lib}" for lib in pc_libs)
localenv["pc_incdirs"] = " ".join(f"-I{dir}" for dir in pc_incdirs)
localenv["pc_cflags"] = " ".join(pc_cflags)

pc = build(localenv.SubstFile("cantera.pc", "cantera.pc.in"))
install("$inst_libdir/pkgconfig", pc)
2 changes: 1 addition & 1 deletion platform/posix/cantera.pc.in
Expand Up @@ -5,7 +5,7 @@ includedir=${prefix}/include

Name: Cantera
Description: Cantera library
URL: http://www.cantera.org
URL: https://cantera.org
Version: @cantera_version@

Libs: -L${libdir} @pc_libdirs@ @pc_libs@
Expand Down

0 comments on commit 8c18c01

Please sign in to comment.