forked from Cantera/cantera
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SConstruct
1892 lines (1629 loc) · 75.4 KB
/
SConstruct
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
SCons build script for Cantera
Basic usage:
'scons help' - print a description of user-specifiable options.
'scons build' - Compile Cantera and the language interfaces using
default options.
'scons clean' - Delete files created while building Cantera.
'[sudo] scons install' - Install Cantera.
'[sudo] scons uninstall' - Uninstall Cantera.
'scons test' - Run all tests which did not previously pass or for which the
results may have changed.
'scons test-reset' - Reset the passing status of all tests.
'scons test-clean' - Delete files created while running the tests.
'scons test-help' - List available tests.
'scons test-NAME' - Run the test named "NAME".
'scons <command> dump' - Dump the state of the SCons environment to the
screen instead of doing <command>, e.g.
'scons build dump'. For debugging purposes.
'scons samples' - Compile the C++ and Fortran samples.
'scons msi' - Build a Windows installer (.msi) for Cantera.
'scons sphinx' - Build the Sphinx documentation
'scons doxygen' - Build the Doxygen documentation
"""
from __future__ import print_function
from buildutils import *
if not COMMAND_LINE_TARGETS:
# Print usage help
print(__doc__)
sys.exit(0)
valid_commands = ('build','clean','install','uninstall',
'help','msi','samples','sphinx','doxygen','dump')
for command in COMMAND_LINE_TARGETS:
if command not in valid_commands and not command.startswith('test'):
print('ERROR: unrecognized command line target: %r' % command)
sys.exit(0)
extraEnvArgs = {}
if 'clean' in COMMAND_LINE_TARGETS:
removeDirectory('build')
removeDirectory('stage')
removeDirectory('.sconf_temp')
removeFile('.sconsign.dblite')
removeFile('include/cantera/base/config.h')
removeFile('src/pch/system.h.gch')
removeDirectory('include/cantera/ext')
removeFile('interfaces/cython/cantera/_cantera.cpp')
removeFile('interfaces/cython/cantera/_cantera.h')
removeFile('interfaces/cython/setup.py')
removeFile('interfaces/python_minimal/setup.py')
removeFile('config.log')
removeDirectory('doc/sphinx/matlab/examples')
removeFile('doc/sphinx/matlab/examples.rst')
removeDirectory('doc/sphinx/matlab/code-docs')
removeDirectory('doc/sphinx/cython/examples')
removeFile('doc/sphinx/cython/examples.rst')
removeDirectory('interfaces/cython/Cantera.egg-info')
removeDirectory('interfaces/python_minimal/Cantera_minimal.egg-info')
for name in os.listdir('interfaces/cython/cantera/data/'):
if name != '__init__.py':
removeFile('interfaces/cython/cantera/data/' + name)
removeDirectory('interfaces/cython/cantera/test/data/test_subdir')
for name in os.listdir('interfaces/cython/cantera/test/data/'):
if name != '__init__.py':
removeFile('interfaces/cython/cantera/test/data/' + name)
for name in os.listdir('.'):
if name.endswith('.msi'):
removeFile(name)
for name in os.listdir('site_scons/'):
if name.endswith('.pyc'):
removeFile('site_scons/' + name)
for name in os.listdir('site_scons/site_tools/'):
if name.endswith('.pyc'):
removeFile('site_scons/site_tools/' + name)
for name in os.listdir('interfaces/python_minimal/cantera'):
if name != '__init__.py':
removeFile('interfaces/python_minimal/cantera/' + name)
removeFile('interfaces/matlab/toolbox/cantera_shared.dll')
removeFile('interfaces/matlab/Contents.m')
removeFile('interfaces/matlab/ctpath.m')
for name in os.listdir('interfaces/matlab/toolbox'):
if name.startswith('ctmethods.'):
removeFile('interfaces/matlab/toolbox/' + name)
print('Done removing output files.')
if COMMAND_LINE_TARGETS == ['clean']:
# Just exit if there's nothing else to do
sys.exit(0)
else:
Alias('clean', [])
if 'test-clean' in COMMAND_LINE_TARGETS:
removeDirectory('build/test')
removeDirectory('test/work')
removeDirectory('build/python_local')
# ******************************************************
# *** Set system-dependent defaults for some options ***
# ******************************************************
print('INFO: SCons is using the following Python interpreter:', sys.executable)
opts = Variables('cantera.conf')
windows_compiler_options = []
if os.name == 'nt':
# On Windows, target the same architecture as the current copy of Python,
# unless the user specified another option.
if '64 bit' in sys.version:
target_arch = 'amd64'
else:
target_arch = 'x86'
# Make an educated guess about the right default compiler
if which('g++') and not which('cl.exe'):
defaultToolchain = 'mingw'
else:
defaultToolchain = 'msvc'
windows_compiler_options.extend([
('msvc_version',
"""Version of Visual Studio to use. The default is the newest
installed version. Specify '12.0' for Visual Studio 2013 or '14.0'
for Visual Studio 2015.""",
''),
EnumVariable(
'target_arch',
"""Target architecture. The default is the same architecture as the
installed version of Python.""",
target_arch, ('amd64', 'x86'))
])
opts.AddVariables(*windows_compiler_options)
pickCompilerEnv = Environment()
opts.Update(pickCompilerEnv)
if pickCompilerEnv['msvc_version']:
defaultToolchain = 'msvc'
windows_compiler_options.append(EnumVariable(
'toolchain',
"""The preferred compiler toolchain.""",
defaultToolchain, ('msvc', 'mingw', 'intel')))
opts.AddVariables(windows_compiler_options[-1])
opts.Update(pickCompilerEnv)
if pickCompilerEnv['toolchain'] == 'msvc':
toolchain = ['default']
if pickCompilerEnv['msvc_version']:
extraEnvArgs['MSVC_VERSION'] = pickCompilerEnv['msvc_version']
print('INFO: Compiling with MSVC', (pickCompilerEnv['msvc_version'] or
pickCompilerEnv['MSVC_VERSION']))
elif pickCompilerEnv['toolchain'] == 'mingw':
toolchain = ['mingw', 'f90']
extraEnvArgs['F77'] = None
# Next line fixes http://scons.tigris.org/issues/show_bug.cgi?id=2683
extraEnvArgs['WINDOWS_INSERT_DEF'] = 1
elif pickCompilerEnv['toolchain'] == 'intel':
toolchain = ['intelc'] # note: untested
extraEnvArgs['TARGET_ARCH'] = pickCompilerEnv['target_arch']
print('INFO: Compiling for architecture:', pickCompilerEnv['target_arch'])
print('INFO: Compiling using the following toolchain(s):', repr(toolchain))
else:
toolchain = ['default']
env = Environment(tools=toolchain+['textfile', 'subst', 'recursiveInstall', 'wix', 'gch'],
ENV={'PATH': os.environ['PATH']},
toolchain=toolchain,
**extraEnvArgs)
env['OS'] = platform.system()
env['OS_BITS'] = int(platform.architecture()[0][:2])
if 'cygwin' in env['OS'].lower():
env['OS'] = 'Cygwin' # remove Windows version suffix
# Fixes a linker error in Windows
if os.name == 'nt' and 'TMP' in os.environ:
env['ENV']['TMP'] = os.environ['TMP']
# Fixes issues with Python subprocesses. See http://bugs.python.org/issue13524
if os.name == 'nt':
env['ENV']['SystemRoot'] = os.environ['SystemRoot']
# Needed for Matlab to source ~/.matlab7rc.sh
if 'HOME' in os.environ:
env['ENV']['HOME'] = os.environ['HOME']
# Fix an issue with Unicode sneaking into the environment on Windows
if os.name == 'nt':
for key,val in env['ENV'].items():
env['ENV'][key] = str(val)
if 'FRAMEWORKS' not in env:
env['FRAMEWORKS'] = []
add_RegressionTest(env)
class defaults: pass
if os.name == 'posix':
defaults.prefix = '/usr/local'
defaults.boostIncDir = ''
env['INSTALL_MANPAGES'] = True
elif os.name == 'nt':
defaults.prefix = pjoin(os.environ['ProgramFiles'], 'Cantera')
defaults.boostIncDir = ''
env['INSTALL_MANPAGES'] = False
else:
print("Error: Unrecognized operating system '%s'" % os.name)
sys.exit(1)
compiler_options = [
('CXX',
"""The C++ compiler to use.""",
env['CXX']),
('CC',
"""The C compiler to use. This is only used to compile CVODE.""",
env['CC'])]
opts.AddVariables(*compiler_options)
opts.Update(env)
defaults.cxxFlags = ''
defaults.ccFlags = ''
defaults.noOptimizeCcFlags = '-O0'
defaults.optimizeCcFlags = '-O3'
defaults.debugCcFlags = '-g'
defaults.noDebugCcFlags = ''
defaults.debugLinkFlags = ''
defaults.noDebugLinkFlags = ''
defaults.warningFlags = '-Wall'
defaults.buildPch = False
env['pch_flags'] = []
env['openmp_flag'] = ['-fopenmp'] # used to generate sample build scripts
env['using_apple_clang'] = False
# Check if this is actually Apple's clang on macOS
if env['OS'] == 'Darwin':
result = subprocess.check_output([env.subst('$CC'), '--version']).decode('utf-8')
if 'clang' in result.lower() and result.startswith('Apple LLVM'):
env['using_apple_clang'] = True
env['openmp_flag'].insert(0, '-Xpreprocessor')
if 'gcc' in env.subst('$CC') or 'gnu-cc' in env.subst('$CC'):
defaults.optimizeCcFlags += ' -Wno-inline'
if env['OS'] == 'Cygwin':
# See http://stackoverflow.com/questions/18784112
defaults.cxxFlags = '-std=gnu++0x'
else:
defaults.cxxFlags = '-std=c++0x'
defaults.buildPch = True
env['pch_flags'] = ['-include', 'src/pch/system.h']
elif env['CC'] == 'cl': # Visual Studio
defaults.cxxFlags = ['/EHsc']
defaults.ccFlags = ['/MD', '/nologo',
'/D_SCL_SECURE_NO_WARNINGS', '/D_CRT_SECURE_NO_WARNINGS']
defaults.debugCcFlags = '/Zi /Fd${TARGET}.pdb'
defaults.noOptimizeCcFlags = '/Od /Ob0'
defaults.optimizeCcFlags = '/O2'
defaults.debugLinkFlags = '/DEBUG'
defaults.warningFlags = '/W3'
defaults.buildPch = True
env['pch_flags'] = ['/FIpch/system.h']
env['openmp_flag'] = ['/openmp']
elif 'icc' in env.subst('$CC'):
defaults.cxxFlags = '-std=c++0x'
defaults.ccFlags = '-vec-report0 -diag-disable 1478'
defaults.warningFlags = '-Wcheck'
env['openmp_flag'] = ['-openmp']
elif 'clang' in env.subst('$CC'):
defaults.ccFlags = '-fcolor-diagnostics'
defaults.cxxFlags = '-std=c++11'
defaults.buildPch = True
env['pch_flags'] = ['-include-pch', 'src/pch/system.h.gch']
else:
print("WARNING: Unrecognized C compiler '%s'" % env['CC'])
if env['OS'] in ('Windows', 'Darwin'):
defaults.threadFlags = ''
else:
defaults.threadFlags = '-pthread'
# InstallVersionedLib only fully functional in SCons >= 2.4.0
# SHLIBVERSION fails with MinGW: http://scons.tigris.org/issues/show_bug.cgi?id=3035
if (env['toolchain'] == 'mingw'
or StrictVersion(SCons.__version__) < StrictVersion('2.4.0')):
defaults.versionedSharedLibrary = False
else:
defaults.versionedSharedLibrary = True
defaults.fsLayout = 'compact' if env['OS'] == 'Windows' else 'standard'
defaults.env_vars = 'PATH,LD_LIBRARY_PATH,PYTHONPATH'
defaults.python_prefix = '$prefix' if env['OS'] != 'Windows' else ''
# Transform lists into strings to keep cantera.conf clean
for key,value in defaults.__dict__.items():
if isinstance(value, (list, tuple)):
setattr(defaults, key, ' '.join(value))
# **************************************
# *** Read user-configurable options ***
# **************************************
config_options = [
PathVariable(
'prefix',
'Set this to the directory where Cantera should be installed.',
defaults.prefix, PathVariable.PathAccept),
PathVariable(
'libdirname',
"""Set this to the directory where Cantera libraries should be installed.
Some distributions (e.g. Fedora/RHEL) use 'lib64' instead of 'lib' on 64-bit systems
or could use some other library directory name instead of 'lib' depends
on architecture and profile (e.g. Gentoo 'libx32' on x32 profile).
If user didn't set 'libdirname' configuration variable set it to default value 'lib'""",
'lib', PathVariable.PathAccept),
EnumVariable(
'python_package',
"""If you plan to work in Python, then you need the ``full`` Cantera Python
package. If, on the other hand, you will only use Cantera from some
other language (e.g. MATLAB or Fortran 90/95) and only need Python
to process CTI files, then you only need a ``minimal`` subset of the
package and Cython and NumPy are not necessary. The ``none`` option
doesn't install any components of the Python interface. The default
behavior is to build the full Python module for whichever version of
Python is running SCons if the required prerequisites (NumPy and
Cython) are installed. Note: ``y`` is a synonym for ``full`` and ``n``
is a synonym for ``none``.""",
'default', ('new', 'full', 'minimal', 'none', 'n', 'y', 'default')),
PathVariable(
'python_cmd',
"""Cantera needs to know where to find the Python interpreter. If
PYTHON_CMD is not set, then the configuration process will use the
same Python interpreter being used by SCons.""",
sys.executable, PathVariable.PathAccept),
PathVariable(
'python_prefix',
"""Use this option if you want to install the Cantera Python package to
an alternate location. On Unix-like systems, the default is the same
as the 'prefix' option. If the 'python_prefix' option is set to
the empty string or the 'prefix' option is not set, then the package
will be installed to the system default 'site-packages' directory.
To install to the current user's 'site-packages' directory, use
'python_prefix=USER'.""",
defaults.python_prefix, PathVariable.PathAccept),
EnumVariable(
'python3_package',
"""Deprecated synonym for the 'python_package' option. Will be overridden
if 'python_package' is set.""",
'default', ('full', 'minimal', 'y', 'n', 'none', 'default')),
PathVariable(
'python3_cmd',
"""Deprecated synonym for the 'python_cmd' option. Will be overridden
if 'python_cmd' is set.""",
sys.executable, PathVariable.PathAccept),
PathVariable(
'python3_prefix',
"""Deprecated synonym for the 'python_prefix' option. Will be overridden
if 'python_prefix' is set.""",
defaults.python_prefix, PathVariable.PathAccept),
EnumVariable(
'matlab_toolbox',
"""This variable controls whether the MATLAB toolbox will be built. If
set to 'y', you will also need to set the value of the 'matlab_path'
variable. If set to 'default', the MATLAB toolbox will be built if
'matlab_path' is set.""",
'default', ('y', 'n', 'default')),
PathVariable(
'matlab_path',
"""Path to the MATLAB install directory. This should be the directory
containing the 'extern', 'bin', etc. subdirectories. Typical values
are: "C:/Program Files/MATLAB/R2011a" on Windows,
"/Applications/MATLAB_R2011a.app" on OS X, or
"/opt/MATLAB/R2011a" on Linux.""",
'', PathVariable.PathAccept),
EnumVariable(
'f90_interface',
"""This variable controls whether the Fortran 90/95 interface will be
built. If set to 'default', the builder will look for a compatible
Fortran compiler in the 'PATH' environment variable, and compile
the Fortran 90 interface if one is found.""",
'default', ('y', 'n', 'default')),
PathVariable(
'FORTRAN',
"""The Fortran (90) compiler. If unspecified, the builder will look for
a compatible compiler (gfortran, ifort, g95) in the 'PATH' environment
variable. Used only for compiling the Fortran 90 interface.""",
'', PathVariable.PathAccept),
('FORTRANFLAGS',
'Compilation options for the Fortran (90) compiler.',
'-O3'),
BoolVariable(
'coverage',
"""Enable collection of code coverage information with gcov.
Available only when compiling with gcc.""",
False),
BoolVariable(
'doxygen_docs',
"""Build HTML documentation for the C++ interface using Doxygen.""",
False),
BoolVariable(
'sphinx_docs',
"""Build HTML documentation for Cantera using Sphinx.""",
False),
PathVariable(
'sphinx_cmd',
"""Command to use for building the Sphinx documentation.""",
'sphinx-build', PathVariable.PathAccept),
EnumVariable(
'system_eigen',
"""Select whether to use Eigen from a system installation ('y'), from a
Git submodule ('n'), or to decide automatically ('default'). If Eigen
is not installed directly into a system include directory, e.g. it is
installed in '/opt/include/eigen3/Eigen', then you will need to add
'/opt/include/eigen3' to 'extra_inc_dirs'.
""",
'default', ('default', 'y', 'n')),
EnumVariable(
'system_fmt',
"""Select whether to use the fmt library from a system installation
('y'), from a Git submodule ('n'), or to decide automatically
('default').""",
'default', ('default', 'y', 'n')),
EnumVariable(
'system_yamlcpp',
"""Select whether to use the yaml-cpp library from a system installation
('y'), from a Git submodule ('n'), or to decide automatically
('default'). If yaml-cpp is not installed directly into system
include and library directories, then you will need to add those
directories to 'extra_inc_dirs' and 'extra_lib_dirs'.""",
'default', ('default', 'y', 'n')),
EnumVariable(
'system_sundials',
"""Select whether to use SUNDIALS from a system installation ('y'), from
a Git submodule ('n'), or to decide automatically ('default').
Specifying 'sundials_include' or 'sundials_libdir' changes the
default to 'y'.""",
'default', ('default', 'y', 'n')),
PathVariable(
'sundials_include',
"""The directory where the SUNDIALS header files are installed. This
should be the directory that contains the "cvodes", "nvector", etc.
subdirectories. Not needed if the headers are installed in a
standard location, e.g., '/usr/include'.""",
'', PathVariable.PathAccept),
PathVariable(
'sundials_libdir',
"""The directory where the SUNDIALS static libraries are installed.
Not needed if the libraries are installed in a standard location,
e.g., '/usr/lib'.""",
'', PathVariable.PathAccept),
(
'blas_lapack_libs',
"""Cantera can use BLAS and LAPACK libraries available on your system if
you have optimized versions available (e.g., Intel MKL). Otherwise,
Cantera will use Eigen for linear algebra support. To use BLAS
and LAPACK, set 'blas_lapack_libs' to the the list of libraries
that should be passed to the linker, separated by commas, e.g.,
"lapack,blas" or "lapack,f77blas,cblas,atlas". Eigen is required
whether or not BLAS/LAPACK are used.""",
''),
PathVariable(
'blas_lapack_dir',
"""Directory containing the libraries specified by 'blas_lapack_libs'. Not
needed if the libraries are installed in a standard location, e.g.
``/usr/lib``.""",
'', PathVariable.PathAccept),
EnumVariable(
'lapack_names',
"""Set depending on whether the procedure names in the specified
libraries are lowercase or uppercase. If you don't know, run 'nm' on
the library file (e.g., 'nm libblas.a').""",
'lower', ('lower','upper')),
BoolVariable(
'lapack_ftn_trailing_underscore',
"""Controls whether the LAPACK functions have a trailing underscore
in the Fortran libraries.""",
True),
BoolVariable(
'lapack_ftn_string_len_at_end',
"""Controls whether the LAPACK functions have the string length
argument at the end of the argument list ('yes') or after
each argument ('no') in the Fortran libraries.""",
True),
EnumVariable(
'system_googletest',
"""Select whether to use gtest/gmock from system
installation ('y'), from a Git submodule ('n'), or to decide
automatically ('default'). Deprecated option, please use 'googletest' instead.
This option is suppressed by 'googletest' option.""",
'unspecified', ('unspecified','default', 'y', 'n')),
EnumVariable(
'googletest',
"""Select whether to use gtest/gmock from system
installation ('system'), from a Git submodule ('submodule'), to decide
automatically ('default') or don't look for gtest/gmock ('none')
and don't run tests that depend on gtest/gmock. If this option is
set then it suppresses the deprecated 'system_googletest' option.""",
'default', ('default', 'system', 'submodule', 'none')),
(
'env_vars',
"""Environment variables to propagate through to SCons. Either the
string "all" or a comma separated list of variable names, e.g.
'LD_LIBRARY_PATH,HOME'.""",
defaults.env_vars),
BoolVariable(
'use_pch',
"""Use a precompiled-header to speed up compilation""",
defaults.buildPch),
(
'cxx_flags',
"""Compiler flags passed to the C++ compiler only. Separate multiple
options with spaces, e.g., "cxx_flags='-g -Wextra -O3 --std=c++11'"
""",
defaults.cxxFlags),
(
'cc_flags',
"""Compiler flags passed to both the C and C++ compilers, regardless of optimization level.""",
defaults.ccFlags),
(
'thread_flags',
"""Compiler and linker flags for POSIX multithreading support.""",
defaults.threadFlags),
BoolVariable(
'optimize',
"""Enable extra compiler optimizations specified by the
'optimize_flags' variable, instead of the flags specified by the
'no_optimize_flags' variable.""",
True),
(
'optimize_flags',
"""Additional compiler flags passed to the C/C++ compiler when 'optimize=yes'.""",
defaults.optimizeCcFlags),
(
'no_optimize_flags',
"""Additional compiler flags passed to the C/C++ compiler when 'optimize=no'.""",
defaults.noOptimizeCcFlags),
BoolVariable(
'debug',
"""Enable compiler debugging symbols.""",
True),
(
'debug_flags',
"""Additional compiler flags passed to the C/C++ compiler when 'debug=yes'.""",
defaults.debugCcFlags),
(
'no_debug_flags',
"""Additional compiler flags passed to the C/C++ compiler when 'debug=no'.""",
defaults.noDebugCcFlags),
(
'debug_linker_flags',
"""Additional options passed to the linker when 'debug=yes'.""",
defaults.debugLinkFlags),
(
'no_debug_linker_flags',
"""Additional options passed to the linker when 'debug=no'.""",
defaults.noDebugLinkFlags),
(
'warning_flags',
"""Additional compiler flags passed to the C/C++ compiler to enable
extra warnings. Used only when compiling source code that is part
of Cantera (e.g. excluding code in the 'ext' directory).""",
defaults.warningFlags),
(
'extra_inc_dirs',
"""Additional directories to search for header files (colon-separated list).""",
''),
(
'extra_lib_dirs',
"""Additional directories to search for libraries (colon-separated list).""",
''),
PathVariable(
'boost_inc_dir',
"""Location of the Boost header files. Not needed if the headers are
installed in a standard location, e.g. '/usr/include'.""",
defaults.boostIncDir, PathVariable.PathAccept),
PathVariable(
'stage_dir',
"""Directory relative to the Cantera source directory to be
used as a staging area for building e.g. a Debian
package. If specified, 'scons install' will install files
to 'stage_dir/prefix/...'.""",
'',
PathVariable.PathAccept),
BoolVariable(
'VERBOSE',
"""Create verbose output about what SCons is doing.""",
False),
(
'gtest_flags',
"""Additional options passed to each GTest test suite, e.g.
'--gtest_filter=*pattern*'. Separate multiple options with spaces.""",
''),
BoolVariable(
'renamed_shared_libraries',
"""If this option is turned on, 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 libraries and avoids a bug with using valgrind with
the '-static' linking flag.""",
True),
BoolVariable(
'versioned_shared_library',
"""If enabled, create a versioned shared library, with symlinks to the
more generic library name, e.g. 'libcantera_shared.so.2.5.0' as the
actual library and 'libcantera_shared.so' and 'libcantera_shared.so.2'
as symlinks.
""",
defaults.versionedSharedLibrary),
BoolVariable(
'use_rpath_linkage',
"""If enabled, link to all shared libraries using 'rpath', i.e., a fixed
run-time search path for dynamic library loading.""",
True),
EnumVariable(
'layout',
"""The layout of the directory structure. 'standard' installs files to
several subdirectories under 'prefix', e.g. 'prefix/bin',
'prefix/include/cantera', 'prefix/lib' etc. This layout is best used in
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.""",
defaults.fsLayout, ('standard','compact','debian'))
]
opts.AddVariables(*config_options)
opts.Update(env)
opts.Save('cantera.conf', env)
# Expand ~/ and environment variables used in cantera.conf (variables used on
# the command line will be expanded by the shell)
for option in opts.keys():
original = env[option]
if isinstance(original, str):
modified = os.path.expandvars(os.path.expanduser(env[option]))
if original != modified:
print('INFO: Expanding {!r} to {!r}'.format(original, modified))
env[option] = modified
if 'help' in COMMAND_LINE_TARGETS:
### Print help about configuration options and exit.
print("""
**************************************************
* Configuration options for building Cantera *
**************************************************
The following options can be passed to SCons to customize the Cantera
build process. They should be given in the form:
scons build option1=value1 option2=value2
Variables set in this way will be stored in the 'cantera.conf' file and reused
automatically on subsequent invocations of scons. Alternatively, the
configuration options can be entered directly into 'cantera.conf' before
running 'scons build'. The format of this file is:
option1 = 'value1'
option2 = 'value2'
**************************************************
""")
for opt in opts.options:
print('\n'.join(formatOption(env, opt)))
sys.exit(0)
if 'doxygen' in COMMAND_LINE_TARGETS:
env['doxygen_docs'] = True
if 'sphinx' in COMMAND_LINE_TARGETS:
env['sphinx_docs'] = True
valid_arguments = (set(opt[0] for opt in windows_compiler_options) |
set(opt[0] for opt in compiler_options) |
set(opt[0] for opt in config_options))
for arg in ARGUMENTS:
if arg not in valid_arguments:
print('Encountered unexpected command line argument: %r' % arg)
sys.exit(1)
# Require a StrictVersion-compatible version
env['cantera_version'] = "2.5.0a3"
ctversion = StrictVersion(env['cantera_version'])
# For use where pre-release tags are not permitted (MSI, sonames)
env['cantera_pure_version'] = '.'.join(str(x) for x in ctversion.version)
env['cantera_short_version'] = '.'.join(str(x) for x in ctversion.version[:2])
try:
env['git_commit'] = getCommandOutput('git', 'rev-parse', '--short', 'HEAD')
except Exception:
env['git_commit'] = 'unknown'
# Print values of all build options:
print("Configuration variables read from 'cantera.conf' and command line:")
for line in open('cantera.conf'):
print(' ', line.strip())
print()
# ********************************************
# *** Configure system-specific properties ***
# ********************************************
# Copy in external environment variables
if env['env_vars'] == 'all':
env['ENV'].update(os.environ)
if 'PYTHONHOME' in env['ENV']:
del env['ENV']['PYTHONHOME']
elif env['env_vars']:
for name in env['env_vars'].split(','):
if name in os.environ:
if name == 'PATH':
env.AppendENVPath('PATH', os.environ['PATH'])
else:
env['ENV'][name] = os.environ[name]
if env['VERBOSE']:
print('Propagating environment variable {0}={1}'.format(name, env['ENV'][name]))
elif name not in defaults.env_vars.split(','):
print('WARNING: failed to propagate environment variable', repr(name))
print(' Edit cantera.conf or the build command line to fix this.')
env['extra_inc_dirs'] = [d for d in env['extra_inc_dirs'].split(':') if d]
env['extra_lib_dirs'] = [d for d in env['extra_lib_dirs'].split(':') if d]
env.Append(CPPPATH=env['extra_inc_dirs'],
LIBPATH=env['extra_lib_dirs'])
if env['use_rpath_linkage']:
env.Append(RPATH=env['extra_lib_dirs'])
if env['CC'] == 'cl':
# embed manifest file
env['LINKCOM'] = [env['LINKCOM'],
'if exist ${TARGET}.manifest mt.exe -nologo -manifest ${TARGET}.manifest -outputresource:$TARGET;1']
env['SHLINKCOM'] = [env['SHLINKCOM'],
'if exist ${TARGET}.manifest mt.exe -nologo -manifest ${TARGET}.manifest -outputresource:$TARGET;2']
if env['boost_inc_dir']:
env.Append(CPPPATH=env['boost_inc_dir'])
if env['blas_lapack_dir']:
env.Append(LIBPATH=[env['blas_lapack_dir']])
if env['use_rpath_linkage']:
env.Append(RPATH=env['blas_lapack_dir'])
if env['system_sundials'] in ('y','default'):
if env['sundials_include']:
env.Append(CPPPATH=[env['sundials_include']])
env['system_sundials'] = 'y'
if env['sundials_libdir']:
env.Append(LIBPATH=[env['sundials_libdir']])
env['system_sundials'] = 'y'
if env['use_rpath_linkage']:
env.Append(RPATH=env['sundials_libdir'])
# BLAS / LAPACK configuration
if env['blas_lapack_libs'] != '':
env['blas_lapack_libs'] = env['blas_lapack_libs'].split(',')
env['use_lapack'] = True
elif env['OS'] == 'Darwin':
env['blas_lapack_libs'] = []
env['use_lapack'] = True
env.Append(FRAMEWORKS=['Accelerate'])
else:
env['blas_lapack_libs'] = []
env['use_lapack'] = False
# ************************************
# *** Compiler Configuration Tests ***
# ************************************
def CheckStatement(context, function, includes=""):
context.Message('Checking for %s... ' % function)
src = """
%(include)s
int main(int argc, char** argv) {
%(func)s;
return 0;
}
""" % {'func':function, 'include':includes}
result = context.TryCompile(src, '.cpp')
context.Result(result)
return result
conf = Configure(env, custom_tests={'CheckStatement': CheckStatement})
# Set up compiler options before running configuration tests
env['CXXFLAGS'] = listify(env['cxx_flags'])
env['CCFLAGS'] = listify(env['cc_flags']) + listify(env['thread_flags'])
env['LINKFLAGS'] += listify(env['thread_flags'])
env['CPPDEFINES'] = {}
env['warning_flags'] = listify(env['warning_flags'])
if env['optimize']:
env['CCFLAGS'] += listify(env['optimize_flags'])
env.Append(CPPDEFINES=['NDEBUG'])
else:
env['CCFLAGS'] += listify(env['no_optimize_flags'])
if env['debug']:
env['CCFLAGS'] += listify(env['debug_flags'])
env['LINKFLAGS'] += listify(env['debug_linker_flags'])
else:
env['CCFLAGS'] += listify(env['no_debug_flags'])
env['LINKFLAGS'] += listify(env['no_debug_linker_flags'])
if env['coverage']:
if 'gcc' in env.subst('$CC') or 'clang' in env.subst('$CC'):
env.Append(CCFLAGS=['-fprofile-arcs', '-ftest-coverage'])
env.Append(LINKFLAGS=['-fprofile-arcs', '-ftest-coverage'])
else:
print('Error: coverage testing is only available with GCC.')
exit(0)
if env['toolchain'] == 'mingw':
env.Append(LINKFLAGS=['-static-libgcc', '-static-libstdc++'])
def config_error(message):
print('ERROR:', message)
if env['VERBOSE']:
print('*' * 25, 'Contents of config.log:', '*' * 25)
print(open('config.log').read())
print('*' * 28, 'End of config.log', '*' * 28)
else:
print("See 'config.log' for details.")
sys.exit(1)
# First, a sanity check:
if not conf.CheckCXXHeader('cmath', '<>'):
config_error('The C++ compiler is not correctly configured.')
def get_expression_value(includes, expression):
s = ['#include ' + i for i in includes]
s.extend(('#define Q(x) #x',
'#define QUOTE(x) Q(x)',
'#include <iostream>',
'#ifndef SUNDIALS_PACKAGE_VERSION', # name change in Sundials >= 3.0
'#define SUNDIALS_PACKAGE_VERSION SUNDIALS_VERSION',
'#endif',
'int main(int argc, char** argv) {',
' std::cout << %s << std::endl;' % expression,
' return 0;',
'}\n'))
return '\n'.join(s)
# Check for fmt library and checkout submodule if needed
# Test for 'ostream.h' to ensure that version >= 3.0.0 is available
if env['system_fmt'] in ('y', 'default'):
if conf.CheckCXXHeader('fmt/ostream.h', '""'):
env['system_fmt'] = True
print("""INFO: Using system installation of fmt library.""")
elif env['system_fmt'] == 'y':
config_error('Expected system installation of fmt library, but it '
'could not be found.')
if env['system_fmt'] in ('n', 'default'):
env['system_fmt'] = False
print("""INFO: Using private installation of fmt library.""")
if not os.path.exists('ext/fmt/include/fmt/ostream.h'):
if not os.path.exists('.git'):
config_error('fmt is missing. Install source in ext/fmt.')
try:
code = subprocess.call(['git','submodule','update','--init',
'--recursive','ext/fmt'])
except Exception:
code = -1
if code:
config_error('fmt submodule checkout failed.\n'
'Try manually checking out the submodule with:\n\n'
' git submodule update --init --recursive ext/fmt\n')
fmt_include = '<fmt/format.h>' if env['system_fmt'] else '"../ext/fmt/include/fmt/format.h"'
fmt_version_source = get_expression_value([fmt_include], 'FMT_VERSION')
retcode, fmt_lib_version = conf.TryRun(fmt_version_source, '.cpp')
try:
fmt_lib_version = divmod(float(fmt_lib_version.strip()), 10000)
(fmt_maj, (fmt_min, fmt_pat)) = fmt_lib_version[0], divmod(fmt_lib_version[1], 100)
env['FMT_VERSION'] = '{major:.0f}.{minor:.0f}.{patch:.0f}'.format(major=fmt_maj, minor=fmt_min, patch=fmt_pat)
print('INFO: Found fmt version {}'.format(env['FMT_VERSION']))
except ValueError:
env['FMT_VERSION'] = '0.0.0'
print('INFO: Could not find version of fmt')
# Convert setting of the deprecated system_googletest option
if env['system_googletest'] != 'unspecified':
print("WARNING: The 'system_googletest' option is deprecated. "
"Use the 'googletest' option instead.")
if env['system_googletest'] == 'default':
env['googletest'] = 'default'
elif env['system_googletest'] == 'y':
env['googletest'] = 'system'
elif env['system_googletest'] == 'n':
env['googletest'] = 'submodule'
# Check for yaml-cpp library and checkout submodule if needed
if env['system_yamlcpp'] in ('y', 'default'):
if conf.CheckCXXHeader('yaml-cpp/yaml.h', '""'):
env['system_yamlcpp'] = True
print("""INFO: Using system installation of yaml-cpp library.""")
elif env['system_yamlcpp'] == 'y':
config_error('Expected system installation of yaml-cpp library, but it '
'could not be found.')
if env['system_yamlcpp'] in ('n', 'default'):
env['system_yamlcpp'] = False
print("""INFO: Using private installation of yaml-cpp library.""")
if not os.path.exists('ext/yaml-cpp/include/yaml-cpp/yaml.h'):
if not os.path.exists('.git'):
config_error('yaml-cpp is missing. Install source in ext/yaml-cpp.')
try:
code = subprocess.call(['git', 'submodule', 'update', '--init',
'--recursive', 'ext/yaml-cpp'])
except Exception:
code = -1
if code:
config_error('yaml-cpp submodule checkout failed.\n'
'Try manually checking out the submodule with:\n\n'
' git submodule update --init --recursive ext/yaml-cpp\n')
# Check for googletest and checkout submodule if needed
if env['googletest'] in ('system', 'default'):
has_gtest = conf.CheckCXXHeader('gtest/gtest.h', '""')
has_gmock = conf.CheckCXXHeader('gmock/gmock.h', '""')
if has_gtest and has_gmock:
env['googletest'] = 'system'
print("""INFO: Using system installation of Googletest""")
elif env['googletest'] == 'system':
config_error('Expected system installation of Googletest-1.8.0, but it '
'could not be found.')
if env['googletest'] in ('submodule', 'default'):
env['googletest'] = 'submodule'
has_gtest = os.path.exists('ext/googletest/googletest/include/gtest/gtest.h')
has_gmock = os.path.exists('ext/googletest/googlemock/include/gmock/gmock.h')
if not (has_gtest and has_gmock):
if not os.path.exists('.git'):
config_error('Googletest is missing. Install source in ext/googletest.')
try:
code = subprocess.call(['git','submodule','update','--init',
'--recursive','ext/googletest'])
except Exception:
code = -1
if code:
config_error('Googletest not found and submodule checkout failed.\n'
'Try manually checking out the submodule with:\n\n'
' git submodule update --init --recursive ext/googletest\n')
print("""INFO: Using Googletest from Git submodule""")
if env['googletest'] == 'none':
print("""INFO: Not using Googletest -- unable to run complete test suite""")
# Check for Eigen and checkout submodule if needed
if env['system_eigen'] in ('y', 'default'):
if conf.CheckCXXHeader('Eigen/Dense', '<>'):
env['system_eigen'] = True
print("""INFO: Using system installation of Eigen.""")
elif env['system_eigen'] == 'y':
config_error('Expected system installation of Eigen, but it '
'could not be found.')
if env['system_eigen'] in ('n', 'default'):
env['system_eigen'] = False
print("""INFO: Using private installation of Eigen.""")
if not os.path.exists('ext/eigen/Eigen/Dense'):