From e11281477ead46762977af61b4b455ba6d15864f Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Thu, 5 Apr 2012 22:03:30 +0000 Subject: [PATCH] Added configuration option for building a single library This is necessary particularly for Windows, where there's no easy way to build shared libraries of the f2c code because those functions don't have the necessary __declspec(dllexport) in their non-existent headers. --- SConstruct | 47 +++++++++++++++++------------- ext/SConscript | 66 ++++++++++++++++++------------------------- src/matlab/SConscript | 9 ++---- 3 files changed, 59 insertions(+), 63 deletions(-) diff --git a/SConstruct b/SConstruct index fc829554e..0c0c6f641 100644 --- a/SConstruct +++ b/SConstruct @@ -7,7 +7,7 @@ Basic usage: 'scons build' - Compile Cantera and the language interfaces using default options. - 'cons clean' - Delete files created while building Cantera. + 'scons clean' - Delete files created while building Cantera. '[sudo] scons install' - Install Cantera. @@ -115,7 +115,7 @@ env = Environment(tools=toolchain+['textfile', 'subst', 'recursiveInstall', 'wix # # To print the current environment # -# print env.Dump() +# print env.Dump() env['OS'] = platform.system() @@ -216,8 +216,10 @@ else: if env['OS'] in ('Windows', 'Darwin'): defaults.threadFlags = '' + defaults.singleLibrary = True else: defaults.threadFlags = '-pthread' + defaults.singleLibrary = False # ************************************** # *** Read user-configurable options *** @@ -581,10 +583,15 @@ opts.AddVariables( """If this option is turned on, which is the default, the shared libraries that are created will be renamed to have a "_shared" extension added to their base name. If not, the base names will be the same as the static libraries. - In some cases this simplifies subsequent linking environments with - static libaries and avoids a bug with using valgrind with + In some cases this simplifies subsequent linking environments with + static libaries and avoids a bug with using valgrind with the -static linking flag.""", True), + BoolVariable( + 'single_library', + """If set, include code from the 'ext' folder in the cantera library + rather than creating separate libraries for ctlapack, ctf2c, etc.""", + defaults.singleLibrary), PathVariable( 'graphvizdir', """The directory location of the graphviz program, "dot". dot is @@ -1076,37 +1083,39 @@ if env['use_sundials'] == 'y': linkSharedLibs.extend(('sundials_cvodes', 'sundials_ida', 'sundials_nvecserial')) else: env['sundials_libs'] = [] - linkLibs.extend(['cvode']) - linkSharedLibs.extend(['cvode_shared']) + if not env['single_library']: + linkLibs.extend(['cvode']) + linkSharedLibs.extend(['cvode_shared']) #print 'linkLibs = ', linkLibs -linkLibs.append('ctmath') -linkSharedLibs.append('ctmath_shared') - +if not env['single_library']: + linkLibs.append('ctmath') + linkSharedLibs.append('ctmath_shared') + + # Add execstream to the link line + linkLibs.append('execstream') + linkSharedLibs.append('execstream_shared') + # # Add lapack and blas to the link line # -if env['blas_lapack_libs'] == []: +if env['blas_lapack_libs']: + linkLibs.extend(env['blas_lapack_libs']) +elif not env['single_library']: linkLibs.extend(('ctlapack', 'ctblas')) linkSharedLibs.extend(('ctlapack_shared', 'ctblas_shared')) -else: - linkLibs.extend(env['blas_lapack_libs']) -# -# Add execstream to the link line -# -linkLibs.append('execstream') -linkSharedLibs.append('execstream_shared') + # # Add the f2c library if it is necessary to link fortran libraries # if not env['build_with_f2c']: - # + # # Early gcc compilers will fail on this line as they use g77 and not gfortran # linkLibs.append('gfortran') linkSharedLibs.append('gfortran') -else: +elif not env['single_library']: # Add the f2c library when f2c is requested # linkLibs.append('ctf2c') diff --git a/ext/SConscript b/ext/SConscript index 75ef9e52b..7989ef318 100644 --- a/ext/SConscript +++ b/ext/SConscript @@ -96,49 +96,39 @@ if env['use_sundials'] == 'n': for subdir, extensions, prepFunction in libs: localenv = prepFunction(env) - # objects = localenv.SharedObject(mglob(localenv, subdir, *extensions)) - # libraryTargets.extend(objects) - libName = 'ct' + subdir - if libName == 'ctf2c_blas': - libName = 'ctblas' - if libName == 'ctf2c_lapack': - libName = 'ctlapack' - if libName == 'ctf2c_math' : - libName = 'ctmath' - if libName == 'ctcvode/source' : - libName = 'cvode' - if libName == 'ctlibexecstream' : - libName = 'execstream' - if libName == 'ctf2c_libs': - libName = 'ctf2c' - - if localenv['renamed_shared_libraries'] : - sharedLibName = libName + '_shared' + if localenv['single_library']: + objects = localenv.SharedObject(mglob(localenv, subdir, *extensions)) + libraryTargets.extend(objects) else: - sharedLibName = libName + libName = 'ct' + subdir + if libName == 'ctf2c_blas': + libName = 'ctblas' + if libName == 'ctf2c_lapack': + libName = 'ctlapack' + if libName == 'ctf2c_math' : + libName = 'ctmath' + if libName == 'ctcvode/source' : + libName = 'cvode' + if libName == 'ctlibexecstream' : + libName = 'execstream' + if libName == 'ctf2c_libs': + libName = 'ctf2c' - # - # Build the static library - # - slTargets = [] + if localenv['renamed_shared_libraries'] : + sharedLibName = libName + '_shared' + else: + sharedLibName = libName - objects = localenv.SharedObject(mglob(localenv, subdir, *extensions)) - slTargets.extend(objects) - # ttarget = pjoin('..', 'lib', libName) - ss = pjoin('..', 'lib', libName) - lib = build(localenv.StaticLibrary(ss, slTargets, SPAWN=getSpawn(localenv))) - #lib = build(localenv.StaticLibrary('../lib/cantera', libraryTargets, - # SPAWN=getSpawn(localenv))) + objects = localenv.SharedObject(mglob(localenv, subdir, *extensions)) - install('$inst_libdir', lib) - # - # Build the shared library - # - liby = build(localenv.SharedLibrary(target = pjoin('..', 'lib', sharedLibName), source = mglob(localenv, subdir, *extensions))) - #liby = build(localenv.SharedLibrary(target = pjoin('..', 'lib', sharedLibName), source = mglob(localenv, subdir, *extensions), - # SPAWN=getSpawn(localenv))) - install('$inst_libdir', liby) + # Build the static library + lib = build(localenv.StaticLibrary(pjoin('..', 'lib', libName), objects)) + install('$inst_libdir', lib) + + # Build the shared library + liby = build(localenv.SharedLibrary(pjoin('..', 'lib', sharedLibName), objects)) + install('$inst_libdir', liby) localenv = env.Clone() diff --git a/src/matlab/SConscript b/src/matlab/SConscript index f8ffd328a..d839710b9 100644 --- a/src/matlab/SConscript +++ b/src/matlab/SConscript @@ -9,8 +9,7 @@ matlab_include = pjoin(localenv['matlab_path'], 'extern', 'include') if localenv['OS'] == 'Windows': mexPlatform = 'w' - linklibs = [] - linkLibs += env['cantera_shared_libs'] + linklibs = list(env['cantera_shared_libs']) linklibs += ['libmx', 'libmex', 'libmat'] if localenv['OS_BITS'] == 32: matlab_libs = pjoin(localenv['matlab_path'], 'extern', @@ -27,8 +26,7 @@ if localenv['OS'] == 'Windows': linkflags.extend(['-static-libgcc', '-static-libstdc++']) elif localenv['OS'] == 'Darwin': - linklibs = [] - linkLibs += env['cantera_libs'] + linklibs = list(env['cantera_libs']) linklibs += ['mx', 'mex', 'mat'] + env['LIBM'] mexPlatform = 'maci' linkflags.extend(['-Wl,-exported_symbol,_mexFunction']) @@ -39,8 +37,7 @@ elif localenv['OS'] == 'Darwin': matlab_libs = pjoin(localenv['matlab_path'], 'bin', 'macx86') elif os.name == 'posix': - linklibs = [] - linklibs += env['cantera_libs'] + linklibs = list(env['cantera_libs']) linklibs += ['mx', 'mex', 'mat'] + env['LIBM'] mexPlatform = 'a'