From 5345040ec0bb8afc89a33caae6cdb2084d38d9f3 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Wed, 14 Dec 2011 02:41:23 +0000 Subject: [PATCH] Initial SCons build scripts Currently just enough to generate a functional config.h --- SConstruct | 198 ++++++++++++++++++++++++++++++++++++++++++++++ buildutils.py | 38 +++++++++ config.h.in.scons | 171 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 407 insertions(+) create mode 100644 SConstruct create mode 100644 buildutils.py create mode 100755 config.h.in.scons diff --git a/SConstruct b/SConstruct new file mode 100644 index 000000000..af0d2a90a --- /dev/null +++ b/SConstruct @@ -0,0 +1,198 @@ +from buildutils import * +import platform, sys, os + +env = Environment() + +# ************************************** +# *** Read user-configurable options *** +# ************************************** + +opts = Variables('cantera.conf') +opts.AddVariables( + PathVariable('prefix', 'Where to install Cantera', + '/usr/local', PathVariable.PathIsDirCreate), + EnumVariable('python_package', 'build python package?', 'default', + ('full', 'minimal', 'none', 'default')), + PathVariable('python_cmd', 'Path to the python interpreter', sys.executable), + EnumVariable('matlab_toolbox', '', 'n', ('y', 'n', 'default')), + BoolVariable('f90_interface', 'Build Fortran90 interface?', False), + ('purify', '', ''), + ('user_src_dir', '', 'Cantera/user'), + BoolVariable('debug', '', False), # ok + BoolVariable('with_lattice_solid', '', True), # ok + BoolVariable('with_metal', '', True), # ok + BoolVariable('with_stoich_substance', '', True), # ok + BoolVariable('with_semiconductor', '', True), # ?? + BoolVariable('with_adsorbate', '', True), + BoolVariable('with_spectra', '', True), + BoolVariable('with_pure_fluids', '', True), + BoolVariable('with_ideal_solutions', '', True), # ok + BoolVariable('with_electrolytes', '', True), # ok + BoolVariable('with_prime', '', False), # ok + BoolVariable('with_h298modify_capability', '', False), # ok + BoolVariable('enable_ck', '', True), + BoolVariable('with_kinetics', '', True), + BoolVariable('with_hetero_kinetics', '', True), + BoolVariable('with_reaction_paths', '', True), + BoolVariable('with_vcsnonideal', '', False), + BoolVariable('enable_transport', '', True), + BoolVariable('enable_equil', '', True), + BoolVariable('enable_reactors', '', True), + BoolVariable('enable_flow1d', '', True), + BoolVariable('enable_solvers', '', True), + BoolVariable('enable_rxnpath', '', True), + BoolVariable('enable_tpx', '', True), + BoolVariable('with_html_log_files', '', True), + EnumVariable('use_sundials', '', 'default', ('default', 'y', 'n')), + ('blas_lapack_libs', '', ''), # '-llapack -lblas' or '-llapack -lf77blas -lcblas -latlas' etc. + ('blas_lapack_dir', '', ''), # '/usr/lib/lapack' etc + EnumVariable('lapack_names', '', 'lower', ('lower','upper')), + BoolVariable('lapack_ftn_trailing_underscore', '', True), + BoolVariable('lapack_ftn_string_len_at_end', '', True), + ('bitcompile', '', ''), # '32' or '64' + ('cxx', '', 'g++'), + ('cc', '', 'gcc'), + ('cxxflags', '', '-O3 -Wall'), + ('lcxx_end_libs', '-lm'), + ('pic', '', ''), + ('shared', '', '-dynamic'), + BoolVariable('build_thread_safe', '', False), + BoolVariable('build_with_f2c', '', True), + ('f77', '', 'g77'), + ('fflags', '', '-O3'), + ('lfort_flags', '', '-L/usr/local/lib'), + ('archive', '', 'ar ruv'), + ('ranlib', '', 'ranlib'), + ('install_bin', '', 'config/install-sh'), + ('graphvisdir', '' ,''), + ('cxx_ext', '', 'cpp'), + ('f77_ext', '', 'f'), + ('f90_ext', '', 'f90'), + ('exe_ext', '', ''), + ('ct_shared_lib', '', 'clib'), + ('rpfont', '', 'Helvetica'), + ('cantera_version', '', '1.8.x') + ) + +opts.Update(env) + +# Additional options that apply only if building the full python package +if env['python_package'] in ('full', 'default'): + opts.AddVariables( + EnumVariable('python_array', 'Which Python array package to use', + 'numpy', ('numpy', 'numarray', 'numeric')), + BoolVariable('set_python_site_package_topdir', '', False), + PathVariable('python_site_package_topdir', '', '/usr/local'), + PathVariable('python_array_home', + 'Location for array package (e.g. if installed with --home)', + None, PathVariable.PathAccept), + PathVariable('cantera_python_home', 'where to install the python package', + None, PathVariable.PathAccept), + + ) + +# Options that apply only if building the Matlab interface +if env['matlab_toolbox'] != 'n': + opts.AddVariables( + PathVariable('matlab_cmd', 'Path to the matlab executable', + 'default', PathVariable.PathAccept) + ) + +# Options that apply only if building the Fortran interface +if env['f90_interface']: + opts.AddVariables( + PathVariable('f90', 'Fortran compiler', 'gfortran'), + ('f90flags', '', '-O3') + ) + +# Extra options for Sundials +if env['use_sundials'] != 'n': + opts.AddVariables( + EnumVariable('sundials_version' ,'', '2.4', ('2.2','2.3','2.4'))) + +# Extra options for Boost.Thread +if env['build_thread_safe']: + opts.AddVariables( + PathVariable('boost_inc_dir', '', '/usr/include/'), + PathVariable('boost_lib_dir', '', '/usr/lib/'), + ('boost_thread_lib', '', 'boost_thread')) + +opts.Update(env) +opts.Save('cantera.conf', env) + +# ******************************************** +# *** Configure system-specific properties *** +# ******************************************** +env['OS'] = platform.system() + +conf = Configure(env) + +env['HAS_SSTREAM'] = conf.CheckCXXHeader('sstream', '<>') + +env = conf.Finish() + + +# ************************************** +# *** Set options needed in config.h *** +# ************************************** + +configh = {'CANTERA_VERSION': quoted(env['cantera_version']), + } + +# Conditional defines +def cdefine(definevar, configvar, comp=True, value=1): + if env.get(configvar) == comp: + configh[definevar] = value + else: + configh[definevar] = None + +cdefine('DEBUG_MODE', 'debug') +cdefine('PURIFY_MODE', 'purify') + +# Need to test all of these to see what platform.system() returns +configh['SOLARIS'] = 1 if env['OS'] == 'Solaris' else None +configh['DARWIN'] = 1 if env['OS'] == 'Darwin' else None +configh['CYGWIN'] = 1 if env['OS'] == 'Cygwin' else None +configh['WINMSVC'] = 1 if env['OS'] == 'Windows' else None +cdefine('NEEDS_GENERIC_TEMPL_STATIC_DECL', 'OS', 'Solaris') + +cdefine('HAS_NUMPY', 'python_array', 'numpy') +cdefine('HAS_NUMARRAY', 'python_array', 'numarray') +cdefine('HAS_NUMERIC', 'python_array', 'numeric') +cdefine('HAS_NO_PYTHON', 'python_package', 'none') +configh['PYTHON_EXE'] = quoted(env['python_cmd']) if env['python_package'] != 'none' else None + +cdefine('HAS_SUNDIALS', 'use_sundials', 'y') +if env['use_sundials']: + cdefine('SUNDIALS_VERSION_22', 'sundials_version', '2.2') + cdefine('SUNDIALS_VERSION_23', 'sundials_version', '2.3') + cdefine('SUNDIALS_VERSION_24', 'sundials_version', '2.4') + +cdefine('WITH_ELECTROLYTES', 'with_electrolytes') +cdefine('WITH_IDEAL_SOLUTIONS', 'with_ideal_solutions') +cdefine('WITH_LATTICE_SOLID', 'with_lattice_solid') +cdefine('WITH_METAL', 'with_metal') +cdefine('WITH_STOICH_SUBSTANCE', 'with_stoich_substance') +cdefine('WITH_SEMICONDUCTOR', 'with_semiconductor') +cdefine('WITH_PRIME', 'with_prime') +cdefine('H298MODIFY_CAPABILITY', 'with_n298modify_capability') +cdefine('WITH_PURE_FLUIDS', 'with_pure_fluids') +cdefine('INCL_PURE_FLUIDS', 'with_pure_fluids') # TODO: fix redundancy +cdefine('WITH_HTML_LOGS', 'with_html_log_files') +cdefine('WITH_VCSNONIDEAL', 'with_vcsnonideal') + +cdefine('LAPACK_FTN_STRING_LEN_AT_END', 'lapack_ftn_string_len_at_end') +cdefine('LAPACK_FTN_TRAILING_UNDERSCORE', 'lapack_ftn_trailing_underscore') +cdefine('FTN_TRAILING_UNDERSCORE', 'lapack_ftn_trailing_underscore') +cdefine('LAPACK_NAMES_LOWERCASE', 'lapack_names', 'lower') + +configh['RXNPATH_FONT'] = quoted(env['rpfont']) +cdefine('THREAD_SAFE_CANTERA', 'build_thread_safe') +cdefine('HAS_SSTREAM', 'HAS_SSTREAM') +configh['CANTERA_DATA'] = quoted(os.path.join(env['prefix'], 'data')) + +env.AlwaysBuild(env.Command('config.h', 'config.h.in.scons', ConfigBuilder(configh))) + +# ********************* +# *** Build Cantera *** +# ********************* diff --git a/buildutils.py b/buildutils.py new file mode 100644 index 000000000..e6d1d2332 --- /dev/null +++ b/buildutils.py @@ -0,0 +1,38 @@ +class DefineDict(object): + def __init__(self, data): + self.data = data + self.undefined = set() + + def __getitem__(self, key): + if key not in self.data: + self.undefined.add(key) + return '/* #undef %s */' % key + elif self.data[key] is None: + return '/* #undef %s */' % key + else: + return '#define %s %s' % (key, self.data[key]) + +class ConfigBuilder(object): + def __init__(self, defines): + self.defines = DefineDict(defines) + + def __call__(self, source, target, env): + for s, t in zip(source, target): + config_h_in = file(str(s), "r") + config_h = file(str(t), "w") + + config_h.write(config_h_in.read() % self.defines) + config_h_in.close() + config_h.close() + self.print_config(str(t)) + + def print_config(self, filename): + print 'Generating %s with the following settings:' % filename + for key, val in sorted(self.defines.data.iteritems()): + if val is not None: + print " %-35s %s" % (key, val) + for key in sorted(self.defines.undefined): + print " %-35s %s" % (key, '*undefined*') + +def quoted(s): + return '"%s"' % s diff --git a/config.h.in.scons b/config.h.in.scons new file mode 100755 index 000000000..641c956d3 --- /dev/null +++ b/config.h.in.scons @@ -0,0 +1,171 @@ +// +// Run the 'preconfig' script to generate 'config.h' from this input file. +// +#ifndef CT_CONFIG_H +#define CT_CONFIG_H + +//---------------------------- Version Flags ------------------// +// Cantera version -> this will be a double-quoted string value +// refering to branch number within svn +%(CANTERA_VERSION)s + +// Integer for major number of Cantera +#define CANTERA_VERSION_MAJORNUMBER 18 +// Flag indicating it's part of major version 18 +#define CANTERA_VERSION_18 1 +// Flag indicating it's a development version +#define CANTERA_VERSION_18_XXX 1 + +//------------------------ Development flags ------------------// +// +// Compile in additional debug printing where available. +// Note, the printing may need to be turned on via a switch. +// This just compiles in the code. +%(DEBUG_MODE)s + +// Compiling with PURIFY instrumentation +%(PURIFY_MODE)s + +//------------------------ Fortran settings -------------------// + + +// define types doublereal, integer, and ftnlen to match the +// corresponding Fortran data types on your system. The defaults +// are OK for most systems + +typedef double doublereal; // Fortran double precision +typedef int integer; // Fortran integer +typedef int ftnlen; // Fortran hidden string length type + + + +// Fortran compilers pass character strings in argument lists by +// adding a hidden argement with the length of the string. Some +// compilers add the hidden length argument immediately after the +// CHARACTER variable being passed, while others put all of the hidden +// length arguments at the end of the argument list. Define this if +// the lengths are at the end of the argument list. This is usually the +// case for most unix Fortran compilers, but is (by default) false for +// Visual Fortran under Windows. +#define STRING_LEN_AT_END + + +// Define this if Fortran adds a trailing underscore to names in object files. +// For linux and most unix systems, this is the case. +%(FTN_TRAILING_UNDERSCORE)s + + +%(HAS_SUNDIALS)s +%(SUNDIALS_VERSION_22)s +%(SUNDIALS_VERSION_23)s +%(SUNDIALS_VERSION_24)s + +//-------- LAPACK / BLAS --------- + +%(LAPACK_FTN_STRING_LEN_AT_END)s +%(LAPACK_NAMES_LOWERCASE)s +%(LAPACK_FTN_TRAILING_UNDERSCORE)s + +//--------- operating system -------------------------------------- + +// The configure script defines this if the operatiing system is Mac +// OS X, This used to add some Mac-specific directories to the default +// data file search path. +%(DARWIN)s +%(HAS_SSTREAM)s + +// Identify whether the operating system is cygwin's overlay of +// windows, with gcc being used as the compiler. +%(CYGWIN)s + +// Identify whether the operating system is windows based, with +// microsoft vc++ being used as the compiler +%(WINMSVC)s + +// Identify whether the operating system is solaris +// with a native compiler +%(SOLARIS)s + +//--------- Fonts for reaction path diagrams ---------------------- +%(RXNPATH_FONT)s + +//---------- C++ Compiler Variations ------------------------------ + +// This define is needed to account for the variability for how +// static variables in templated classes are defined. Right now +// this is only turned on for the SunPro compiler on solaris. +// in that system , you need to declare the static storage variable. +// with the following line in the include file +// +// template Cabinet* Cabinet::__storage; +// +// Note, on other systems that declaration is treated as a definition +// and this leads to multiple defines at link time +%(NEEDS_GENERIC_TEMPL_STATIC_DECL)s + +//--------------------- Python ------------------------------------ +// This path to the python executable is created during +// Cantera's setup. It identifies the python executable +// used to run Python to process .cti files. Note that this is only +// used if environment variable PYTHON_CMD is not set. +%(PYTHON_EXE)s + +// If this is defined, the Cantera Python interface will use the +// Numeric package +%(HAS_NUMERIC)s + +// If this is defined, the Cantera Python interface will use the +// numarray package +%(HAS_NUMARRAY)s + +// If this is defined, the Cantera Python interface will use the +// numpy package +%(HAS_NUMPY)s + +// If this is defined, then python will not be assumed to be +// present to support conversions +%(HAS_NO_PYTHON)s + +//--------------------- Cantera ----------------------------------- +// This data pathway is used to locate a directory where datafiles +// are to be found. Note, the local directory is always searched +// as well. +%(CANTERA_DATA)s + + +%(WITH_HTML_LOGS)s + +//--------------------- compile options ---------------------------- +%(THREAD_SAFE_CANTERA)s + +//--------------------- optional phase models ---------------------- +// This define indicates the enabling of the inclusion of +// accurate liquid/vapor equations +// of state for several fluids, including water, nitrogen, hydrogen, +// oxygen, methane, andd HFC-134a. +%(INCL_PURE_FLUIDS)s +%(WITH_PURE_FLUIDS)s + +%(WITH_LATTICE_SOLID)s +%(WITH_METAL)s +%(WITH_STOICH_SUBSTANCE)s +// Enable expanded thermodynamic capabilities, adding +// ideal solid solutions +%(WITH_IDEAL_SOLUTIONS)s +// Enable expanded electrochemistry capabilities, include thermo +// models for electrolyte solutions. +%(WITH_ELECTROLYTES)s + +%(WITH_PRIME)s + +// Enable the VCS NonIdeal equilibrium solver. This is +// accessed by specifying the solver=2 option +%(WITH_VCSNONIDEAL)s + +//-------------- Optional Cantera Capabilities ---------------------- + +// Enable sensitivity analysis via changing H298 directly +// for species +%(H298MODIFY_CAPABILITY)s + +#endif