-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup
executable file
·770 lines (692 loc) · 29.1 KB
/
setup
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
#!/usr/bin/env python
# vim:ft=python
#
# primitive frontend to cmake
# (c) Radovan Bast <[email protected]>
# (c) Jonas Juselius <[email protected]>
# licensed under the GNU Lesser General Public License
# Ported to Psi4 by Roberto Di Remigio Oct. 2014
# based on initial work by Andy Simmonett (May 2013)
import os
import sys
import string
import re
import subprocess
import shutil
import datetime
sys.path.append('cmake')
import argparse
root_directory = os.path.dirname(os.path.realpath(__file__))
default_path = os.path.join(root_directory, 'objdir')
if root_directory != os.getcwd():
default_path = os.getcwd()
def parse_input():
parser = argparse.ArgumentParser(description="Configure Psi4 using CMake",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('builddir', nargs='?',
action='store',
default=default_path,
help='build directory [default: %(default)s]',
metavar='OBJDIR')
group = parser.add_argument_group('Basic options')
# The C compiler
group.add_argument('--cc',
action='store',
default=None,
help='set the C compiler [default: pick automatically or based on CC=...]',
metavar='STRING')
# The C++ compiler
group.add_argument('--cxx',
action='store',
default=None,
help='set the C++ compiler [default: pick automatically or based on CXX=...]',
metavar='STRING')
# The Fortran compiler
group.add_argument('--fc',
action='store',
default=None,
help='set the Fortran compiler [default: pick automatically or based on FC=...]',
metavar='STRING')
# Libint maximum angular momentum.
parser.add_argument('--max-am-eri',
metavar="MAX_ANGULAR_MOMENTUM",
type=int,
default=5,
help="""The maximum angular momentum level (1=p, 2=d, 3=f, etc.) for the libint and libderiv packages.
Note: A value of N implies a maximum first derivative of N-1, and maximum second derivative of N-2.
[default: %(default)s]""")
# Release, debug or profiling build
group.add_argument('--type',
nargs='?',
action='store',
type=str,
choices=('release', 'debug', 'profile'),
default='release',
help='set the CMake build type [default: %(default)s]')
# Install prefix
group.add_argument('--prefix',
action='store',
type=str,
default='/usr/local/psi4',
help='set the install path for make install [default: %(default)s]',
metavar='PATH')
# Show CMake command
group.add_argument('--show',
action='store_true',
default=False,
help='show CMake command and exit [default: %(default)s]')
group.add_argument('--cmake',
action='store',
type=str,
default='cmake',
help='set the CMake executable to use [default: cmake; e.g. --cmake cmake28]',
metavar='STRING')
group = parser.add_argument_group('Boost and Python options')
group.add_argument('--boost-incdir',
action='store',
default=None,
help="""The includes directory for boost.
'boost/version.hpp' should be in this directory.
If this is left blank cmake will attempt to find one on your system.
Failing that it will build one for you""",
metavar='PATH')
group.add_argument('--boost-libdir',
action='store',
default=None,
help="""The libraries directory for boost.
If this is left blank cmake will attempt to find one on your system.
Failing that it will build one for you""",
metavar='PATH')
group.add_argument('--python',
metavar='PYTHON',
action='store',
default=None,
help="""The Python interpreter (development version) to use. CMake will detect one automatically, if omitted.""")
group = parser.add_argument_group('Parallelization')
group.add_argument('--mpi',
action='store_true',
default=False,
help='enable MPI [default: %(default)s]')
group.add_argument('--sgi-mpt',
action='store_true',
default=False,
help='enable SGI MPT [default: %(default)s]')
group.add_argument('--omp',
# at present, there's no way to turn this off. recc switch to on/off
action='store_true',
default=True,
help='enable OpenMP [default: %(default)s]')
group = parser.add_argument_group('Math libraries')
group.add_argument('--mkl',
nargs='?',
action='store',
choices=('sequential', 'parallel', 'cluster'),
default='none',
help='pass -mkl=STRING flag to the compiler and linker [default: None]')
group.add_argument('--blas',
action='store',
default='auto',
help='specify BLAS library; possible choices are "auto", "builtin", "none", or full path [default: %(default)s]',
metavar='[{auto,builtin,none,/full/path/lib.a}]')
group.add_argument('--lapack',
action='store',
default='auto',
help='specify LAPACK library; possible choices are "auto", "builtin", "none", or full path [default: %(default)s]',
metavar='[{auto,builtin,none,/full/path/lib.a}]')
group.add_argument('--extra-math-flags',
action='store',
default=None,
help='extra linker flags (usually -Llibdir -llibname type arguments). use equals, quotes, and spaces for correct parsing (e.g., --extra-math-flags="-lm -lgfortran") [default: %(default)s]',
metavar='STRING')
group.add_argument('--accelerate',
action='store_true',
default=False,
help='build using Mac OS X Accelerate Framework [default: %(default)s]')
group.add_argument('--cray',
action='store_true',
default=False,
help='use cray wrappers for BLAS/LAPACK and MPI which disables math detection and builtin math implementation [default: %(default)s]')
group.add_argument('--csr',
action='store_true',
default=False,
help='build using MKL compressed sparse row [default: %(default)s]')
group.add_argument('--scalapack',
action='store_true',
default=False,
help='build using SCALAPACK [default: %(default)s]')
group.add_argument('--scalasca',
action='store_true',
default=False,
help='build using SCALASCA profiler mode [default: %(default)s]')
# Advanced options
group = parser.add_argument_group('Advanced options')
# C++11 support (CMake will detect what's available)
group.add_argument('--cxx11',
nargs='?',
action='store',
choices=('on', 'off'),
default='on',
help='C++11 support [default: %(default)s]')
# Plugins
group.add_argument('--plugins',
nargs='?',
action='store',
choices=('on', 'off'),
default='off',
help='Build the example plugins [default: %(default)s]')
# Suffix for the psi4 executable
group.add_argument('--suffix',
type=str,
action='store',
default='',
help="Append the given suffix to the psi4 executable [default: %(default)s]",
metavar='STRING')
group.add_argument('--check',
action='store_true',
default=False,
help='enable bounds checking [default: %(default)s]')
group.add_argument('--memcheck',
action='store_true',
default=False,
help='enable memcheck build with Valgrind [default: %(default)s]')
group.add_argument('--coverage',
action='store_true',
default=False,
help='enable code coverage [default: %(default)s]')
group.add_argument('--static',
action='store_true',
default=False,
help='link statically [default: %(default)s]')
group.add_argument('--unit-tests',
action='store_true',
default=False,
help='build unit test suite [default: %(default)s]')
group.add_argument('--vectorization',
action='store_true',
default=False,
help='enable vectorization [default: %(default)s]')
group.add_argument('-D',
action="append",
dest='define',
default=[],
help="""forward directly to cmake (example: -D ENABLE_THIS=1 -D ENABLE_THAT=1);
you can also forward CPP definitions all the way to the program
(example: -D CPP="-DDEBUG"); also handle multi-word arguments
(example: -D MORELIBS="-L/path/to/lib /path/to/lib2")""",
metavar='STRING')
group.add_argument('--host',
action='store',
default=None,
help="use predefined defaults for 'host'",
metavar='STRING')
group.add_argument('--generator',
action='store',
default=None,
help='set the cmake generator [default: %(default)s]',
metavar='STRING')
group.add_argument('--timings',
action='store_true',
default=False,
help='build using timings [default: %(default)s]')
group = parser.add_mutually_exclusive_group(required=False)
group.add_argument('--asan',
action='store_true',
default=False,
help='enable address sanitizer (ASan) build [default: %(default)s]')
group.add_argument('--msan',
action='store_true',
default=False,
help='enable memory sanitizer (MSan) build [default: %(default)s]')
group.add_argument('--tsan',
action='store_true',
default=False,
help='enable thread sanitizer (TSan) build [default: %(default)s]')
group.add_argument('--ubsan',
action='store_true',
default=False,
help='enable undefined behaviour sanitizer (UBSan) build [default: %(default)s]')
group = parser.add_argument_group('External quantum chemistry libraries')
# For the external QC libraries section, let's explicitly set no
# defaults and defer the logic to CMakeLists.txt. This setup script
# will translate explicit user prefs into CMake options but let CMake
# handle user indifference.
# conda psi4metapackage
group.add_argument('--metapackage-dir',
action='store',
default=None,
help="""The install directory for a pre-installed conda
psi4metapackage to supply dependencies and add-ons.""",
metavar='PATH')
# ERD package
group.add_argument('--erd',
action='store',
choices=('on', 'off'),
default=None,
help="""Add support for the ERD integral package (requires Fortran). If this is left blank,
LibERD will not be included.""")
# JK_Factory
group.add_argument('--jkfactory',
action='store',
choices=('on', 'off'),
default=None,
help="""Enable distributed J and K builds (requires Fortran). If this is left blank,
JKFactory will not be included.""")
# GDMA package
group.add_argument('--gdma',
action='store',
choices=('on', 'off'),
default=None,
help="""Add support for the GDMA distributed multipole analysis package (requires Fortran). If this is left blank,
LibGDMA will not be included.""")
# GPU_DFCC package
group.add_argument('--gpu-dfcc',
action='store',
choices=('on', 'off'),
default=None,
help="""Enable GPU_DFCC external project. If this is left blank,
GPU_DFCC will not be included.""")
# Dummy plugin
group.add_argument('--dummy-plugin',
action='store',
choices=('on', 'off'),
default=None,
help="""Enable dummy plugin external project. If this is left blank,
the dummy plugin will not be included.""")
# PCMSolver package
group.add_argument('--pcmsolver',
action='store',
choices=('on', 'off'),
default=None,
help="""Enable PCMSolver external project (requires Fortran, zlib). If this is left blank,
PCMSolver will be included if Fortran compiler specified, otherwise not.""")
group.add_argument('--pcmsolver-dir',
action='store',
default=None,
help="""The install directory for a pre-built PCMSolver.
'lib/libpcm.so' and 'include/pcmsolver/pcmsolver.h' should be in this directory.
If this is left blank cmake will build one for you.""",
metavar='PATH')
# CheMPS2 package
group.add_argument('--chemps2',
action='store',
choices=('on', 'off'),
default=None,
help="""Enable CheMPS2 external project (requires hdf5, gsl, zlib). If this is left blank,
CheMPS2 will be included.""")
group.add_argument('--chemps2-dir',
action='store',
default=None,
help="""The install directory for a pre-built CheMPS2.
'lib/chemps2.so' and 'include/chemps2/DMRG.h' should be in this directory.
If this is left blank cmake will build one for you.""",
metavar='PATH')
# Ambit
group.add_argument('--ambit',
action='store',
choices=('on', 'off'),
default=None,
help="""Enable Ambit external project (requires hdf5).""")
group.add_argument('--ambit-dir',
action='store',
default=None,
help="""The install directory for a pre-built Ambit.
'lib/libambit.a' and 'include/ambit/tensor.h' should be in this directory.
If this is left blank cmake will build one for you.""",
metavar='PATH')
group = parser.add_argument_group('External libraries')
# ZLIB
group.add_argument('--zlib-dir',
action='store',
default=None,
help="""The root directory for zlib.
'include/zlib.h' and 'lib/libz.so' (or similar) should be in this directory.
If this is left blank cmake will attempt to find one on your system.""",
metavar='PATH')
# GSL
group.add_argument('--gsl-dir',
action='store',
default=None,
help="""The root directory for gsl.
'include/gsl/gsl_sf.h' and 'lib/libgsl.so' should be in this directory.
If this is left blank cmake will attempt to find one on your system.""",
metavar='PATH')
# HDF5
group.add_argument('--hdf5-dir',
action='store',
default=None,
help="""The root directory for hdf5.
'include/hdf5.h' and 'lib/libhdf5.so' (or similar) should be in this directory.
If this is left blank cmake will attempt to find one on your system.""",
metavar='PATH')
group = parser.add_argument_group('Pass extra flags to the compiler')
group.add_argument('--extra-cc-flags',
action='store',
default=None,
help='extra C flags. use equals, quotes, and spaces for correct parsing (e.g., --extra-cc-flags="-no-prec-div") [default: %(default)s]',
metavar='STRING')
group.add_argument('--extra-cxx-flags',
action='store',
default=None,
help='extra C++ flags [default: %(default)s]',
metavar='STRING')
group.add_argument('--extra-fc-flags',
action='store',
default=None,
help='extra Fortran flags [default: %(default)s]',
metavar='STRING')
group = parser.add_argument_group('Bypass compiler flags')
group.add_argument('--custom-cc-flags',
action='store',
default=None,
help='C flags. use equals, quotes, and spaces for correct parsing (e.g., --custom-cc-flags="-dynamic -fPIC") [default: %(default)s]',
metavar='STRING')
group.add_argument('--custom-cxx-flags',
action='store',
default=None,
help='C++ flags [default: %(default)s]',
metavar='STRING')
group.add_argument('--custom-fc-flags',
action='store',
default=None,
help='Fortran flags [default: %(default)s]',
metavar='STRING')
return parser.parse_args()
def check_cmake_exists(cmake_command):
p = subprocess.Popen('%s --version' % cmake_command,
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
if not ('cmake version' in str(p.communicate()[0])):
print(' This code is built using CMake')
print('')
print(' CMake is not found')
print(' get CMake at http://www.cmake.org/')
print(' on many clusters CMake is installed')
print(' but you have to load it first:')
print(' >>> module load cmake')
sys.exit()
def translate_cmake(cmakevar, s):
cmakeformat = ' -D{0}={{0}}'.format(cmakevar)
if s is None:
return ''
elif s == 'on':
return cmakeformat.format('ON')
elif s == 'off':
return cmakeformat.format('OFF')
elif s:
return cmakeformat.format('ON')
else:
return cmakeformat.format('OFF')
def gen_cmake_command(args):
# create cmake command from flags
command = ''
if args.fc:
command += ' -DCMAKE_Fortran_COMPILER=%s' % args.fc
if args.cc:
command += ' -DCMAKE_C_COMPILER=%s' % args.cc
if args.cxx:
command += ' -DCMAKE_CXX_COMPILER=%s' % args.cxx
command = ' %s ' % args.cmake + command
# placing this early in command construction so that more specific commands can override it
if args.metapackage_dir:
command += ' -DBOOST_INCLUDEDIR={0}'.format(args.metapackage_dir + '/include')
command += ' -DBOOST_LIBRARYDIR={0}'.format(args.metapackage_dir + '/lib')
command += ' -DPYTHON_INTERPRETER={0}'.format(args.metapackage_dir + '/bin/python')
command += ' -DCHEMPS2_ROOT={0}'.format(args.metapackage_dir)
command += ' -DHDF5_ROOT={0}'.format(args.metapackage_dir)
command += ' -DZLIB_ROOT={0}'.format(args.metapackage_dir)
command += ' -DPCMSOLVER_ROOT={0}'.format(args.metapackage_dir)
command += ' -DAMBIT_ROOT={0}'.format(args.metapackage_dir)
command += translate_cmake('ENABLE_MPI', args.mpi)
command += translate_cmake('ENABLE_SGI_MPT', args.sgi_mpt)
command += translate_cmake('ENABLE_OMP', args.omp)
command += translate_cmake('ENABLE_VECTORIZATION', args.vectorization)
command += translate_cmake('ENABLE_CSR', args.csr)
command += translate_cmake('ENABLE_SCALAPACK', args.scalapack)
command += translate_cmake('ENABLE_SCALASCA', args.scalasca)
command += translate_cmake('ENABLE_UNIT_TESTS', args.unit_tests)
command += translate_cmake('ENABLE_STATIC_LINKING', args.static)
command += translate_cmake('ENABLE_PLUGINS', args.plugins)
command += translate_cmake('ENABLE_LIBERD', args.erd)
command += translate_cmake('ENABLE_GDMA', args.gdma)
command += translate_cmake('ENABLE_JKFACTORY', args.jkfactory)
command += translate_cmake('ENABLE_GPU_DFCC', args.gpu_dfcc)
command += translate_cmake('ENABLE_DUMMY_PLUGIN', args.dummy_plugin)
command += translate_cmake('ENABLE_PCMSOLVER', args.pcmsolver)
command += translate_cmake('ENABLE_CHEMPS2', args.chemps2)
command += translate_cmake('ENABLE_AMBIT', args.ambit)
command += translate_cmake('ENABLE_CXX11_SUPPORT', args.cxx11)
command += ' -DLIBINT_OPT_AM={0}'.format(args.max_am_eri)
command += ' -DEXECUTABLE_SUFFIX={0}'.format(args.suffix)
if args.blas == 'builtin':
command += ' -DENABLE_BUILTIN_BLAS=ON'
command += ' -DENABLE_AUTO_BLAS=OFF'
elif args.blas == 'auto':
if (args.mkl != 'none') and not args.cray:
command += ' -DENABLE_AUTO_BLAS=ON'
elif args.blas == 'none':
command += ' -DENABLE_AUTO_BLAS=OFF'
else:
if not os.path.isfile(args.blas):
print('--blas=%s does not exist' % args.blas)
sys.exit(1)
command += ' -DEXPLICIT_BLAS_LIB=%s' % args.blas
command += ' -DENABLE_AUTO_BLAS=OFF'
if args.lapack == 'builtin':
command += ' -DENABLE_BUILTIN_LAPACK=ON'
command += ' -DENABLE_AUTO_LAPACK=OFF'
elif args.lapack == 'auto':
if (args.mkl != 'none') and not args.cray:
command += ' -DENABLE_AUTO_LAPACK=ON'
elif args.lapack == 'none':
command += ' -DENABLE_AUTO_LAPACK=OFF'
else:
if not os.path.isfile(args.lapack):
print('--lapack=%s does not exist' % args.lapack)
sys.exit(1)
command += ' -DEXPLICIT_LAPACK_LIB=%s' % args.lapack
command += ' -DENABLE_AUTO_LAPACK=OFF'
if args.accelerate:
command += ' -DENABLE_ACCELERATE=ON'
command += ' -DENABLE_AUTO_BLAS=OFF'
command += ' -DENABLE_AUTO_LAPACK=OFF'
if args.cray:
command += ' -DENABLE_CRAY_WRAPPERS=ON'
command += ' -DENABLE_AUTO_BLAS=OFF'
command += ' -DENABLE_AUTO_LAPACK=OFF'
if args.mkl != 'none':
if args.mkl == None:
print('you have to choose between --mkl=[{sequential,parallel,cluster}]')
sys.exit(1)
command += ' -DMKL_FLAG="-mkl=%s"' % args.mkl
command += ' -DMKL_FLAG_SET=ON'
command += ' -DENABLE_AUTO_BLAS=OFF'
command += ' -DENABLE_AUTO_LAPACK=OFF'
if args.extra_math_flags:
# remove leading and trailing whitespace
# otherwise CMake complains
command += ' -DEXPLICIT_LIBS="%s"' % args.extra_math_flags.strip()
if args.boost_incdir:
command += ' -DBOOST_INCLUDEDIR={0}'.format(args.boost_incdir)
if args.boost_libdir:
command += ' -DBOOST_LIBRARYDIR={0}'.format(args.boost_libdir)
if args.python:
command += ' -DPYTHON_INTERPRETER={0}'.format(args.python)
if args.zlib_dir:
command += ' -DZLIB_ROOT={0}'.format(args.zlib_dir)
if args.gsl_dir:
command += ' -DGSL_ROOT_DIR={0}'.format(args.gsl_dir)
if args.hdf5_dir:
command += ' -DHDF5_ROOT={0}'.format(args.hdf5_dir)
if args.pcmsolver_dir:
command += ' -DPCMSOLVER_ROOT={0}'.format(args.pcmsolver_dir)
if args.chemps2_dir:
command += ' -DCHEMPS2_ROOT={0}'.format(args.chemps2_dir)
if args.ambit_dir:
command += ' -DAMBIT_ROOT={0}'.format(args.ambit_dir)
if args.extra_cc_flags:
command += ' -DEXTRA_C_FLAGS="%s"' % args.extra_cc_flags
if args.extra_cxx_flags:
command += ' -DEXTRA_CXX_FLAGS="%s"' % args.extra_cxx_flags
if args.extra_fc_flags:
command += ' -DEXTRA_Fortran_FLAGS="%s"' % args.extra_fc_flags
if args.custom_cc_flags:
command += ' -DCUSTOM_C_FLAGS="%s"' % args.custom_cc_flags
if args.custom_cxx_flags:
command += ' -DCUSTOM_CXX_FLAGS="%s"' % args.custom_cxx_flags
if args.custom_fc_flags:
command += ' -DCUSTOM_Fortran_FLAGS="%s"' % args.custom_fc_flags
if args.check:
command += ' -DENABLE_BOUNDS_CHECK=ON'
if args.memcheck:
command += ' -DENABLE_MEMCHECK=ON'
if args.asan:
command += ' -DENABLE_ASAN=ON'
if args.msan:
command += ' -DENABLE_MSAN=ON'
if args.tsan:
command += ' -DENABLE_TSAN=ON'
if args.ubsan:
command += ' -DENABLE_UBSAN=ON'
if args.coverage:
command += ' -DENABLE_CODE_COVERAGE=ON'
if args.prefix:
command += ' -DCMAKE_INSTALL_PREFIX=' + args.prefix
if (args.asan or args.msan or args.tsan or args.ubsan):
command += ' -DCMAKE_BUILD_TYPE=debug'
else:
command += ' -DCMAKE_BUILD_TYPE=%s' % args.type
if args.define:
for definition in args.define:
if ' ' in definition:
# allow correct quoting of string values
# e.g., -D MORELIBS="-L/path/to/lib /path/to/lib2"
_tmp = definition.split('=', 1)
command += ' -D%s="%s"' % (_tmp[0], _tmp[1])
else:
command += ' -D%s' % definition
if args.generator:
command += ' -G "%s"' % args.generator
command += ' %s' % root_directory
print('%s\n' % command)
if args.show:
sys.exit()
return command
def print_build_help(build_path):
print(' configure step is done')
print(' now you need to compile the sources:')
if (build_path == default_path):
print(' >>> cd objdir')
else:
print(' >>> cd ' + build_path)
print(' >>> make')
def save_setup_command(argv, command, build_path):
file_name = os.path.join(build_path, 'setup_command')
f = open(file_name, 'w')
f.write('# setup command was executed '+datetime.datetime.now().strftime("%d-%B-%Y %H:%M:%S"+"\n"))
f.write(" ".join(argv[:])+"\n")
f.write("\n# cmake command generated by this setup command was: \n")
f.write("# "+command+"\n")
f.close()
def setup_build_path(build_path):
if os.path.isdir(build_path):
fname = os.path.join(build_path, 'CMakeCache.txt')
if os.path.exists(fname):
print('aborting setup - build directory %s which contains CMakeCache.txt exists already' % build_path)
print('remove the build directory and then rerun setup')
sys.exit(1)
else:
os.makedirs(build_path, 0o755)
def run_cmake(command, build_path):
topdir = os.getcwd()
os.chdir(build_path)
p = subprocess.Popen(command,
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
s = p.communicate()[0].decode('utf-8')
# print cmake output to screen
print(s)
# write cmake output to file
f = open('setup_cmake_output', 'w')
f.write(s)
f.close()
# change directory and return
os.chdir(topdir)
return s
def main(argv):
args = parse_input()
check_cmake_exists(args.cmake)
build_path = args.builddir
if not args.show:
setup_build_path(build_path)
if not configure_host(args):
configure_default_compilers(args)
command = gen_cmake_command(args)
status = run_cmake(command, build_path)
if 'Configuring incomplete' in str(status):
# configuration was not successful
if (build_path == os.path.join(root_directory, 'objdir')):
# remove build_path iff not set by the user
# otherwise removal can be dangerous
shutil.rmtree(default_path)
else:
# configuration was successful
save_setup_command(argv, command, build_path)
print_build_help(build_path)
# host/system specific configurations
def configure_host(args):
if args.host:
host = args.host
else:
if sys.platform != "win32":
u = os.uname()
else:
u = "Windows"
host = " ".join(u)
msg = None
# Generic systems
if re.search('ubuntu', host, re.I):
msg = "Configuring system: Ubuntu"
configure_ubuntu(args)
if re.search('fedora', host, re.I):
msg = "Configuring system: Fedora"
configure_fedora(args)
if re.search('osx', host, re.I):
msg = "Configuring system: MacOSX"
configure_osx(args)
if msg is None:
return False
if not args.show:
print(msg)
return True
def configure_default_compilers(args):
if args.mpi and not args.cc and not args.cxx:
# only --mpi flag but no --fc, --cc, --cxx
# set --cc, --cxx to mpicc, mpicxx
args.cc = 'mpicc'
args.cxx = 'mpicxx'
if not args.mpi:
# if compiler starts with 'mp' turn on mpi
# it is possible to call compilers with long paths
if args.cc and os.path.basename(args.cc).lower().startswith('mp') or \
args.cxx and os.path.basename(args.cxx).lower().startswith('mp') or \
args.fc and os.path.basename(args.fc).lower().startswith('mp'):
args.mpi = 'on'
# if compiler starts with 'openmpi' turn on mpi
# it is possible to call compilers with long paths
if args.cc and os.path.basename(args.cc).lower().startswith('openmpi') or \
args.cxx and os.path.basename(args.cxx).lower().startswith('openmpi') or \
args.fc and os.path.basename(args.fc).lower().startswith('openmpi'):
args.mpi = 'on'
if not args.cc and 'CC' in os.environ:
args.cc = os.environ['CC']
if not args.cxx and 'CXX' in os.environ:
args.cxx = os.environ['CXX']
if not args.fc and 'FC' in os.environ:
args.fc = os.environ['FC']
configure_ubuntu = configure_default_compilers
configure_fedora = configure_default_compilers
configure_osx = configure_default_compilers
if __name__ == '__main__':
main(sys.argv)