Skip to content

Commit

Permalink
Update installation folders
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Feb 10, 2022
1 parent b0cee4f commit de362a9
Showing 1 changed file with 61 additions and 55 deletions.
116 changes: 61 additions & 55 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import subprocess
import re
import textwrap
from os.path import join as pjoin
from attr import asdict
from pkg_resources import parse_version
import SCons
from buildutils import *
Expand Down Expand Up @@ -217,8 +218,10 @@ config_options = [
}),
PathOption(
"prefix",
"""Set this to the directory where Cantera should be installed. On Windows
systems, '$ProgramFiles' typically refers to "C:\Program Files".""",
"""Set this to the directory where Cantera should be installed. If the Python
executable found during compilation is managed by 'conda', the
installation 'prefix' will default to the corresponding environment. On
Windows systems, '$ProgramFiles' typically refers to "C:\Program Files".""",
{"Windows": "$ProgramFiles\Cantera", "default": "/usr/local"},
PathVariable.PathAccept),
PathOption(
Expand Down Expand Up @@ -553,9 +556,11 @@ config_options = [
conjunction with "prefix='/usr/local'". 'compact' puts all installed
files in the subdirectory defined by 'prefix'. This layout is best
with a prefix like '/opt/cantera'. 'debian' installs to the stage
directory in a layout used for generating Debian packages.""",
directory in a layout used for generating Debian packages. If the Python
executable found during compilation is managed by 'conda', the layout
will default to 'conda' irrespective of operating system.""",
{"Windows": "compact", "default": "standard"},
("standard", "compact", "debian")),
("standard", "compact", "debian", "conda")),
BoolOption(
"fast_fail_tests",
"If enabled, tests will exit at the first failure.",
Expand Down Expand Up @@ -822,6 +827,8 @@ opts.Save('cantera.conf', env)
cantera_conf = []
for line in open('cantera.conf'):
cantera_conf.append(line.strip())
selected_options = set(line.split("=")[0].strip() for line in cantera_conf)


# Expand ~/ and environment variables used in cantera.conf (variables used on
# the command line will be expanded by the shell)
Expand Down Expand Up @@ -1052,10 +1059,13 @@ if nan_works.strip() != "1":
# Add conda library/include paths (if applicable)
conda_prefix = os.environ.get("CONDA_PREFIX")
if conda_prefix is not None:
arg_list = set(line.split("=")[0].strip() for line in cantera_conf)
if not arg_list & {"extra_inc_dirs", "extra_lib_dirs"}:
env.Append(CPPPATH=pjoin(conda_prefix, "Library", "include"),
LIBPATH=pjoin(conda_prefix, "Library", env["libdirname"]))
if not selected_options & {"extra_inc_dirs", "extra_lib_dirs"}:
if os.name == "nt":
env.Append(CPPPATH=pjoin(conda_prefix, "Library", "include"),
LIBPATH=pjoin(conda_prefix, "Library", env["libdirname"]))
else:
env.Append(CPPPATH=pjoin(conda_prefix, "include"),
LIBPATH=pjoin(conda_prefix, env["libdirname"]))

# Check for fmt library and checkout submodule if needed
# Test for 'ostream.h' to ensure that version >= 3.0.0 is available
Expand Down Expand Up @@ -1638,40 +1648,57 @@ if env['matlab_toolbox'] == 'y':
env['debian'] = any(name.endswith('dist-packages') for name in sys.path)

# Check whether Cantera should be installed into a conda environment
use_conda = False
if conda_prefix is not None:
arg_list = set(line.split("=")[0].strip() for line in cantera_conf)
use_conda = not arg_list & {"prefix", "python_prefix", "python_cmd"}
use_conda &= sys.executable.startswith(conda_prefix)
if use_conda:
env["prefix"] = pjoin(conda_prefix, "Library")
logger.info(f"Using conda environment as default 'prefix': {env['prefix']}")
if env["layout"] != "conda":
use_conda = not selected_options & \
{"layout", "prefix", "python_prefix", "python_cmd"}
use_conda &= sys.executable.startswith(conda_prefix)
if use_conda:
env["layout"] = "conda"
logger.info(
f"Using conda environment as default 'prefix': {env['prefix']}")
else:
if env["layout"] == "conda":
logger.error("Layout option 'conda' requires a conda environment.")
sys.exit(1)

# Directories where things will be after actually being installed. These
# variables are the ones that are used to populate header files, scripts, etc.
env['prefix'] = os.path.normpath(env['prefix'])
env['ct_installroot'] = env['prefix']
env['ct_libdir'] = pjoin(env['prefix'], env['libdirname'])
env['ct_bindir'] = pjoin(env['prefix'], 'bin')
env['ct_incdir'] = pjoin(env['prefix'], 'include', 'cantera')
env['ct_incroot'] = pjoin(env['prefix'], 'include')

if use_conda:
env["ct_datadir"] = pjoin(env["prefix"], "cantera", "data")
env["ct_sampledir"] = pjoin(env["prefix"], "cantera", "samples")
env["ct_mandir"] = pjoin(env["prefix"], "cantera", "man1")
env["ct_matlab_dir"] = pjoin(env["prefix"], "cantera", "matlab", "toolbox")
elif env["layout"] == "compact":
if env["layout"] == "conda":
env["prefix"] = os.path.normpath(conda_prefix)

if env["layout"] == "conda" and os.name == "nt":
env["ct_libdir"] = pjoin(env["prefix"], "Library", env["libdirname"])
env["ct_bindir"] = pjoin(env["prefix"], "Scripts")
env["ct_python_bindir"] = pjoin(env["prefix"], "Scripts")
env["ct_incdir"] = pjoin(env["prefix"], "Library", "include", "cantera")
env["ct_incroot"] = pjoin(env["prefix"], "Library", "include")
else:
env["prefix"] = os.path.normpath(env["prefix"])
env["ct_libdir"] = pjoin(env["prefix"], env["libdirname"])
env["ct_bindir"] = pjoin(env["prefix"], "bin")
env["ct_python_bindir"] = pjoin(env["prefix"], "bin")
env["ct_incdir"] = pjoin(env["prefix"], "include", "cantera")
env["ct_incroot"] = pjoin(env["prefix"], "include")
env["ct_installroot"] = env["prefix"]

if env['layout'] == 'compact':
env['ct_datadir'] = pjoin(env['prefix'], 'data')
env['ct_sampledir'] = pjoin(env['prefix'], 'samples')
env["ct_docdir"] = pjoin(env["prefix"], "doc")
env['ct_mandir'] = pjoin(env['prefix'], 'man1')
env['ct_matlab_dir'] = pjoin(env['prefix'], 'matlab', 'toolbox')
else:
env['ct_datadir'] = pjoin(env['prefix'], 'share', 'cantera', 'data')
env['ct_sampledir'] = pjoin(env['prefix'], 'share', 'cantera', 'samples')
env["ct_docdir"] = pjoin(env["prefix"], "share", "cantera", "doc")
env['ct_mandir'] = pjoin(env['prefix'], 'share', 'man', 'man1')
env['ct_matlab_dir'] = pjoin(env['prefix'], env['libdirname'],
'cantera', 'matlab', 'toolbox')
if env["layout"] == "conda":
env["ct_matlab_dir"] = pjoin(
env["prefix"], "share", "cantera", "matlab", "toolbox")
else:
env["ct_matlab_dir"] = pjoin(
env["prefix"], env["libdirname"], "cantera", "matlab", "toolbox")

# Always set the stage directory before building an MSI installer
if 'msi' in COMMAND_LINE_TARGETS:
Expand Down Expand Up @@ -1727,31 +1754,10 @@ if env['layout'] == 'debian':
env['inst_python_bindir'] = pjoin(base, 'cantera-python', 'usr', 'bin')
env['python_prefix'] = pjoin(base, 'cantera-python3')
else:
env['inst_libdir'] = pjoin(instRoot, env['libdirname'])
env['inst_bindir'] = pjoin(instRoot, 'bin')
env['inst_python_bindir'] = pjoin(instRoot, 'bin')
env['inst_incdir'] = pjoin(instRoot, 'include', 'cantera')
env['inst_incroot'] = pjoin(instRoot, 'include')

if use_conda:
env["inst_matlab_dir"] = pjoin(instRoot, "cantera", "matlab", "toolbox")
env["inst_datadir"] = pjoin(instRoot, "cantera", "data")
env["inst_sampledir"] = pjoin(instRoot, "cantera", "samples")
env['inst_docdir'] = pjoin(instRoot, "cantera", "doc")
env["inst_mandir"] = pjoin(instRoot, "cantera", "man1")
elif env["layout"] == "compact":
env['inst_matlab_dir'] = pjoin(instRoot, 'matlab', 'toolbox')
env['inst_datadir'] = pjoin(instRoot, 'data')
env['inst_sampledir'] = pjoin(instRoot, 'samples')
env['inst_docdir'] = pjoin(instRoot, 'doc')
env['inst_mandir'] = pjoin(instRoot, 'man1')
else: # env['layout'] == 'standard'
env['inst_matlab_dir'] = pjoin(instRoot, env['libdirname'], 'cantera',
'matlab', 'toolbox')
env['inst_datadir'] = pjoin(instRoot, 'share', 'cantera', 'data')
env['inst_sampledir'] = pjoin(instRoot, 'share', 'cantera', 'samples')
env['inst_docdir'] = pjoin(instRoot, 'share', 'cantera', 'doc')
env['inst_mandir'] = pjoin(instRoot, 'share', 'man', 'man1')
locations = ["libdir", "bindir", "python_bindir", "incdir", "incroot",
"matlab_dir", "datadir", "sampledir", "docdir", "mandir"]
for loc in locations:
env[f"inst_{loc}"] = env[f"ct_{loc}"].replace(env["ct_installroot"], instRoot)

# **************************************
# *** Set options needed in config.h ***
Expand Down

0 comments on commit de362a9

Please sign in to comment.