forked from MRtrix3/mrtrix3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·1138 lines (842 loc) · 30.6 KB
/
configure
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
#!/usr/bin/env python
import subprocess, sys, os, platform, tempfile, shutil, shlex, re, copy
debug = False
profile = False
nogui = False
noshared = False
static = False
verbose = False
R_module = False
profile_name = None
sh_basis_def = None
for arg in sys.argv[1:]:
if '-debug'.startswith (arg): debug = True
elif '-profile'.startswith (arg): profile = True
elif '-nogui'.startswith (arg): nogui = True
elif '-noortho'.startswith (arg): sh_basis_def = '-DUSE_NON_ORTHONORMAL_SH_BASIS'
elif '-noshared'.startswith (arg): noshared = True
elif '-static'.startswith (arg):
static = True
noshared = True
elif '-verbose'.startswith (arg): verbose = True
elif '-R'.startswith (arg):
R_module = True
#noshared = True
nogui = True
elif arg[0] != '-':
if profile_name != None:
print ('configure: too many names supplied')
sys.exit (1)
profile_name = arg
else:
print ("""
usage: [ENV] ./configure [name] [-debug] [-profile] [-nogui] [-noshared]
In most cases, a simple invocation should work:
$ ./configure
If a name is provided, the configuration will be written to a different file,
which can then be used by the build script. For example:
$ ./configure testing -debug
will generate the file 'config.testing', which can be used with the build
script as follows:
$ ./build testing
Note that all intermediate files will be named according to the name of the
configuration to avoid conflict with any other configuration.
OPTIONS:
-debug enable debugging symbols.
-profile enable profiling.
-nogui disable GUI components.
-noshared disable shared library generation.
-R used to generate an R module (implies -noshared)
-static produce statically-linked executables.
-verbose enable more informative output.
ENVIRONMENT VARIABLES:
For non-standard setups, you may need to supply additional
information using environment variables. For example, to set
the compiler, use:
$ CXX=/usr/local/bin/g++-4.1 ./configure
The following environment variables can be set:
CXX The compiler command to use. The default is "g++" ("clang" on MacOSX)
CXX_ARGS The arguments expected by the compiler. The default is:
"-c CFLAGS SRC -o OBJECT"
LD The linker command to use. The default is:
"g++" ("clang++" on MacOSX)
LD_ARGS The arguments expected by the linker. The default is:
"LDFLAGS OBJECTS -o EXECUTABLE"
LDLIB_ARGS The arguments expected by the linker for generating a shared library.
The default is:
"-shared LDLIB_FLAGS OBJECTS -o LIB"
ARCH the specific CPU architecture to compile for. This variable
will be passed to the compiler using -march=$ARCH.
The default is 'native'.
CFLAGS Any additional flags to the compiler.
LDFLAGS Any additional flags to the linker.
LDLIB_FLAGS Any additional flags to the linker to generate a shared library.
GSL_CFLAGS Any flags required to compile with the GSL.
This may include in particular the path to the
include files, if not in a standard location
For example:
$ GSL_CFLAGS="-I/usr/local/include" ./configure
GSL_LDFLAGS Any flags required to link with the GSL.
This may include in particular the path to the
libraries, if not in a standard location
For example:
$ GSL_LDFLAGS="-L/usr/local/lib -lgsl -lgslcblas" ./configure
ZLIB_CFLAGS Any flags required to compile with the zlib compression library.
ZLIB_LDFLAGS Any flags required to link with the zlib compression library.
CBLAS_LDFLAGS Any flags required to link with an alternate cblas library.
QMAKE The command to run to invoke qmake.
MOC The command to invoke Qt's meta-object compile (default: moc)
RCC The command to invoke Qt's resource compiler (default: rcc)
PATH Set the path to use during the configure process.
This may be useful to set the path to Qt's qmake.
For example:
$ PATH=/usr/local/bin:$PATH ./configure
Note that this path will NOT be used during the build
process itself.
""")
sys.exit (0)
if not profile_name:
profile_name = 'default'
global logfile, config_report
logfile = open (os.path.join (os.path.dirname(sys.argv[0]), 'configure.log'), 'wb')
config_report = ''
def log (message):
global logfile
logfile.write (message.encode (errors='ignore'))
if (verbose):
sys.stdout.write (message)
sys.stdout.flush()
def report (message):
global config_report, logfile
config_report += message
sys.stdout.write (message)
sys.stdout.flush()
logfile.write (('\nREPORT: ' + message.rstrip() + '\n').encode (errors='ignore'))
def error (message):
global logfile
logfile.write (('\nERROR: ' + message.rstrip() + '\n\n').encode (errors='ignore'))
sys.stderr.write ('\nERROR: ' + message.rstrip() + '\n\n')
sys.exit (1)
report ("""
MRtrix build type requested: """)
if profile: report ('profiling')
elif debug: report ('debug')
else: report ('release')
if nogui: report (' [command-line only]')
report ('\n\n')
global cpp, cpp_cmd, ld, ld_args, ld_cmd
cxx = [ 'g++' ]
cxx_args = '-c CFLAGS SRC -o OBJECT'.split()
cpp_flags = [ '-std=c++11' ]
ld_args = 'OBJECTS LDFLAGS -o EXECUTABLE'.split()
ld_flags = [ ]
if static:
ld_flags += [ '-static', '-Wl,-u,pthread_cancel,-u,pthread_cond_broadcast,-u,pthread_cond_destroy,-u,pthread_cond_signal,-u,pthread_cond_wait,-u,pthread_create,-u,pthread_detach,-u,pthread_cond_signal,-u,pthread_equal,-u,pthread_join,-u,pthread_mutex_lock,-u,pthread_mutex_unlock,-u,pthread_once,-u,pthread_setcancelstate' ]
ld_lib_args = 'OBJECTS LDLIB_FLAGS -o LIB'.split()
ld_lib_flags = [ ]
zlib_cflags = []
zlib_ldflags = [ '-lz' ]
gsl_cflags = []
gsl_ldflags = [ '-lgsl', '-lgslcblas' ]
class TempFile:
def __init__ (self, suffix):
self.fid = None
self.name = None
[ fid, self.name ] = tempfile.mkstemp (suffix)
self.fid = os.fdopen (fid, 'w')
def __enter__ (self):
return self
def __exit__(self, type, value, traceback):
try:
os.unlink (self.name)
except OSError as error:
log ('error deleting temporary file "' + self.name + '": ' + error.strerror)
except:
raise
class DeleteAfter:
def __init__ (self, name):
self.name = name
def __enter__ (self):
return self
def __exit__(self, exception_type, value, traceback):
try:
os.unlink (self.name)
except OSError as error:
log ('error deleting temporary file "' + self.name + '": ' + error.strerror)
except:
raise
class TempDir:
def __init__ (self):
self.name = tempfile.mkdtemp ();
def __enter__ (self):
return self
def __exit__(self, type, value, traceback):
try:
for entry in os.listdir (self.name):
fname = os.path.join (self.name, entry)
if os.path.isdir (fname):
os.rmdir (fname)
else:
os.unlink (fname)
os.rmdir (self.name)
except OSError as error:
log ('error deleting temporary folder "' + self.name + '": ' + error.strerror)
except:
raise
class QMakeError (Exception): pass
class QMOCError (Exception): pass
class CompileError (Exception): pass
class LinkError (Exception): pass
class RuntimeError (Exception): pass
def commit (name, variable):
cache.write (name + ' = ')
if type (variable) == type([]):
cache.write ('[')
if len(variable): cache.write(' \'' + '\', \''.join (variable) + '\' ')
cache.write (']\n')
else: cache.write ('\'' + variable + '\'\n')
def fillin (template, keyvalue):
cmd = []
for item in template:
if item in keyvalue:
if type(keyvalue[item]) == type ([]): cmd += keyvalue[item]
else: cmd += [ keyvalue[item] ]
else: cmd += [ item ]
return cmd
def execute (cmd, exception, raise_on_non_zero_exit_code = True, cwd = None):
log ('EXEC <<\nCMD: ' + ' '.join(cmd) + '\n')
try:
process = subprocess.Popen (cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd)
( stdout, stderr ) = process.communicate()
log ('EXIT: ' + str(process.returncode) + '\n')
stdout = stdout.decode(errors='ignore').rstrip()
if len (stdout): log ('STDOUT:\n' + stdout + '\n')
stderr = stderr.decode(errors='ignore').rstrip()
if len (stderr): log ('STDERR:\n' + stderr + '\n')
log ('>>\n\n')
except OSError as error:
log ('error invoking command "' + cmd[0] + '": ' + error.strerror + '\n>>\n\n')
raise exception
except:
print ('Unexpected error:', str(sys.exc_info()))
raise
else:
if raise_on_non_zero_exit_code and process.returncode != 0:
raise exception (stderr)
return (process.returncode, stdout, stderr)
def compile (source, compiler_flags = [], linker_flags = []):
global cpp, ld
with TempFile ('.cpp') as F:
log ('\nCOMPILE ' + F.name + ':\n---\n' + source + '\n---\n')
F.fid.write (source)
F.fid.flush()
F.fid.close()
with DeleteAfter (F.name[:-4] + '.o') as obj:
cmd = fillin (cpp, {
'CFLAGS': compiler_flags,
'SRC': F.name,
'OBJECT': obj.name })
execute (cmd, CompileError)
with DeleteAfter ('a.out') as out:
cmd = fillin (ld, {
'LDFLAGS': linker_flags,
'OBJECTS': obj.name,
'EXECUTABLE': out.name })
execute (cmd, LinkError)
ret = execute ([ './'+out.name ], RuntimeError)
return ret[1]
def compare_version (needed, observed):
needed = [ float(n) for n in needed.split()[0].split('.') ]
observed = [ float(n) for n in observed.split()[0].split('.') ]
for n in zip (needed, observed):
if n[0] > n[1]:
return False
return True
# OS-dependent variables:
obj_suffix = '.o'
exe_suffix = ''
lib_prefix = 'lib'
system = platform.system().lower()
if system.startswith('mingw') or system.startswith('msys'):
system = 'windows'
report ('Detecting OS: ' + system + '\n')
if system == 'linux':
cpp_flags += [ '-pthread', '-fPIC' ]
lib_suffix = '.so'
ld_flags += [ '-pthread' ]
ld_lib_flags += [ '-pthread', '-shared' ]
runpath = '-Wl,-rpath,$ORIGIN/'
elif system == 'windows':
cpp_flags += [ '-pthread', '-DMRTRIX_WINDOWS', '-mms-bitfields' ]
exe_suffix = '.exe'
lib_prefix = ''
lib_suffix = '.dll'
ld_flags += [ '-pthread', '-Wl,--allow-multiple-definition' ]
ld_lib_flags += [ '-pthread', '-shared' ]
runpath = ''
elif system == 'darwin':
cxx = [ 'clang++' ]
cpp_flags += [ '-DMRTRIX_MACOSX', '-fPIC' ]
ld_lib_flags += [ '-dynamiclib', '-install_name', '@rpath/LIBNAME' ]
runpath = '-Wl,-rpath,@loader_path/'
lib_suffix = '.dylib'
if 'ARCH' in os.environ.keys():
march = os.environ['ARCH']
report ('Machine architecture set by ARCH environment variable to: ' + march + '\n')
cpp_flags += [ '-march='+march ]
else:
if system != 'darwin':
cpp_flags += [ '-march=native' ]
# set CPP compiler:
if 'CXX' in os.environ.keys(): cxx = shlex.split (os.environ['CXX'])
if 'CXX_ARGS' in os.environ.keys(): cxx_args = shlex.split (os.environ['CXX_ARGS'])
ld = copy.copy(cxx)
if 'LD' in os.environ.keys(): ld = shlex.split (os.environ['LD'])
if 'LD_ARGS' in os.environ.keys(): ld_args = shlex.split (os.environ['LD_ARGS'])
if 'LDLIB_ARGS' in os.environ.keys(): ld_lib_args = shlex.split (os.environ['LDLIB_ARGS'])
cpp = cxx + cxx_args
ld_lib = ld + ld_lib_args
ld += ld_args
# CPP flags:
if 'CFLAGS' in os.environ.keys(): cpp_flags += shlex.split (os.environ['CFLAGS'])
if 'LDFLAGS' in os.environ.keys(): ld_flags + shlex.split (os.environ['LDFLAGS'])
ld_lib_flags += ld_flags
if 'LDLIB_FLAGS' in os.environ.keys(): ld_lib_flags + shlex.split (os.environ['LDLIB_FLAGS'])
report ('Checking for C++11 compliant compiler [' + cpp[0] + ']: ')
try:
compiler_version = execute ([ cpp[0], '-dumpversion' ], CompileError)[1]
if len(compiler_version) == 0: report ('(no version information)')
else: report (compiler_version)
except:
error ('''compiler not found!
Use CXX environment variable to set path to compiler, as follows:
CXX=/usr/bin/g++-4.2 ./configure''')
try:
compile ('''
struct Base {
Base (int);
};
struct Derived : Base {
using Base::Base;
};
int main() {
Derived D (int); // check for contructor inheritance
return (0);
}
''', cpp_flags, ld_flags)
report (' - tested ok\n')
except CompileError:
error ('''compiler test failed!
Use CXX environment variable to set path to compiler, as follows:
CXX=/usr/bin/g++-4.2 ./configure
You can also use the CXX_ARGS to set the arguments expected by the
compiler, in case this differs from gcc, as follows:
CXX_ARGS="-c CFLAGS SRC -o OBJECT" ./configure''')
except (LinkError, RuntimeError):
error ('''linking error!
Use LD environment variable to set path to compiler, as follows:
LD=/usr/bin/g++-4.2 ./configure''')
except:
raise
report ('Detecting pointer size: ')
try:
pointer_size = int (compile ('''
#include <iostream>
int main() {
std::cout << sizeof(void*);
return (0);
}
''', cpp_flags, ld_flags))
report (str(8*pointer_size) + ' bit\n')
if pointer_size == 8: cpp_flags += [ '-DMRTRIX_WORD64' ]
elif pointer_size != 4:
error ('unexpected pointer size!')
except:
error ('unable to determine pointer size!')
report ('Detecting byte order: ')
if sys.byteorder == 'big':
report ('big-endian\n')
cpp_flags += [ '-DMRTRIX_BYTE_ORDER_IS_BIG_ENDIAN' ]
else:
report ('little-endian\n')
report ('Checking for variable-length array support: ')
try:
compile ('''
int main(int argc, char* argv[]) {
int x[argc];
return 0;
}
''', cpp_flags, ld_flags)
report ('yes\n')
except:
report ('no\n')
cpp_flags += [ '-DMRTRIX_NO_VLA' ]
report ('Checking for non-POD variable-length array support: ')
try:
compile ('''
#include <string>
class X {
int x;
double y;
std::string s;
};
int main(int argc, char* argv[]) {
X x[argc];
return 0;
}
''', cpp_flags, ld_flags)
report ('yes\n')
except:
report ('no\n')
cpp_flags += [ '-DMRTRIX_NO_NON_POD_VLA' ]
# zlib:
report ('Checking for zlib compression library: ')
if 'ZLIB_CFLAGS' in os.environ.keys(): zlib_cflags = shlex.split (os.environ['ZLIB_CFLAGS'])
if 'ZLIB_LDFLAGS' in os.environ.keys(): zlib_ldflags = shlex.split (os.environ['ZLIB_LDFLAGS'])
try:
zlib_version = compile ('''
#include <iostream>
#include <zlib.h>
int main() {
std::cout << zlibVersion();
return (0);
}
''', cpp_flags + zlib_cflags, ld_flags + zlib_ldflags)
report (zlib_version + '\n')
except CompileError:
error ('''compiler error!
Use the ZLIB_CFLAGS environment variable to set the path to
the zlib include files and to set any required flags
For example:
ZLIB_CFLAGS="-I/usr/local/include" ./configure''')
except LinkError:
error ('''linker error!
Use the ZLIB_LDFLAGS environment variable to set the path to
the zlib libraries and to set the library to use
For example:
ZLIB_LDFLAGS="-L/usr/local/lib -lz" ./configure''')
except RuntimeError:
error ('''runtime error!
There is something wrong with your zlib implementation!''')
except:
error ('zlib implementation not found!')
cpp_flags += zlib_cflags
ld_flags += zlib_ldflags
ld_lib_flags += zlib_ldflags
# GSL flags:
report ('Checking for GNU Scientific Library: ')
if 'GSL_CFLAGS' in os.environ.keys():
gsl_cflags = shlex.split (os.environ['GSL_CFLAGS'])
else:
try:
gsl_cflags = shlex.split (execute ([ 'gsl-config', '--cflags' ], RuntimeError)[1])
gsl_cflags = [ c for c in gsl_cflags if c is not 0 ]
except:
log ('gsl-config not in PATH - assuming defaults for GSL_CFLAGS\n\n')
if 'GSL_LDFLAGS' in os.environ.keys():
gsl_ldflags = shlex.split (os.environ['GSL_LDFLAGS'])
else:
try:
gsl_ldflags = shlex.split (execute ([ 'gsl-config', '--libs' ], RuntimeError)[1])
gsl_ldflags = [ c for c in gsl_ldflags if c is not 0 ]
except:
log ('gsl-config not in PATH - assuming defaults for GSL_LDFLAGS\n\n')
try:
gsl_version = compile ('''
#include <iostream>
#include <gsl/gsl_version.h>
#include <gsl/gsl_matrix.h>
int main() {
std::cout << gsl_version;
gsl_matrix* M = gsl_matrix_alloc (3,3);
return (M->size1 != 3);
}
''', cpp_flags + gsl_cflags, ld_flags + gsl_ldflags)
report (gsl_version + '\n')
except CompileError:
error ('''compiler error!
Use the GSL_CFLAGS environment variable to set the path to the GSL include files'
For example:'
GSL_CFLAGS=-I/usr/local/include ./configure''')
except LinkError:
error ('''linker error!'
Use the GSL_LDFLAGS environment variable to set the path to the GSL libraries'
and include any required libraries'
For example:'
GSL_LDFLAGS="-L/usr/local/lib -lgsl -lgslcblas" ./configure''')
ld_lib_flags += gsl_ldflags
report ('Checking whether GSL compiles with -DHAVE_INLINE: ')
try:
gsl_version = compile ('''
#include <gsl/gsl_matrix.h>
int main() {
gsl_matrix* M = gsl_matrix_alloc (3,3);
gsl_matrix_set(M,0,0,3.14);
return (gsl_matrix_get(M,0,0) != 3.14);
}''', cpp_flags + gsl_cflags + [ '-DHAVE_INLINE' ], ld_flags + gsl_ldflags)
gsl_cflags += [ '-DHAVE_INLINE' ]
report ('yes\n')
except:
report ('no\n')
# check for alternate cblas libraries:
if 'CBLAS_LDFLAGS' in os.environ.keys():
cblas_ldflags = shlex.split (os.environ['CBLAS_LDFLAGS'])
flags = gsl_ldflags[:]
flags.remove ('-lgslcblas')
flags += cblas_ldflags;
report ('Checking whether GSL compiles with alternate C BLAS libraries ("' + ' '.join(cblas_ldflags) + '"): ')
try:
compile ('''
#include <iostream>
#include <gsl/gsl_version.h>
#include <gsl/gsl_matrix.h>
int main() {
std::cout << gsl_version;
gsl_matrix* M = gsl_matrix_alloc (3,3);
return (M->size1 != 3);
}
''', cpp_flags + gsl_cflags, ld_flags + flags)
report ('yes\n')
gsl_ldflags = flags
except:
error ('''Error compiling and/or linking with alternative C BLAS libraries provided!
Check whether the information provided by the CBLAS_LDFLAGS environment
variable is correct.''')
# shared library generation:
if not noshared:
report ('Checking shared library generation: ')
with TempFile ('.cpp') as F:
F.fid.write ('int bogus() { return (1); }')
F.fid.flush()
F.fid.close()
with DeleteAfter (F.name[:-4] + '.o') as obj:
cmd = fillin (cpp, {
'CFLAGS': cpp_flags,
'SRC': F.name,
'OBJECT': obj.name })
try: execute (cmd, CompileError)
except CompileError:
error ('''compiler not found!
an unexpected error occurred''')
except:
raise
with DeleteAfter (lib_prefix + 'test' + lib_suffix) as lib:
cmd = fillin (ld_lib, {
'LDLIB_FLAGS': ld_lib_flags,
'OBJECTS': obj.name,
'LIB': lib.name })
try: execute (cmd, LinkError)
except LinkError:
error ('''linker not found!
Use the LDLIB_ARGS environment variable to set the command-line
for shared library generation''')
except:
raise
report ('yes\n')
#the following regex will be reused so keep it outside of the get_qt_version func
version_regex = re.compile(r'\d+\.\d+(\.\d+)+') #: :type version_regex: re.compile
def get_qt_version(cmd_list, raise_on_non_zero_exit_code):
out = execute (cmd_list, raise_on_non_zero_exit_code, False)
stdouterr = ' '.join(out[1:]).replace(r'\n',' ').replace(r'\r','')
version_found = version_regex.search(stdouterr)
if version_found: return version_found.group()
else: raise raise_on_non_zero_exit_code('Version not Found')
moc = ''
rcc = ''
qt_cflags = []
qt_ldflags = []
if not nogui:
report ('Checking for Qt moc: ')
moc = 'moc'
if 'MOC' in os.environ.keys():
moc = os.environ['MOC']
try:
moc_version = get_qt_version([ moc, '-v' ], OSError)
report (moc + ' (version ' + moc_version + ')\n')
if int (moc_version.split('.')[0]) < 4:
error (''' Qt moc version is too old!
Use the MOC environment variable to specify the Qt meta-object compiler,
or set PATH to ensure the correct version is listed first''')
except OSError:
error (''' Qt moc not found!
Use the MOC environment variable to specify the Qt meta-object compiler,
or set PATH to include its location''')
except:
raise
report ('Checking for Qt qmake: ')
qmake = 'qmake'
if 'QMAKE' in os.environ.keys():
qmake = os.environ['QMAKE']
try:
qmake_version = get_qt_version([ qmake, '-v' ], OSError)
report (qmake + ' (version ' + qmake_version + ')\n')
if int (qmake_version.split('.')[0]) < 4:
error (''' Qt qmake not found!
Use the QMAKE environment variable to specify the Qt qmake executable,
or set PATH to ensure the correct version is listed first''')
except OSError:
error (''' Qt qmake not found!
Use the QMAKE environment variable to specify the Qt qmake executable,
or set PATH to include its location''')
except:
raise
report ('Checking for Qt rcc: ')
rcc = 'rcc'
if 'RCC' in os.environ.keys():
rcc = os.environ['RCC']
try:
rcc_version = get_qt_version([ rcc, '-v' ], OSError)
report (rcc + ' (version ' + rcc_version + ')\n')
if int (rcc_version.split('.')[0]) < 4:
error (''' Qt rcc not found!
Use the RCC environment variable to specify the Qt rcc executable,
or set PATH to ensure the correct version is listed first''')
except OSError:
error (''' Qt rcc not found!
Use the RCC environment variable to specify the Qt rcc executable,
or set PATH to include its location''')
except:
raise
report ('Checking for Qt: ')
try:
with TempDir() as qt_dir:
file = '''#include <QObject>
class Foo: public QObject {
Q_OBJECT;
public:
Foo();
~Foo();
public slots:
void setValue(int value);
signals:
void valueChanged (int newValue);
private:
int value_;
};
'''
log ('\nsource file "qt.h":\n---\n' + file + '---\n')
f=open (os.path.join (qt_dir.name, 'qt.h'), 'w')
f.write (file)
f.close();
file = '''#include <iostream>
#include "qt.h"
Foo::Foo() : value_ (42) { connect (this, SIGNAL(valueChanged(int)), this, SLOT(setValue(int))); }
Foo::~Foo() { std::cout << qVersion() << "\\n"; }
void Foo::setValue (int value) { value_ = value; }
int main() { Foo f; }
'''
log ('\nsource file "qt.cpp":\n---\n' + file + '---\n')
f=open (os.path.join (qt_dir.name, 'qt.cpp'), 'w')
f.write (file)
f.close();
file = 'CONFIG += c++11'
if debug: file += ' debug'
file += '\nQT += core gui opengl svg\n'
file += 'HEADERS += qt.h\nSOURCES += qt.cpp\n'
log ('\nproject file "qt.pro":\n---\n' + file + '---\n')
f=open (os.path.join (qt_dir.name, 'qt.pro'), 'w')
f.write (file)
f.close();
qmake_cmd = [ qmake ]
try:
(retcode, stdout, stderr) = execute (qmake_cmd, QMakeError, raise_on_non_zero_exit_code = False, cwd=qt_dir.name)
if retcode != 0:
error ('''qmake returned with error:
''' + stderr)
except QMakeError as E:
error ('''error issuing qmake command!
Use the QMAKE environment variable to set the correct qmake command for use with Qt''')
except:
raise
qt_defines = []
qt_includes = []
qt_cflags = []
qt_libs = []
qt_ldflags = []
qt_makefile = 'Makefile'
if system == 'windows':
qt_makefile = 'Makefile.Release'
for line in open (os.path.join (qt_dir.name, qt_makefile)):
line = line.strip()
if line.startswith ('DEFINES'):
qt_defines = shlex.split (line[line.find('=')+1:].strip())
elif line.startswith ('CXXFLAGS'):
qt_cflags = shlex.split (line[line.find('=')+1:].strip())
elif line.startswith ('INCPATH'):
qt_includes = shlex.split (line[line.find('=')+1:].strip())
elif line.startswith ('LIBS'):
qt_libs = shlex.split (line[line.find('=')+1:].strip())
elif line.startswith ('LFLAGS'):
qt_ldflags = shlex.split (line[line.find('=')+1:].strip())
for index, entry in enumerate(qt_includes):
if entry[2:].startswith('..'):
qt_includes[index] = '-I' + os.path.abspath(qt_dir.name + '/' + entry[2:])
qt = qt_cflags + qt_defines + qt_includes
qt_cflags = []
for entry in qt:
if entry[0] != '$' and not entry == '-I.': qt_cflags += [ entry.replace('\"','').replace("'",'') ]
qt = qt_ldflags + qt_libs
qt_ldflags = []
for entry in qt:
if entry[0] != '$': qt_ldflags += [ entry.replace('\"','').replace("'",'') ]
cmd = [ moc, 'qt.h', '-o', 'qt_moc.cpp' ]
log ('\nexecuting "' + ' ' .join(cmd) + '"...\n')
try: process = subprocess.Popen (cmd, cwd=qt_dir.name, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except OSError: raise QMOCError
if process.wait() != 0: raise QMOCError
cmd = cxx + [ '-c' ] + cpp_flags + qt_cflags + [ 'qt.cpp', '-o', 'qt.o' ]
log ('\nexecuting "' + ' ' .join(cmd) + '"...\n')
try: process = subprocess.Popen (cmd, cwd=qt_dir.name, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except OSError: raise CompileError('oserror')
except: raise
retcode = process.wait()
if retcode != 0: raise CompileError('process not terminated properly (exit code = %s)'%str(retcode))
cmd = cxx + [ '-c' ] + cpp_flags + qt_cflags + [ 'qt_moc.cpp', '-o', 'qt_moc.o' ]
log ('\nexecuting "' + ' ' .join(cmd) + '"...\n')
try: process = subprocess.Popen (cmd , cwd=qt_dir.name, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except OSError: raise CompileError('oserror')
except: raise
if process.wait() != 0: raise CompileError('process not terminated properly')
cmd = cxx + ld_flags + [ 'qt_moc.o', 'qt.o', '-o', 'qt' ] + qt_ldflags
log ('\nexecuting "' + ' ' .join(cmd) + '"...\n')
try: process = subprocess.Popen (cmd , cwd=qt_dir.name, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except OSError: raise LinkError('oserror')
except: raise
if process.wait() != 0: raise LinkError('process not terminated properly')
cmd = os.path.join(qt_dir.name, 'qt')
log ('\nexecuting "' + cmd + '"...\n')
process = subprocess.Popen (cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if process.wait() != 0: raise LinkError('process not terminated properly')
report (process.stdout.read().decode(errors='ignore').strip() + '\n')
except QMakeError:
error ('''error invoking Qt qmake!
Use the QMAKE environment variable to set the correct qmake command for use with Qt''')
except QMOCError:
error ('''error invoking Qt moc!
use the MOC environment variable to specify the Qt moc command''')
except LinkError:
error ('''error linking Qt application!
Are all necessary (static or shared) Qt libraries installed?''')
except QMOCError:
error ('''error invoking Qt moc!
use the MOC environment variable to specify the Qt moc command''')
except CompileError as e:
error ('error compiling Qt application! ' + str(e))
except OSError as e:
error ('Unexpected error! Unable to configure Qt environment: ' + str(e))
except:
raise
if system == "darwin":
if '-Wall' in qt_cflags: qt_cflags.remove ('-Wall')
if '-W' in qt_cflags: qt_cflags.remove ('-W')
# output R module:
if R_module: