blob: b7762cb4e94be2728039a65697f7a12bd49f8b8a [file] [log] [blame]
José Fonseca94090432008-02-27 17:36:28 +09001#######################################################################
2# Common SCons code
3
4import os
5import os.path
Brian Paul5c682482010-05-20 10:25:17 -06006import re
José Fonsecaea532f02010-04-10 02:41:39 +01007import subprocess
José Fonseca94090432008-02-27 17:36:28 +09008import sys
9import platform as _platform
10
José Fonseca601498a2010-11-01 13:30:22 +000011import SCons.Script.SConscript
12
José Fonseca94090432008-02-27 17:36:28 +090013
14#######################################################################
15# Defaults
16
José Fonsecaae760272011-02-11 16:44:13 +000017host_platform = _platform.system().lower()
Vinson Leeeb178022011-02-24 19:49:37 -080018if host_platform.startswith('cygwin'):
19 host_platform = 'cygwin'
Prodea Alexandru-Liviu6309c312019-10-05 08:43:13 +000020# MSYS2 default platform selection.
21if host_platform.startswith('mingw'):
22 host_platform = 'windows'
José Fonseca94090432008-02-27 17:36:28 +090023
José Fonseca601498a2010-11-01 13:30:22 +000024# Search sys.argv[] for a "platform=foo" argument since we don't have
25# an 'env' variable at this point.
26if 'platform' in SCons.Script.ARGUMENTS:
José Fonsecae1bc68b2011-01-13 20:52:01 +000027 target_platform = SCons.Script.ARGUMENTS['platform']
José Fonseca601498a2010-11-01 13:30:22 +000028else:
José Fonsecae1bc68b2011-01-13 20:52:01 +000029 target_platform = host_platform
José Fonseca601498a2010-11-01 13:30:22 +000030
José Fonseca94090432008-02-27 17:36:28 +090031_machine_map = {
Vinson Lee60f77b22015-03-14 01:45:03 -070032 'x86': 'x86',
33 'i386': 'x86',
34 'i486': 'x86',
35 'i586': 'x86',
36 'i686': 'x86',
37 'BePC': 'x86',
38 'Intel': 'x86',
39 'ppc': 'ppc',
40 'BeBox': 'ppc',
41 'BeMac': 'ppc',
42 'AMD64': 'x86_64',
43 'x86_64': 'x86_64',
44 'sparc': 'sparc',
45 'sun4u': 'sparc',
José Fonseca94090432008-02-27 17:36:28 +090046}
Brian Paul6ca61892010-05-20 10:26:19 -060047
48
José Fonsecae1bc68b2011-01-13 20:52:01 +000049# find host_machine value
José Fonseca94090432008-02-27 17:36:28 +090050if 'PROCESSOR_ARCHITECTURE' in os.environ:
Vinson Lee60f77b22015-03-14 01:45:03 -070051 host_machine = os.environ['PROCESSOR_ARCHITECTURE']
José Fonseca94090432008-02-27 17:36:28 +090052else:
Vinson Lee60f77b22015-03-14 01:45:03 -070053 host_machine = _platform.machine()
José Fonsecae1bc68b2011-01-13 20:52:01 +000054host_machine = _machine_map.get(host_machine, 'generic')
Prodea Alexandru-Liviu6309c312019-10-05 08:43:13 +000055# MSYS2 default machine selection.
56if _platform.system().lower().startswith('mingw') and 'MSYSTEM' in os.environ:
57 if os.environ['MSYSTEM'] == 'MINGW32':
58 host_machine = 'x86'
59 if os.environ['MSYSTEM'] == 'MINGW64':
60 host_machine = 'x86_64'
José Fonsecae1bc68b2011-01-13 20:52:01 +000061
62default_machine = host_machine
José Fonseca601498a2010-11-01 13:30:22 +000063default_toolchain = 'default'
Prodea Alexandru-Liviu6309c312019-10-05 08:43:13 +000064# MSYS2 default toolchain selection.
65if _platform.system().lower().startswith('mingw'):
66 default_toolchain = 'mingw'
José Fonseca601498a2010-11-01 13:30:22 +000067
José Fonsecaae760272011-02-11 16:44:13 +000068if target_platform == 'windows' and host_platform != 'windows':
José Fonseca601498a2010-11-01 13:30:22 +000069 default_machine = 'x86'
70 default_toolchain = 'crossmingw'
José Fonseca94090432008-02-27 17:36:28 +090071
Brian Paul6ca61892010-05-20 10:26:19 -060072
73# find default_llvm value
Vinson Leef07da5a2016-11-22 17:01:35 -080074if 'LLVM' in os.environ or 'LLVM_CONFIG' in os.environ:
José Fonsecaea532f02010-04-10 02:41:39 +010075 default_llvm = 'yes'
76else:
77 default_llvm = 'no'
José Fonsecacd4e5872010-04-13 19:40:48 +090078 try:
José Fonsecae1bc68b2011-01-13 20:52:01 +000079 if target_platform != 'windows' and \
Vinson Lee60f77b22015-03-14 01:45:03 -070080 subprocess.call(['llvm-config', '--version'],
81 stdout=subprocess.PIPE) == 0:
José Fonsecacd4e5872010-04-13 19:40:48 +090082 default_llvm = 'yes'
83 except:
84 pass
José Fonsecaea532f02010-04-10 02:41:39 +010085
Brian Paul6ca61892010-05-20 10:26:19 -060086
José Fonseca94090432008-02-27 17:36:28 +090087#######################################################################
88# Common options
89
José Fonseca13174c12008-03-03 18:52:37 +010090def AddOptions(opts):
Vinson Lee60f77b22015-03-14 01:45:03 -070091 try:
92 from SCons.Variables.BoolVariable import BoolVariable as BoolOption
93 except ImportError:
94 from SCons.Options.BoolOption import BoolOption
95 try:
96 from SCons.Variables.EnumVariable import EnumVariable as EnumOption
97 except ImportError:
98 from SCons.Options.EnumOption import EnumOption
99 opts.Add(EnumOption('build', 'build type', 'debug',
100 allowed_values=('debug', 'checked', 'profile',
Brian Pauld6be0b52018-10-26 10:23:39 -0600101 'release')))
Vinson Lee60f77b22015-03-14 01:45:03 -0700102 opts.Add(BoolOption('verbose', 'verbose output', 'no'))
103 opts.Add(EnumOption('machine', 'use machine-specific assembly code',
104 default_machine,
105 allowed_values=('generic', 'ppc', 'x86', 'x86_64')))
106 opts.Add(EnumOption('platform', 'target platform', host_platform,
107 allowed_values=('cygwin', 'darwin', 'freebsd', 'haiku',
108 'linux', 'sunos', 'windows')))
109 opts.Add(BoolOption('embedded', 'embedded build', 'no'))
110 opts.Add(BoolOption('analyze',
111 'enable static code analysis where available', 'no'))
Jose Fonsecafa468482016-04-09 20:26:42 +0100112 opts.Add(BoolOption('asan', 'enable Address Sanitizer', 'no'))
Vinson Lee60f77b22015-03-14 01:45:03 -0700113 opts.Add('toolchain', 'compiler toolchain', default_toolchain)
Vinson Lee60f77b22015-03-14 01:45:03 -0700114 opts.Add(BoolOption('llvm', 'use LLVM', default_llvm))
Dylan Baker54053bc2019-10-21 09:29:23 -0700115 opts.Add(BoolOption('force_scons', 'Force enable scons on deprecated platforms', 'false'))
Vinson Lee60f77b22015-03-14 01:45:03 -0700116 opts.Add(BoolOption('openmp', 'EXPERIMENTAL: compile with openmp (swrast)',
117 'no'))
118 opts.Add(BoolOption('debug', 'DEPRECATED: debug build', 'yes'))
119 opts.Add(BoolOption('profile', 'DEPRECATED: profile build', 'no'))
120 opts.Add(BoolOption('quiet', 'DEPRECATED: profile build', 'yes'))
George Kyriazis9085f1a2016-11-15 18:52:39 -0600121 opts.Add(BoolOption('swr', 'Build OpenSWR', 'no'))
Vinson Lee60f77b22015-03-14 01:45:03 -0700122 if host_platform == 'windows':
123 opts.Add('MSVC_VERSION', 'Microsoft Visual C/C++ version')
Jose Fonseca7c5aece2018-10-09 16:46:21 +0100124 opts.Add('MSVC_USE_SCRIPT', 'Microsoft Visual C/C++ vcvarsall script', True)