José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 1 | ####################################################################### |
| 2 | # Common SCons code |
| 3 | |
| 4 | import os |
| 5 | import os.path |
Brian Paul | 5c68248 | 2010-05-20 10:25:17 -0600 | [diff] [blame] | 6 | import re |
José Fonseca | ea532f0 | 2010-04-10 02:41:39 +0100 | [diff] [blame] | 7 | import subprocess |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 8 | import sys |
| 9 | import platform as _platform |
| 10 | |
José Fonseca | 601498a | 2010-11-01 13:30:22 +0000 | [diff] [blame] | 11 | import SCons.Script.SConscript |
| 12 | |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 13 | |
| 14 | ####################################################################### |
| 15 | # Defaults |
| 16 | |
José Fonseca | ae76027 | 2011-02-11 16:44:13 +0000 | [diff] [blame] | 17 | host_platform = _platform.system().lower() |
Vinson Lee | eb17802 | 2011-02-24 19:49:37 -0800 | [diff] [blame] | 18 | if host_platform.startswith('cygwin'): |
| 19 | host_platform = 'cygwin' |
Prodea Alexandru-Liviu | 6309c31 | 2019-10-05 08:43:13 +0000 | [diff] [blame] | 20 | # MSYS2 default platform selection. |
| 21 | if host_platform.startswith('mingw'): |
| 22 | host_platform = 'windows' |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 23 | |
José Fonseca | 601498a | 2010-11-01 13:30:22 +0000 | [diff] [blame] | 24 | # Search sys.argv[] for a "platform=foo" argument since we don't have |
| 25 | # an 'env' variable at this point. |
| 26 | if 'platform' in SCons.Script.ARGUMENTS: |
José Fonseca | e1bc68b | 2011-01-13 20:52:01 +0000 | [diff] [blame] | 27 | target_platform = SCons.Script.ARGUMENTS['platform'] |
José Fonseca | 601498a | 2010-11-01 13:30:22 +0000 | [diff] [blame] | 28 | else: |
José Fonseca | e1bc68b | 2011-01-13 20:52:01 +0000 | [diff] [blame] | 29 | target_platform = host_platform |
José Fonseca | 601498a | 2010-11-01 13:30:22 +0000 | [diff] [blame] | 30 | |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 31 | _machine_map = { |
Vinson Lee | 60f77b2 | 2015-03-14 01:45:03 -0700 | [diff] [blame] | 32 | '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é Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 46 | } |
Brian Paul | 6ca6189 | 2010-05-20 10:26:19 -0600 | [diff] [blame] | 47 | |
| 48 | |
José Fonseca | e1bc68b | 2011-01-13 20:52:01 +0000 | [diff] [blame] | 49 | # find host_machine value |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 50 | if 'PROCESSOR_ARCHITECTURE' in os.environ: |
Vinson Lee | 60f77b2 | 2015-03-14 01:45:03 -0700 | [diff] [blame] | 51 | host_machine = os.environ['PROCESSOR_ARCHITECTURE'] |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 52 | else: |
Vinson Lee | 60f77b2 | 2015-03-14 01:45:03 -0700 | [diff] [blame] | 53 | host_machine = _platform.machine() |
José Fonseca | e1bc68b | 2011-01-13 20:52:01 +0000 | [diff] [blame] | 54 | host_machine = _machine_map.get(host_machine, 'generic') |
Prodea Alexandru-Liviu | 6309c31 | 2019-10-05 08:43:13 +0000 | [diff] [blame] | 55 | # MSYS2 default machine selection. |
| 56 | if _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é Fonseca | e1bc68b | 2011-01-13 20:52:01 +0000 | [diff] [blame] | 61 | |
| 62 | default_machine = host_machine |
José Fonseca | 601498a | 2010-11-01 13:30:22 +0000 | [diff] [blame] | 63 | default_toolchain = 'default' |
Prodea Alexandru-Liviu | 6309c31 | 2019-10-05 08:43:13 +0000 | [diff] [blame] | 64 | # MSYS2 default toolchain selection. |
| 65 | if _platform.system().lower().startswith('mingw'): |
| 66 | default_toolchain = 'mingw' |
José Fonseca | 601498a | 2010-11-01 13:30:22 +0000 | [diff] [blame] | 67 | |
José Fonseca | ae76027 | 2011-02-11 16:44:13 +0000 | [diff] [blame] | 68 | if target_platform == 'windows' and host_platform != 'windows': |
José Fonseca | 601498a | 2010-11-01 13:30:22 +0000 | [diff] [blame] | 69 | default_machine = 'x86' |
| 70 | default_toolchain = 'crossmingw' |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 71 | |
Brian Paul | 6ca6189 | 2010-05-20 10:26:19 -0600 | [diff] [blame] | 72 | |
| 73 | # find default_llvm value |
Vinson Lee | f07da5a | 2016-11-22 17:01:35 -0800 | [diff] [blame] | 74 | if 'LLVM' in os.environ or 'LLVM_CONFIG' in os.environ: |
José Fonseca | ea532f0 | 2010-04-10 02:41:39 +0100 | [diff] [blame] | 75 | default_llvm = 'yes' |
| 76 | else: |
| 77 | default_llvm = 'no' |
José Fonseca | cd4e587 | 2010-04-13 19:40:48 +0900 | [diff] [blame] | 78 | try: |
José Fonseca | e1bc68b | 2011-01-13 20:52:01 +0000 | [diff] [blame] | 79 | if target_platform != 'windows' and \ |
Vinson Lee | 60f77b2 | 2015-03-14 01:45:03 -0700 | [diff] [blame] | 80 | subprocess.call(['llvm-config', '--version'], |
| 81 | stdout=subprocess.PIPE) == 0: |
José Fonseca | cd4e587 | 2010-04-13 19:40:48 +0900 | [diff] [blame] | 82 | default_llvm = 'yes' |
| 83 | except: |
| 84 | pass |
José Fonseca | ea532f0 | 2010-04-10 02:41:39 +0100 | [diff] [blame] | 85 | |
Brian Paul | 6ca6189 | 2010-05-20 10:26:19 -0600 | [diff] [blame] | 86 | |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 87 | ####################################################################### |
| 88 | # Common options |
| 89 | |
José Fonseca | 13174c1 | 2008-03-03 18:52:37 +0100 | [diff] [blame] | 90 | def AddOptions(opts): |
Vinson Lee | 60f77b2 | 2015-03-14 01:45:03 -0700 | [diff] [blame] | 91 | 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 Paul | d6be0b5 | 2018-10-26 10:23:39 -0600 | [diff] [blame] | 101 | 'release'))) |
Vinson Lee | 60f77b2 | 2015-03-14 01:45:03 -0700 | [diff] [blame] | 102 | 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 Fonseca | fa46848 | 2016-04-09 20:26:42 +0100 | [diff] [blame] | 112 | opts.Add(BoolOption('asan', 'enable Address Sanitizer', 'no')) |
Vinson Lee | 60f77b2 | 2015-03-14 01:45:03 -0700 | [diff] [blame] | 113 | opts.Add('toolchain', 'compiler toolchain', default_toolchain) |
Vinson Lee | 60f77b2 | 2015-03-14 01:45:03 -0700 | [diff] [blame] | 114 | opts.Add(BoolOption('llvm', 'use LLVM', default_llvm)) |
Dylan Baker | 54053bc | 2019-10-21 09:29:23 -0700 | [diff] [blame] | 115 | opts.Add(BoolOption('force_scons', 'Force enable scons on deprecated platforms', 'false')) |
Vinson Lee | 60f77b2 | 2015-03-14 01:45:03 -0700 | [diff] [blame] | 116 | 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 Kyriazis | 9085f1a | 2016-11-15 18:52:39 -0600 | [diff] [blame] | 121 | opts.Add(BoolOption('swr', 'Build OpenSWR', 'no')) |
Vinson Lee | 60f77b2 | 2015-03-14 01:45:03 -0700 | [diff] [blame] | 122 | if host_platform == 'windows': |
| 123 | opts.Add('MSVC_VERSION', 'Microsoft Visual C/C++ version') |
Jose Fonseca | 7c5aece | 2018-10-09 16:46:21 +0100 | [diff] [blame] | 124 | opts.Add('MSVC_USE_SCRIPT', 'Microsoft Visual C/C++ vcvarsall script', True) |