diff --git a/SConstruct b/SConstruct index 865a0f294..170109a97 100644 --- a/SConstruct +++ b/SConstruct @@ -802,7 +802,9 @@ if not conf.CheckCXXHeader('cmath', '<>'): def get_expression_value(includes, expression): s = ['#include ' + i for i in includes] - s.extend(('#include ', + s.extend(('#define Q(x) #x', + '#define QUOTE(x) Q(x)', + '#include ', 'int main(int argc, char** argv) {', ' std::cout << %s << std::endl;' % expression, ' return 0;', @@ -863,23 +865,30 @@ env['LIBM'] = ['m'] if env['NEED_LIBM'] else [] if env['HAS_SUNDIALS'] and env['use_sundials'] != 'n': # Determine Sundials version sundials_version_source = get_expression_value(['"sundials/sundials_config.h"'], - 'SUNDIALS_PACKAGE_VERSION') + 'QUOTE(SUNDIALS_PACKAGE_VERSION)') retcode, sundials_version = conf.TryRun(sundials_version_source, '.cpp') if retcode == 0: config_error("Failed to determine Sundials version.") + sundials_version = sundials_version.strip(' "\n') # Ignore the minor version, e.g. 2.4.x -> 2.4 - env['sundials_version'] = '.'.join(sundials_version.strip().split('.')[:2]) - print """INFO: Using Sundials version %s.""" % sundials_version.strip() + env['sundials_version'] = '.'.join(sundials_version.split('.')[:2]) + print """INFO: Using Sundials version %s.""" % sundials_version #Determine whether or not Sundials was built with BLAS/LAPACK - sundials_blas_lapack = get_expression_value(['"sundials/sundials_config.h"'], - 'SUNDIALS_BLAS_LAPACK') - retcode, has_sundials_lapack = conf.TryRun(sundials_blas_lapack, '.cpp') - if retcode == 0: - config_error("Failed to determine Sundials BLAS/LAPACK.") - env['has_sundials_lapack'] = int(has_sundials_lapack.strip()) - + if LooseVersion(env['sundials_version']) < LooseVersion('2.6'): + # In Sundials 2.4 / 2.5, SUNDIALS_BLAS_LAPACK is either 0 or 1 + sundials_blas_lapack = get_expression_value(['"sundials/sundials_config.h"'], + 'SUNDIALS_BLAS_LAPACK') + retcode, has_sundials_lapack = conf.TryRun(sundials_blas_lapack, '.cpp') + if retcode == 0: + config_error("Failed to determine Sundials BLAS/LAPACK.") + env['has_sundials_lapack'] = int(has_sundials_lapack.strip()) + else: + # In Sundials 2.6, SUNDIALS_BLAS_LAPACK is either defined or undefined + env['has_sundials_lapack'] = conf.CheckDeclaration('SUNDIALS_BLAS_LAPACK', + '#include "sundials/sundials_config.h"', 'C++') + #In the case where a user is trying to link Cantera to an exteral BLAS/LAPACK #library, but Sundials was configured without this support, print a Warning. if not env['has_sundials_lapack'] and not env['BUILD_BLAS_LAPACK']: @@ -1122,7 +1131,7 @@ if env['use_sundials'] == 'default': env['use_sundials'] = 'n' elif env['use_sundials'] == 'y' and not env['HAS_SUNDIALS']: config_error("Unable to find Sundials headers and / or libraries.") -elif env['use_sundials'] == 'y' and env['sundials_version'] not in ('2.4','2.5'): +elif env['use_sundials'] == 'y' and env['sundials_version'] not in ('2.4','2.5','2.6'): print """ERROR: Sundials version %r is not supported.""" % env['sundials_version'] sys.exit(1) diff --git a/doc/sphinx/compiling.rst b/doc/sphinx/compiling.rst index 374356a6e..f8e298e7c 100644 --- a/doc/sphinx/compiling.rst +++ b/doc/sphinx/compiling.rst @@ -478,12 +478,17 @@ Optional Programs * Required to enable some features such as sensitivity analysis. * Strongly recommended if using reactor network or 1D simulation capabilities. * https://computation.llnl.gov/casc/sundials/download/download.html - * Known to work with versions 2.4 and 2.5. - * To use Sundials with Cantera, you may need to compile it with the - ``-fPIC`` flag. You can specify this flag when configuring Sundials:: + * Known to work with versions 2.4, 2.5 and 2.6. + * To use Sundials with Cantera on a Linux/Unix system, it must be compiled + with the ``-fPIC`` flag. You can specify this flag when configuring + Sundials (2.4 or 2.5):: configure --with-cflags=-fPIC + or Sundials 2.6:: + + cmake -DCMAKE_C_FLAGS=-fPIC + .. note:: If you are compiling Sundials 2.5.0 on Windows using CMake, you need to edit the ``CMakeLists.txt`` file first and change the lines::