forked from roc-streaming/roc-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SConstruct
1180 lines (979 loc) · 37.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
import SCons
import os
import os.path
import platform
import re
import sys
# supported platform names
supported_platforms = [
'linux',
'unix',
'darwin',
'android',
]
# supported compiler names (without version)
supported_compilers = [
'clang',
'gcc',
'cc',
]
# supported sanitizers
supported_sanitizers = [
'undefined',
'address',
]
# supported macOS target architectures
supported_macos_archs = [
'all', # for universal binaries, same as manually listing all archs
'x86_64',
'arm64',
]
# default installation prefix
if platform.system() == 'Darwin':
default_prefix = '/usr/local'
else:
default_prefix = '/usr'
AddOption('--prefix',
dest='prefix',
action='store',
type='string',
default=default_prefix,
help="installation prefix, '{}' by default".format(default_prefix))
AddOption('--bindir',
dest='bindir',
action='store',
type='string',
default=os.path.join(GetOption('prefix'), 'bin'),
help=("path to the binary installation directory"
" (where to install Roc command-line tools),"
" '<prefix>/bin' by default"))
AddOption('--libdir',
dest='libdir',
action='store',
type='string',
help=("path to the library installation directory"
" (where to install Roc library),"
" auto-detected by default"))
AddOption('--incdir',
dest='incdir',
action='store',
type='string',
default=os.path.join(GetOption('prefix'), 'include'),
help=("path to the headers installation directory"
" (where to install Roc headers),"
" '<prefix>/include' by default"))
AddOption('--mandir',
dest='mandir',
action='store',
type='string',
default=os.path.join(GetOption('prefix'), 'share/man/man1'),
help=("path to the manuals installation directory"
" (where to install Roc manual pages),"
" '<prefix>/share/man/man1' by default"))
AddOption('--build',
dest='build',
action='store',
type='string',
help=("system name where Roc is being compiled,"
" e.g. 'x86_64-pc-linux-gnu',"
" auto-detected by default"))
AddOption('--host',
dest='host',
action='store',
type='string',
help=("system name where Roc will run,"
" e.g. 'arm-linux-gnueabihf',"
" auto-detected by default"))
AddOption('--platform',
dest='platform',
action='store',
choices=([''] + supported_platforms),
help=("platform name where Roc will run,"
" supported values: empty (detect from host), {}".format(
', '.join(["'{}'".format(s) for s in supported_platforms]))))
AddOption('--compiler',
dest='compiler',
action='store',
type='string',
help=("compiler name and optional version, e.g. 'gcc-4.9',"
" supported names: empty (detect what available), {}".format(
', '.join(["'{}'".format(s) for s in supported_compilers]))))
AddOption('--compiler-launcher',
dest='compiler_launcher',
action='store',
type='string',
help=("optional launching tool for c and c++ compilers,"
" e.g. 'ccache'"))
AddOption('--sanitizers',
dest='sanitizers',
action='store',
type='string',
help=("list of gcc/clang sanitizers,"
" supported names: empty (no sanitizers), 'all', " +
', '.join(["'{}'".format(s) for s in supported_sanitizers])))
AddOption('--enable-debug',
dest='enable_debug',
action='store_true',
help='enable debug build for Roc')
AddOption('--enable-debug-3rdparty',
dest='enable_debug_3rdparty',
action='store_true',
help='enable debug build for 3rdparty libraries')
AddOption('--enable-werror',
dest='enable_werror',
action='store_true',
help='treat warnings as errors')
AddOption('--enable-static',
dest='enable_static',
action='store_true',
help='enable building static library')
AddOption('--disable-shared',
dest='disable_shared',
action='store_true',
help='disable building shared library')
AddOption('--disable-tools',
dest='disable_tools',
action='store_true',
help='disable tools building')
AddOption('--enable-tests',
dest='enable_tests',
action='store_true',
help='enable tests building and running (requires CppUTest)')
AddOption('--enable-benchmarks',
dest='enable_benchmarks',
action='store_true',
help='enable bechmarks building and running (requires Google Benchmark)')
AddOption('--enable-examples',
dest='enable_examples',
action='store_true',
help='enable examples building')
AddOption('--enable-doxygen',
dest='enable_doxygen',
action='store_true',
help='enable Doxygen documentation generation')
AddOption('--enable-sphinx',
dest='enable_sphinx',
action='store_true',
help='enable Sphinx documentation generation')
AddOption('--disable-c11',
dest='disable_c11',
action='store_true',
help='disable C11 support')
AddOption('--disable-soversion',
dest='disable_soversion',
action='store_true',
help=("don't write version into the shared library"
" and don't create version symlinks"))
AddOption('--disable-openfec',
dest='disable_openfec',
action='store_true',
help='disable OpenFEC support required for FEC codes')
AddOption('--disable-speexdsp',
dest='disable_speexdsp',
action='store_true',
help='disable SpeexDSP support for resampling')
AddOption('--disable-sox',
dest='disable_sox',
action='store_true',
help='disable SoX support in tools')
AddOption('--disable-sndfile',
dest='disable_sndfile',
action='store_true',
help='disable sndfile support in tools')
AddOption('--disable-openssl',
dest='disable_openssl',
action='store_true',
help='disable OpenSSL support required for DTLS and SRTP')
AddOption('--disable-libunwind',
dest='disable_libunwind',
action='store_true',
help='disable libunwind support required for printing backtrace')
AddOption('--disable-alsa',
dest='disable_alsa',
action='store_true',
help='disable ALSA support in tools')
AddOption('--disable-pulseaudio',
dest='disable_pulseaudio',
action='store_true',
help='disable PulseAudio support in tools')
AddOption('--with-openfec-includes',
dest='with_openfec_includes',
action='store',
type='string',
help=("path to the directory with OpenFEC headers (it should contain"
" lib_common and lib_stable subdirectories)"))
AddOption('--with-includes',
dest='with_includes',
action='append',
type='string',
help=("additional include search path, may be used multiple times"))
AddOption('--with-libraries',
dest='with_libraries',
action='append',
type='string',
help=("additional library search path, may be used multiple times"))
AddOption('--macos-platform',
dest='macos_platform',
action='store',
type='string',
help=("macOS target platform, e.g. 10.12,"
" (default is current OS version)"))
AddOption('--macos-arch',
dest='macos_arch',
action='store',
type='string',
help=("macOS target architecture(s),"
" comma-separated list, supported values: {}".format(
', '.join(["'{}'".format(s) for s in supported_macos_archs])) +
" (default is current OS arch, pass multiple values"
" or 'all' for univeral binaries)"))
AddOption('--build-3rdparty',
dest='build_3rdparty',
action='store',
type='string',
help=("download and build specified 3rdparty libraries,"
" comma-separated list of library names and optional"
" versions, e.g. 'libuv:1.4.2,openfec'"))
AddOption('--override-targets',
dest='override_targets',
action='store',
type='string',
help=("override targets to use,"
" pass a comma-separated list of target names,"
" e.g. 'pc,posix,posix_ext,gnu,libuv,openfec,...'"))
# configure even in dry run mode
SCons.SConf.dryrun = 0
# when we cross-compile on macOS to Android using clang, we should use
# GNU-like clang options, but SCons incorrectly sets up Apple-like
# clang options; here we prevent this behavior by forcing 'posix' platform
scons_platform = Environment(ENV=os.environ)['PLATFORM']
for opt in ['host', 'platform']:
if 'android' in (GetOption(opt) or ''):
scons_platform = 'posix'
env = Environment(
ENV=os.environ,
platform=scons_platform,
toolpath=[os.path.join(Dir('#').abspath, 'scripts')],
tools=[
'default',
'scons_plugin', # our plugin in scripts/
])
# performance tuning
env.Decider('MD5-timestamp')
env.SetOption('implicit_cache', 1)
# provide absolute path to force single sconsign file
# per-directory sconsign files seems to be buggy with generated sources
# create separate sconsign file for each python version, since different
# python versions can use different pickle protocols and switching from
# a higher version to a lower one would cause exception
env.SConsignFile(os.path.join(
env.Dir('#').abspath, '.sconsign{}{}.dblite'.format(*sys.version_info[0:2])))
# we always use -fPIC, so object files built for static and shared
# libraries are no different
env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
# fill vars from environment (CC=gcc scons ...) and arguments (scons CC=gcc ...)
for var in ['CXX', 'CC', 'LD', 'AR', 'RANLIB', 'LIPO', 'INSTALL_NAME_TOOL',
'RAGEL', 'GENGETOPT',
'PKG_CONFIG', 'PKG_CONFIG_PATH', 'CONFIG_GUESS',
'CLANG_FORMAT']:
env.OverrideFromArgument(var)
env.OverrideFromArgument('CXXLD', names=['CXXLD', 'CXX'])
env.OverrideFromArgument('CCLD', names=['CCLD', 'LD', 'CC'])
env.OverrideFromArgument('STRIP', default='strip')
env.OverrideFromArgument('OBJCOPY', default='objcopy')
env.OverrideFromArgument('DOXYGEN', default='doxygen')
env.OverrideFromArgument('SPHINX_BUILD', default='sphinx-build')
env.OverrideFromArgument('BREATHE_APIDOC', default='breathe-apidoc')
env.OverrideFromArgument('DESTDIR')
env.PrependFromArgument('CPPFLAGS')
env.PrependFromArgument('CXXFLAGS')
env.PrependFromArgument('CFLAGS')
env.PrependFromArgument('LINKFLAGS', names=['LINKFLAGS', 'LDFLAGS'])
env.PrependFromArgument('STRIPFLAGS')
# ensure that these vars always exist
env.Append(CXXFLAGS=[])
env.Append(CPPDEFINES=[])
env.Append(CPPPATH=[])
env.Append(LIBPATH=[])
env.Append(LIBS=[])
env.Append(STRIPFLAGS=[])
# handle --with-*
if GetOption('with_includes'):
env.Append(CPPPATH=GetOption('with_includes'))
if GetOption('with_libraries'):
env.Append(LIBPATH=GetOption('with_libraries'))
# handle --help
if GetOption('help'):
Return()
# clean* targets
clean_build = []
for p in ['bin', 'build/src']:
for d in env.GlobDirs(p):
clean_build += [env.DeleteDir(d)]
clean_doc = []
for p in ['build/docs', 'docs/html']:
for d in env.GlobDirs(p):
clean_doc += [env.DeleteDir(d)]
clean_all = []
for p in ['bin',
'build',
'dist',
'docs/html',
'compile_commands.json',
'config.log',
'.sconsign*.dblite',
'.sconf_temp',
'debian/.debhelper',
'debian/tmp',
'debian/libroc',
'debian/libroc-dev',
'debian/roc',
'debian/*.substvars',
'debian/*.debhelper.log',
'debian/debhelper-*',
'debian/files',
]:
for d in env.GlobDirs(p):
clean_all += [env.DeleteDir(d)]
for f in env.GlobFiles(p):
clean_all += [env.DeleteFile(f)]
env.AlwaysBuild(env.Alias('clean', [], clean_all))
env.AlwaysBuild(env.Alias('cleanbuild', [], clean_build))
env.AlwaysBuild(env.Alias('cleandocs', [], clean_doc))
if set(COMMAND_LINE_TARGETS).intersection(['clean', 'cleanbuild', 'cleandocs']) or \
env.GetOption('clean'):
if set(COMMAND_LINE_TARGETS) - set(['clean', 'cleanbuild', 'cleandocs']):
env.Die("combining 'clean*' targets with other targets is not allowed")
if env.GetOption('clean'):
if clean_all:
env.Execute(clean_all)
else:
print("scons: Nothing to be done for `clean'.")
Return()
# fmt target
if 'fmt' in COMMAND_LINE_TARGETS:
conf = Configure(env, custom_tests=env.CustomTests)
conf.FindClangFormat()
env = conf.Finish()
fmt_actions = []
fmt_actions.append(env.ClangFormat('#src'))
fmt_actions.append(env.HeaderFormat('#src/internal_modules'))
fmt_actions.append(env.HeaderFormat('#src/public_api/src'))
fmt_actions.append(env.HeaderFormat('#src/tests'))
fmt_actions.append(env.HeaderFormat('#src/tools'))
env.AlwaysBuild(
env.Alias('fmt', [], fmt_actions))
# build documentation
doc_env = env.DeepClone()
doc_env.SConscript('docs/SConscript',
duplicate=0, exports='doc_env')
# exit early if there is nothing to build
non_build_targets = ['fmt', 'docs', 'sphinx', 'doxygen']
if set(COMMAND_LINE_TARGETS) \
and set(COMMAND_LINE_TARGETS).intersection(non_build_targets) == set(COMMAND_LINE_TARGETS):
Return()
# meta-information about the build, used to generate env parameters
meta = type('meta', (), {
field: '' for field in ('build host toolchain platform variant thirdparty_variant '
'compiler compiler_ver '
'c11_support gnu_toolchain').split()})
# toolchain triple of the local system (where we're building), e.g. x86_64-pc-linux-gnu
meta.build = GetOption('build')
# toolchain triple of the target system (where we will run), e.g. aarch64-linux-gnu
meta.host = GetOption('host') or ''
# toolchain prefix for compiler, linker, and other tools, e.g. aarch64-linux-gnu
meta.toolchain = GetOption('host') or ''
# name of the target platform, e.g. 'linux'; see supported_platforms
meta.platform = GetOption('platform') or ''
# build variant, i.e. 'debug' or 'release'
meta.variant = 'debug' if GetOption('enable_debug') else 'release'
# build variant for third-parties
meta.thirdparty_variant = 'debug' if GetOption('enable_debug_3rdparty') else 'release'
# compiler name, e.g. 'gcc', and version tuple, e.g. (4, 9)
if GetOption('compiler'):
meta.compiler = GetOption('compiler')
if '-' in meta.compiler:
meta.compiler, meta.compiler_ver = meta.compiler.split('-')
meta.compiler_ver = tuple(map(int, meta.compiler_ver.split('.')))
else:
if env.HasArgument('CXX'):
meta.compiler = env.ParseCompilerType(env['CXX'])
elif meta.toolchain:
if env.Which('{}-clang++'.format(meta.toolchain)):
meta.compiler = 'clang'
elif env.Which('{}-g++'.format(meta.toolchain)):
meta.compiler = 'gcc'
elif env.Which('{}-c++'.format(meta.toolchain)):
meta.compiler = 'cc'
else:
if env.Which('clang++'):
meta.compiler = 'clang'
elif env.Which('g++'):
meta.compiler = 'gcc'
elif env.Which('c++'):
meta.compiler = 'cc'
if not meta.compiler:
env.Die("can't detect compiler name, please specify '--compiler=<name>' manually, "
"should be one of: {}", ', '.join(supported_compilers))
if not meta.compiler in supported_compilers:
env.Die("unknown --compiler '{}', expected one of: {}",
meta.compiler, ', '.join(supported_compilers))
if not meta.compiler_ver:
if meta.toolchain:
meta.compiler_ver = env.ParseCompilerVersion('{}-{}'.format(meta.toolchain, meta.compiler))
else:
meta.compiler_ver = env.ParseCompilerVersion(meta.compiler)
if not meta.compiler_ver:
if meta.compiler not in ['cc']:
env.Die("can't detect compiler version for compiler '{}'",
'-'.join([s for s in [meta.toolchain, meta.compiler] if s]))
conf = Configure(env, custom_tests=env.CustomTests)
if meta.compiler == 'clang':
conf.FindLLVMDir(meta.compiler_ver)
if meta.compiler == 'clang':
conf.FindTool('CXX', [meta.toolchain], [('clang++', meta.compiler_ver)])
elif meta.compiler == 'gcc':
conf.FindTool('CXX', [meta.toolchain], [('g++', meta.compiler_ver)])
elif meta.compiler == 'cc':
conf.FindTool('CXX', [meta.toolchain], [('c++', meta.compiler_ver)])
full_compiler_ver = env.ParseCompilerVersion(conf.env['CXX'])
if full_compiler_ver:
meta.compiler_ver = full_compiler_ver
if not meta.build:
for local_compiler in ['/usr/bin/gcc', '/usr/bin/clang']:
meta.build = env.ParseCompilerTarget(local_compiler)
if meta.build:
break
if not meta.build and not meta.host:
if conf.CheckCanRunProgs():
meta.build = env.ParseCompilerTarget(conf.env['CXX'])
if not meta.build:
if conf.FindConfigGuess():
meta.build = env.ParseConfigGuess(conf.env['CONFIG_GUESS'])
if not meta.build:
env.Die(("can't detect system type, please specify '--build=<type>' manually, "
"e.g. '--build=x86_64-pc-linux-gnu'"))
if not meta.host:
meta.host = env.ParseCompilerTarget(conf.env['CXX'])
if not meta.host:
meta.host = meta.build
if not meta.toolchain and meta.build != meta.host:
meta.toolchain = meta.host
if not meta.toolchain and meta.build == meta.host:
meta.build = meta.host = env.ParseMacosHost(
meta.host, GetOption('macos_platform'), GetOption('macos_arch'))
if not meta.platform:
if 'android' in meta.host:
meta.platform = 'android'
elif 'linux' in meta.host:
meta.platform = 'linux'
elif 'darwin' in meta.host:
meta.platform = 'darwin'
elif 'gnu' in meta.host:
meta.platform = 'unix'
if not meta.platform and meta.host == meta.build:
if os.name == 'posix':
meta.platform = 'unix'
if not meta.platform:
env.Die("can't detect platform name, please specify '--platform=<name>' manually, "
"should be one of: {}", ', '.join(supported_platforms))
if meta.platform not in supported_platforms:
env.Die(("unknown --platform '{}', expected on of: {}"),
meta.platform, ', '.join(supported_platforms))
allowed_toolchains = [meta.toolchain]
if meta.toolchain != '' and meta.build == meta.host:
allowed_toolchains += ['']
if meta.compiler == 'clang':
conf.FindTool('CXX', allowed_toolchains, [('clang++', meta.compiler_ver)])
conf.FindTool('CC', allowed_toolchains, [('clang', meta.compiler_ver)])
conf.FindTool('CXXLD', allowed_toolchains, [('clang++', meta.compiler_ver)])
conf.FindTool('CCLD', allowed_toolchains, [('clang', meta.compiler_ver)])
conf.FindTool('LD', allowed_toolchains, [('ld', None)], required=False)
compiler_dir = env.ParseCompilerDirectory(conf.env['CXX'])
if compiler_dir:
prepend_path = [compiler_dir]
else:
prepend_path = []
conf.FindTool('AR', allowed_toolchains,
[('llvm-ar', meta.compiler_ver), ('llvm-ar', None), ('ar', None)],
compiler_dir=compiler_dir,
prepend_path=prepend_path)
conf.FindTool('RANLIB', allowed_toolchains,
[('llvm-ranlib', meta.compiler_ver), ('llvm-ranlib', None), ('ranlib', None)],
compiler_dir=compiler_dir,
prepend_path=prepend_path)
conf.FindTool('STRIP', allowed_toolchains,
[('llvm-strip', meta.compiler_ver), ('llvm-strip', None), ('strip', None)],
compiler_dir=compiler_dir,
prepend_path=prepend_path)
conf.FindTool('OBJCOPY', allowed_toolchains,
[('llvm-objcopy', meta.compiler_ver),
('llvm-objcopy', None),
('objcopy', None)],
compiler_dir=compiler_dir,
prepend_path=prepend_path,
required=False)
elif meta.compiler == 'gcc':
conf.FindTool('CXX', allowed_toolchains, [('g++', meta.compiler_ver)])
conf.FindTool('CC', allowed_toolchains, [('gcc', meta.compiler_ver)])
conf.FindTool('CXXLD', allowed_toolchains, [('g++', meta.compiler_ver)])
conf.FindTool('CCLD', allowed_toolchains, [('gcc', meta.compiler_ver)])
conf.FindTool('LD', allowed_toolchains, [('ld', None)], required=False)
conf.FindTool('AR', allowed_toolchains, [('ar', None)])
conf.FindTool('RANLIB', allowed_toolchains, [('ranlib', None)])
conf.FindTool('STRIP', allowed_toolchains, [('strip', None)])
conf.FindTool('OBJCOPY', allowed_toolchains, [('objcopy', None)], required=False)
elif meta.compiler == 'cc':
conf.FindTool('CXX', allowed_toolchains, [('c++', meta.compiler_ver)])
conf.FindTool('CC', allowed_toolchains, [('cc', meta.compiler_ver)])
conf.FindTool('CXXLD', allowed_toolchains, [('c++', meta.compiler_ver)])
conf.FindTool('CCLD', allowed_toolchains, [('cc', meta.compiler_ver)])
conf.FindTool('AR', allowed_toolchains, [('ar', None)])
conf.FindTool('RANLIB', allowed_toolchains, [('ranlib', None)])
conf.FindTool('STRIP', allowed_toolchains, [('strip', None)])
conf.env['LINK'] = env['CXXLD']
conf.env['SHLINK'] = env['CXXLD']
if GetOption('compiler_launcher'):
conf.FindProgram('COMPILER_LAUNCHER', GetOption('compiler_launcher'))
if meta.platform == 'darwin':
conf.FindTool('LIPO', [''], [('lipo', None)], required=False)
conf.FindTool('INSTALL_NAME_TOOL', [''], [('install_name_tool', None)], required=False)
meta.c11_support = False
if not GetOption('disable_c11'):
if meta.compiler == 'gcc':
meta.c11_support = meta.compiler_ver[:2] >= (4, 9)
elif meta.compiler == 'clang' and meta.platform == 'darwin':
meta.c11_support = meta.compiler_ver[:2] >= (7, 0)
elif meta.compiler == 'clang' and meta.platform != 'darwin':
meta.c11_support = meta.compiler_ver[:2] >= (3, 6)
# true if we have full-featured GNU toolchain with all needed compiler and linker options
# note that macOS is excluded
meta.gnu_toolchain = False
if meta.platform in ['linux', 'unix']:
meta.gnu_toolchain = 'gnu' in meta.host
elif meta.platform in ['android']:
meta.gnu_toolchain = True
conf.env['ROC_SYSTEM_BINDIR'] = GetOption('bindir')
conf.env['ROC_SYSTEM_INCDIR'] = GetOption('incdir')
if GetOption('libdir'):
conf.env['ROC_SYSTEM_LIBDIR'] = GetOption('libdir')
else:
conf.FindLibDir(GetOption('prefix'), meta.host)
conf.env['ROC_SYSTEM_PCDIR'] = os.path.join(env['ROC_SYSTEM_LIBDIR'], 'pkgconfig')
conf.FindPkgConfig(meta.toolchain)
conf.FindPkgConfigPath(GetOption('prefix'))
env = conf.Finish()
# build directories
env['ROC_BINDIR'] = '#bin/{}'.format(meta.host)
env['ROC_BUILDDIR'] = '#build/src/{}/{}'.format(
meta.host,
'-'.join(
[s for s in [
meta.compiler,
'.'.join(map(str, meta.compiler_ver)) if meta.compiler_ver else '',
meta.variant
] if s])
)
env['ROC_THIRDPARTY_BUILDDIR'] = '#build/3rdparty/{}/{}'.format(
meta.host,
'-'.join(
[s for s in [
meta.compiler,
'.'.join(map(str, meta.compiler_ver)) if meta.compiler_ver else '',
meta.thirdparty_variant
] if s])
)
# version info
env['ROC_VERSION'] = env.ParseProjectVersion('src/public_api/include/roc/version.h')
env['ROC_COMMIT'] = env.ParseGitHead()
env['ROC_SOVER'] = '.'.join(env['ROC_VERSION'].split('.')[:2])
# internal modules
env['ROC_MODULES'] = [
'roc_core',
'roc_status',
'roc_address',
'roc_packet',
'roc_audio',
'roc_rtp',
'roc_rtcp',
'roc_fec',
'roc_netio',
'roc_sndio',
'roc_pipeline',
'roc_sdp',
'roc_ctl',
'roc_node',
]
# build variant for roc and dependencies (e.g. 'debug' or 'release')
env['ROC_VARIANT'] = meta.variant
env['ROC_THIRDPARTY_VARIANT'] = meta.thirdparty_variant
# toolchain tuples (e.g. 'aarch64-linux-gnu')
env['ROC_BUILD'] = meta.build
env['ROC_HOST'] = meta.host
env['ROC_TOOLCHAIN'] = meta.toolchain
# platform identifier (e.g. 'linux', 'android')
env['ROC_PLATFORM'] = meta.platform
# platform version that we build against
env['ROC_POSIX_PLATFORM'] = '200809'
env['ROC_ANDROID_PLATFORM'] = '21'
# macOS target platform version and architecture(s)
env['ROC_MACOS_PLATFORM'] = env.ParseMacosPlatform(meta.host, GetOption('macos_platform'))
env['ROC_MACOS_ARCH'] = env.ParseMacosArch(meta.host, GetOption('macos_arch'))
# enabled target directories
env['ROC_TARGETS'] = []
if GetOption('override_targets'):
for t in GetOption('override_targets').split(','):
env['ROC_TARGETS'] += ['target_' + t]
else:
if meta.platform in ['linux', 'darwin', 'unix']:
env.Append(ROC_TARGETS=[
'target_pc',
])
if meta.platform in ['linux', 'android', 'darwin', 'unix']:
env.Append(ROC_TARGETS=[
'target_posix',
])
if meta.platform in ['linux', 'darwin', 'unix']:
env.Append(ROC_TARGETS=[
'target_posix_pc',
])
if meta.platform in ['linux', 'android', 'unix']:
env.Append(ROC_TARGETS=[
'target_posix_ext',
])
if meta.platform in ['linux', 'android' 'darwin'] or meta.gnu_toolchain:
env.Append(ROC_TARGETS=[
# GNU C++ Standard Library (libstdc++), or compatible, like
# LLVM C++ Standard Library (libc++)
'target_gnu',
])
if meta.platform in ['darwin']:
env.Append(ROC_TARGETS=[
'target_darwin',
])
if meta.platform in ['android']:
env.Append(ROC_TARGETS=[
'target_android',
])
if meta.c11_support:
env.Append(ROC_TARGETS=[
'target_c11',
])
else:
env.Append(ROC_TARGETS=[
'target_libatomic_ops',
])
if meta.platform in ['linux', 'darwin', 'unix'] and not GetOption('disable_libunwind'):
env.Append(ROC_TARGETS=[
'target_libunwind',
])
env.Append(ROC_TARGETS=[
'target_libuv',
])
if not GetOption('disable_openfec'):
env.Append(ROC_TARGETS=[
'target_openfec',
])
if not GetOption('disable_openssl'):
env.Append(ROC_TARGETS=[
'target_openssl',
])
else:
env.Append(ROC_TARGETS=[
'target_nocsprng',
])
if not GetOption('disable_speexdsp'):
env.Append(ROC_TARGETS=[
'target_speexdsp',
])
if not GetOption('disable_tools'):
if not GetOption('disable_sox'):
env.Append(ROC_TARGETS=[
'target_sox',
])
if not GetOption('disable_sndfile'):
env.Append(ROC_TARGETS=[
'target_sndfile',
])
if not GetOption('disable_alsa') and meta.platform in ['linux']:
env.Append(ROC_TARGETS=[
'target_alsa',
])
if not GetOption('disable_pulseaudio') and meta.platform in ['linux']:
env.Append(ROC_TARGETS=[
'target_pulseaudio',
])
if 'target_gnu' not in env['ROC_TARGETS']:
env.Append(ROC_TARGETS=[
'target_nodemangle',
])
if 'target_libunwind' not in env['ROC_TARGETS'] and \
'target_android' not in env['ROC_TARGETS']:
env.Append(ROC_TARGETS=[
'target_nobacktrace',
])
# env will hold settings common to all code
# subenvs will hold settings specific to particular parts of code
subenv_names = 'internal_modules public_libs examples tools tests generated_code'.split()
subenv_attrs = {field: env.DeepClone() for field in subenv_names}
subenv_attrs['all'] = list(subenv_attrs.values())
subenvs = type('subenvs', (), subenv_attrs)
# find or build third-party dependencies
env, subenvs = env.SConscript('3rdparty/SConscript',
duplicate=0, exports='env subenvs meta')
env.Append(CPPDEFINES=[
# for UINT32_MAX and others (https://bugzilla.mozilla.org/show_bug.cgi?id=673556):
('__STDC_LIMIT_MACROS', '1'),
])
if 'target_posix' in env['ROC_TARGETS'] and meta.platform not in ['darwin']:
# macOS is special, otherwise rely on _POSIX_C_SOURCE
env.Append(CPPDEFINES=[('_POSIX_C_SOURCE', env['ROC_POSIX_PLATFORM'])])
if meta.platform in ['darwin']:
if env['ROC_MACOS_PLATFORM']:
for var in ['CXXFLAGS', 'CFLAGS', 'LINKFLAGS']:
env.Append(**{var: [
'-mmacosx-version-min=' + env['ROC_MACOS_PLATFORM'],
]})
for arch in env['ROC_MACOS_ARCH']:
for var in ['CXXFLAGS', 'CFLAGS', 'LINKFLAGS']:
env.Append(**{var: [
'-arch', arch,
]})
if meta.platform in ['linux', 'unix']:
env.AddManualDependency(libs=['rt', 'dl', 'm'])
if meta.platform in ['android']:
env.AddManualDependency(libs=['log', 'android'])
if meta.compiler in ['gcc', 'clang']:
if not meta.platform in ['android']:
env.Append(CXXFLAGS=[
'-std=c++98',
])
env.Append(CXXFLAGS=[
'-fno-exceptions',
])
for var in ['CXXFLAGS', 'CFLAGS']:
env.Append(**{var: [
'-pthread',
'-fPIC',
]})
if meta.platform in ['linux', 'darwin']:
env.AddManualDependency(libs=['pthread'])
if meta.platform in ['linux', 'android'] or meta.gnu_toolchain:
if not GetOption('disable_soversion'):
subenvs.public_libs['SHLIBSUFFIX'] = '{}.{}'.format(
subenvs.public_libs['SHLIBSUFFIX'], env['ROC_SOVER'])
subenvs.public_libs.Append(LINKFLAGS=[
'-Wl,-soname,libroc{}'.format(subenvs.public_libs['SHLIBSUFFIX']),
])
if meta.variant == 'release':
subenvs.public_libs.Append(LINKFLAGS=[
'-Wl,--version-script={}'.format(env.File('#src/public_api/roc.version').path)
])
if meta.platform in ['darwin']:
if not GetOption('disable_soversion'):
subenvs.public_libs['SHLIBSUFFIX'] = '.{}{}'.format(
env['ROC_SOVER'], subenvs.public_libs['SHLIBSUFFIX'])
subenvs.public_libs.Append(LINKFLAGS=[
'-Wl,-compatibility_version,{}'.format(env['ROC_SOVER']),
'-Wl,-current_version,{}'.format(env['ROC_VERSION']),
])
subenvs.public_libs.Append(LINKFLAGS=[
'-Wl,-install_name,{}/libroc{}'.format(
env.Dir(env['ROC_BINDIR']).abspath, subenvs.public_libs['SHLIBSUFFIX']),
])
if meta.variant == 'release':
subenvs.public_libs.Append(LINKFLAGS=[
'-Wl,-exported_symbol,_roc_*',
])
if not(meta.compiler == 'clang' and meta.variant == 'debug'):
env.Append(CXXFLAGS=[
'-fno-rtti',
])
if meta.variant == 'debug':
for var in ['CXXFLAGS', 'CFLAGS']:
env.Append(**{var: [
'-ggdb',
'-funwind-tables',
'-fno-omit-frame-pointer',
]})
env.Append(LINKFLAGS=[
'-rdynamic'
])
else:
for var in ['CXXFLAGS', 'CFLAGS']:
env.Append(**{var: [
'-fvisibility=hidden',
'-O3',
]})
if meta.compiler == 'gcc' and meta.compiler_ver[:2] < (4, 6):
for var in ['CXXFLAGS', 'CFLAGS']:
env.Append(**{var: [
'-fno-strict-aliasing',
]})
if meta.compiler in ['cc']:
env.AddManualDependency(libs=['pthread'])
if meta.variant == 'debug':
for var in ['CXXFLAGS', 'CFLAGS']:
env.Append(**{var: [
'-g',
]})
else:
for var in ['CXXFLAGS', 'CFLAGS']:
env.Append(**{var: [
'-O3',
]})
for var in ['CXXFLAGS', 'CFLAGS']:
conf.env.Append(**{var: [
'-fPIC',