Jenkins | 18b685f | 2020-08-21 10:26:22 +0100 | [diff] [blame] | 1 | # Copyright (c) 2016, 2017 Arm Limited. |
Anthony Barbier | 871448e | 2017-03-24 14:54:29 +0000 | [diff] [blame] | 2 | # |
| 3 | # SPDX-License-Identifier: MIT |
| 4 | # |
| 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | # of this software and associated documentation files (the "Software"), to |
| 7 | # deal in the Software without restriction, including without limitation the |
| 8 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 9 | # sell copies of the Software, and to permit persons to whom the Software is |
| 10 | # furnished to do so, subject to the following conditions: |
| 11 | # |
| 12 | # The above copyright notice and this permission notice shall be included in all |
| 13 | # copies or substantial portions of the Software. |
| 14 | # |
| 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | # SOFTWARE. |
| 22 | |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 23 | import SCons |
Anthony Barbier | 46d5927 | 2017-05-04 09:15:15 +0100 | [diff] [blame] | 24 | import os |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 25 | import subprocess |
| 26 | |
| 27 | def version_at_least(version, required): |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 28 | |
Jenkins | 49b8f90 | 2020-11-27 12:49:11 +0000 | [diff] [blame] | 29 | version_list = version.split('.') |
| 30 | required_list = required.split('.') |
| 31 | end = min(len(version_list), len(required_list)) |
| 32 | for i in range(0, end): |
| 33 | if int(version_list[i]) < int(required_list[i]): |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 34 | return False |
Jenkins | 49b8f90 | 2020-11-27 12:49:11 +0000 | [diff] [blame] | 35 | elif int(version_list[i]) > int(required_list[i]): |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 36 | return True |
| 37 | |
| 38 | return True |
Anthony Barbier | 46d5927 | 2017-05-04 09:15:15 +0100 | [diff] [blame] | 39 | |
| 40 | vars = Variables("scons") |
| 41 | vars.AddVariables( |
| 42 | BoolVariable("debug", "Debug", False), |
| 43 | BoolVariable("asserts", "Enable asserts (this flag is forced to 1 for debug=1)", False), |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 44 | BoolVariable("logging", "Logging (this flag is forced to 1 for debug=1)", False), |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 45 | EnumVariable("arch", "Target Architecture", "armv7a", |
| 46 | allowed_values=("armv7a", "arm64-v8a", "arm64-v8.2-a", "arm64-v8.2-a-sve", "x86_32", "x86_64", |
Jenkins | 49b8f90 | 2020-11-27 12:49:11 +0000 | [diff] [blame] | 47 | "armv8a", "armv8.2-a", "armv8.2-a-sve", "armv8.6-a", "armv8.6-a-sve", "x86")), |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 48 | EnumVariable("estate", "Execution State", "auto", allowed_values=("auto", "32", "64")), |
Jenkins | 6a7771e | 2020-05-28 11:28:36 +0100 | [diff] [blame] | 49 | EnumVariable("os", "Target OS", "linux", allowed_values=("linux", "android", "tizen", "bare_metal")), |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 50 | EnumVariable("build", "Build type", "cross_compile", allowed_values=("native", "cross_compile", "embed_only")), |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 51 | BoolVariable("examples", "Build example programs", True), |
Jenkins | 0e205f7 | 2019-11-28 16:53:35 +0000 | [diff] [blame] | 52 | BoolVariable("gemm_tuner", "Build gemm_tuner programs", True), |
Anthony Barbier | 46d5927 | 2017-05-04 09:15:15 +0100 | [diff] [blame] | 53 | BoolVariable("Werror", "Enable/disable the -Werror compilation flag", True), |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 54 | BoolVariable("standalone", "Builds the tests as standalone executables, links statically with libgcc, libstdc++ and libarm_compute", False), |
Anthony Barbier | 46d5927 | 2017-05-04 09:15:15 +0100 | [diff] [blame] | 55 | BoolVariable("opencl", "Enable OpenCL support", True), |
| 56 | BoolVariable("neon", "Enable Neon support", False), |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 57 | BoolVariable("gles_compute", "Enable OpenGL ES Compute Shader support", False), |
Anthony Barbier | f45d5a9 | 2018-01-24 16:23:15 +0000 | [diff] [blame] | 58 | BoolVariable("embed_kernels", "Embed OpenCL kernels and OpenGL ES compute shaders in library binary", True), |
Anthony Barbier | 46d5927 | 2017-05-04 09:15:15 +0100 | [diff] [blame] | 59 | BoolVariable("set_soname", "Set the library's soname and shlibversion (requires SCons 2.4 or above)", False), |
Jenkins | 6a7771e | 2020-05-28 11:28:36 +0100 | [diff] [blame] | 60 | BoolVariable("tracing", "Enable runtime tracing", False), |
Anthony Barbier | 46d5927 | 2017-05-04 09:15:15 +0100 | [diff] [blame] | 61 | BoolVariable("openmp", "Enable OpenMP backend", False), |
| 62 | BoolVariable("cppthreads", "Enable C++11 threads backend", True), |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 63 | PathVariable("build_dir", "Specify sub-folder for the build", ".", PathVariable.PathAccept), |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame] | 64 | PathVariable("install_dir", "Specify sub-folder for the install", "", PathVariable.PathAccept), |
Jenkins | 514be65 | 2019-02-28 12:25:18 +0000 | [diff] [blame] | 65 | BoolVariable("exceptions", "Enable/disable C++ exception support", True), |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 66 | PathVariable("linker_script", "Use an external linker script", "", PathVariable.PathAccept), |
Jenkins | 49b8f90 | 2020-11-27 12:49:11 +0000 | [diff] [blame] | 67 | ListVariable("custom_options", "Custom options that can be used to turn on/off features", "none", ["disable_mmla_fp"]), |
| 68 | ListVariable("data_type_support", "Enable a list of data types to support", "all", ["qasymm8", "qasymm8_signed", "qsymm16", "fp16", "fp32"]), |
Jenkins | 514be65 | 2019-02-28 12:25:18 +0000 | [diff] [blame] | 69 | ("toolchain_prefix", "Override the toolchain prefix", ""), |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 70 | ("compiler_prefix", "Override the compiler prefix", ""), |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 71 | ("extra_cxx_flags", "Extra CXX flags to be appended to the build command", ""), |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame] | 72 | ("extra_link_flags", "Extra LD flags to be appended to the build command", ""), |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 73 | ("compiler_cache", "Command to prefix to the C and C++ compiler (e.g ccache)", "") |
Anthony Barbier | 46d5927 | 2017-05-04 09:15:15 +0100 | [diff] [blame] | 74 | ) |
| 75 | |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 76 | env = Environment(platform="posix", variables=vars, ENV = os.environ) |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame] | 77 | build_path = env['build_dir'] |
| 78 | # If build_dir is a relative path then add a #build/ prefix: |
| 79 | if not env['build_dir'].startswith('/'): |
| 80 | SConsignFile('build/%s/.scons' % build_path) |
| 81 | build_path = "#build/%s" % build_path |
| 82 | else: |
| 83 | SConsignFile('%s/.scons' % build_path) |
| 84 | |
| 85 | install_path = env['install_dir'] |
| 86 | #If the install_dir is a relative path then assume it's from inside build_dir |
| 87 | if not env['install_dir'].startswith('/') and install_path != "": |
| 88 | install_path = "%s/%s" % (build_path, install_path) |
| 89 | |
| 90 | env.Append(LIBPATH = [build_path]) |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 91 | Export('env') |
| 92 | Export('vars') |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 93 | |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame] | 94 | def install_lib( lib ): |
| 95 | # If there is no install folder, then there is nothing to do: |
| 96 | if install_path == "": |
| 97 | return lib |
| 98 | return env.Install( "%s/lib/" % install_path, lib) |
| 99 | def install_bin( bin ): |
| 100 | # If there is no install folder, then there is nothing to do: |
| 101 | if install_path == "": |
| 102 | return bin |
| 103 | return env.Install( "%s/bin/" % install_path, bin) |
| 104 | def install_include( inc ): |
| 105 | if install_path == "": |
| 106 | return inc |
| 107 | return env.Install( "%s/include/" % install_path, inc) |
| 108 | |
| 109 | Export('install_lib') |
| 110 | Export('install_bin') |
Anthony Barbier | 46d5927 | 2017-05-04 09:15:15 +0100 | [diff] [blame] | 111 | |
| 112 | Help(vars.GenerateHelpText(env)) |
| 113 | |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 114 | if env['linker_script'] and env['os'] != 'bare_metal': |
| 115 | print("Linker script is only supported for bare_metal builds") |
| 116 | Exit(1) |
| 117 | |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 118 | if env['build'] == "embed_only": |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame] | 119 | SConscript('./SConscript', variant_dir=build_path, duplicate=0) |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 120 | Return() |
| 121 | |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 122 | if env['neon'] and 'x86' in env['arch']: |
ggardet | e2542c9 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 123 | print("Cannot compile NEON for x86") |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 124 | Exit(1) |
| 125 | |
| 126 | if env['set_soname'] and not version_at_least(SCons.__version__, "2.4"): |
ggardet | e2542c9 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 127 | print("Setting the library's SONAME / SHLIBVERSION requires SCons 2.4 or above") |
| 128 | print("Update your version of SCons or use set_soname=0") |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 129 | Exit(1) |
| 130 | |
| 131 | if env['os'] == 'bare_metal': |
| 132 | if env['cppthreads'] or env['openmp']: |
| 133 | print("ERROR: OpenMP and C++11 threads not supported in bare_metal. Use cppthreads=0 openmp=0") |
| 134 | Exit(1) |
| 135 | |
Jenkins | 514be65 | 2019-02-28 12:25:18 +0000 | [diff] [blame] | 136 | if not env['exceptions']: |
| 137 | if env['opencl'] or env['gles_compute']: |
| 138 | print("ERROR: OpenCL and GLES are not supported when building without exceptions. Use opencl=0 gles_compute=0") |
| 139 | Exit(1) |
| 140 | |
| 141 | env.Append(CPPDEFINES = ['ARM_COMPUTE_EXCEPTIONS_DISABLED']) |
| 142 | env.Append(CXXFLAGS = ['-fno-exceptions']) |
| 143 | |
Jenkins | 0e205f7 | 2019-11-28 16:53:35 +0000 | [diff] [blame] | 144 | env.Append(CXXFLAGS = ['-Wall','-DARCH_ARM', |
| 145 | '-Wextra','-pedantic','-Wdisabled-optimization','-Wformat=2', |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 146 | '-Winit-self','-Wstrict-overflow=2','-Wswitch-default', |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 147 | '-std=gnu++11','-Woverloaded-virtual', '-Wformat-security', |
Jenkins | 0e205f7 | 2019-11-28 16:53:35 +0000 | [diff] [blame] | 148 | '-Wctor-dtor-privacy','-Wsign-promo','-Weffc++','-Wno-overlength-strings']) |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 149 | |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 150 | env.Append(CPPDEFINES = ['_GLIBCXX_USE_NANOSLEEP']) |
| 151 | |
Anthony Barbier | f45d5a9 | 2018-01-24 16:23:15 +0000 | [diff] [blame] | 152 | default_cpp_compiler = 'g++' if env['os'] != 'android' else 'clang++' |
| 153 | default_c_compiler = 'gcc' if env['os'] != 'android' else 'clang' |
| 154 | cpp_compiler = os.environ.get('CXX', default_cpp_compiler) |
| 155 | c_compiler = os.environ.get('CC', default_c_compiler) |
| 156 | |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 157 | if env['os'] == 'android' and ( 'clang++' not in cpp_compiler or 'clang' not in c_compiler ): |
ggardet | e2542c9 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 158 | print( "WARNING: Only clang is officially supported to build the Compute Library for Android") |
Anthony Barbier | f45d5a9 | 2018-01-24 16:23:15 +0000 | [diff] [blame] | 159 | |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 160 | if 'clang++' in cpp_compiler: |
Jenkins | 0e205f7 | 2019-11-28 16:53:35 +0000 | [diff] [blame] | 161 | env.Append(CXXFLAGS = ['-Wno-vla-extension']) |
| 162 | elif 'armclang' in cpp_compiler: |
| 163 | pass |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 164 | else: |
Jenkins | 0e205f7 | 2019-11-28 16:53:35 +0000 | [diff] [blame] | 165 | env.Append(CXXFLAGS = ['-Wlogical-op','-Wnoexcept','-Wstrict-null-sentinel']) |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 166 | |
| 167 | if env['cppthreads']: |
| 168 | env.Append(CPPDEFINES = [('ARM_COMPUTE_CPP_SCHEDULER', 1)]) |
| 169 | |
| 170 | if env['openmp']: |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 171 | if 'clang++' in cpp_compiler: |
ggardet | e2542c9 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 172 | print( "Clang does not support OpenMP. Use scheduler=cpp.") |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 173 | Exit(1) |
| 174 | |
| 175 | env.Append(CPPDEFINES = [('ARM_COMPUTE_OPENMP_SCHEDULER', 1)]) |
| 176 | env.Append(CXXFLAGS = ['-fopenmp']) |
| 177 | env.Append(LINKFLAGS = ['-fopenmp']) |
| 178 | |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 179 | # Validate and define state |
| 180 | if env['estate'] == 'auto': |
| 181 | if 'v7a' in env['arch']: |
| 182 | env['estate'] = '32' |
| 183 | else: |
| 184 | env['estate'] = '64' |
| 185 | |
| 186 | # Map legacy arch |
| 187 | if 'arm64' in env['arch']: |
| 188 | env['estate'] = '64' |
| 189 | |
| 190 | if 'v7a' in env['estate'] and env['estate'] == '64': |
| 191 | print("ERROR: armv7a architecture has only 32-bit execution state") |
| 192 | Exit(1) |
| 193 | |
Jenkins | 0e205f7 | 2019-11-28 16:53:35 +0000 | [diff] [blame] | 194 | # Add architecture specific flags |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 195 | prefix = "" |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 196 | if 'v7a' in env['arch']: |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 197 | env.Append(CXXFLAGS = ['-march=armv7-a', '-mthumb', '-mfpu=neon']) |
Jenkins | 6a7771e | 2020-05-28 11:28:36 +0100 | [diff] [blame] | 198 | if env['os'] == 'android' or env['os'] == 'tizen': |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 199 | env.Append(CXXFLAGS = ['-mfloat-abi=softfp']) |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame] | 200 | else: |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 201 | env.Append(CXXFLAGS = ['-mfloat-abi=hard']) |
| 202 | elif 'v8' in env['arch']: |
| 203 | if 'sve' in env['arch']: |
| 204 | env.Append(CXXFLAGS = ['-march=armv8.2-a+sve+fp16+dotprod']) |
| 205 | elif 'v8.2-a' in env['arch']: |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame] | 206 | env.Append(CXXFLAGS = ['-march=armv8.2-a+fp16']) # explicitly enable fp16 extension otherwise __ARM_FEATURE_FP16_VECTOR_ARITHMETIC is undefined |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 207 | else: |
| 208 | env.Append(CXXFLAGS = ['-march=armv8-a']) |
| 209 | |
| 210 | if 'v8.6-a' in env['arch']: |
Jenkins | 49b8f90 | 2020-11-27 12:49:11 +0000 | [diff] [blame] | 211 | env.Append(CPPDEFINES = ['MMLA_INT8', 'V8P6', 'V8P6_BF', 'ARM_COMPUTE_FORCE_BF16']) |
| 212 | if "disable_mmla_fp" not in env['custom_options']: |
| 213 | env.Append(CPPDEFINES = ['MMLA_FP32']) |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 214 | |
| 215 | elif 'x86' in env['arch']: |
| 216 | if env['estate'] == '32': |
| 217 | env.Append(CCFLAGS = ['-m32']) |
| 218 | env.Append(LINKFLAGS = ['-m32']) |
| 219 | else: |
| 220 | env.Append(CXXFLAGS = ['-fPIC']) |
| 221 | env.Append(CCFLAGS = ['-m64']) |
| 222 | env.Append(LINKFLAGS = ['-m64']) |
| 223 | |
| 224 | # Define toolchain |
| 225 | prefix = "" |
| 226 | if 'x86' not in env['arch']: |
| 227 | if env['estate'] == '32': |
| 228 | if env['os'] == 'linux': |
| 229 | prefix = "arm-linux-gnueabihf-" if 'v7' in env['arch'] else "armv8l-linux-gnueabihf-" |
| 230 | elif env['os'] == 'bare_metal': |
| 231 | prefix = "arm-eabi-" |
| 232 | elif env['os'] == 'android': |
| 233 | prefix = "arm-linux-androideabi-" |
Jenkins | 6a7771e | 2020-05-28 11:28:36 +0100 | [diff] [blame] | 234 | elif env['os'] == 'tizen': |
| 235 | prefix = "armv7l-tizen-linux-gnueabi-" |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 236 | elif env['estate'] == '64' and 'v8' in env['arch']: |
| 237 | if env['os'] == 'linux': |
| 238 | prefix = "aarch64-linux-gnu-" |
| 239 | elif env['os'] == 'bare_metal': |
| 240 | prefix = "aarch64-elf-" |
| 241 | elif env['os'] == 'android': |
| 242 | prefix = "aarch64-linux-android-" |
Jenkins | 6a7771e | 2020-05-28 11:28:36 +0100 | [diff] [blame] | 243 | elif env['os'] == 'tizen': |
| 244 | prefix = "aarch64-tizen-linux-gnu-" |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 245 | |
| 246 | if env['build'] == 'native': |
| 247 | prefix = "" |
| 248 | |
Jenkins | 514be65 | 2019-02-28 12:25:18 +0000 | [diff] [blame] | 249 | if env["toolchain_prefix"] != "": |
| 250 | prefix = env["toolchain_prefix"] |
| 251 | |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 252 | compiler_prefix = prefix |
| 253 | if env["compiler_prefix"] != "": |
| 254 | compiler_prefix = env["compiler_prefix"] |
| 255 | |
| 256 | env['CC'] = env['compiler_cache']+ " " + compiler_prefix + c_compiler |
| 257 | env['CXX'] = env['compiler_cache']+ " " + compiler_prefix + cpp_compiler |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 258 | env['LD'] = prefix + "ld" |
| 259 | env['AS'] = prefix + "as" |
| 260 | env['AR'] = prefix + "ar" |
| 261 | env['RANLIB'] = prefix + "ranlib" |
Anthony Barbier | 46d5927 | 2017-05-04 09:15:15 +0100 | [diff] [blame] | 262 | |
| 263 | if not GetOption("help"): |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 264 | try: |
Jenkins | 49b8f90 | 2020-11-27 12:49:11 +0000 | [diff] [blame] | 265 | compiler_ver = subprocess.check_output(env['CXX'].split() + ["-dumpversion"]).decode().strip() |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 266 | except OSError: |
| 267 | print("ERROR: Compiler '%s' not found" % env['CXX']) |
| 268 | Exit(1) |
| 269 | |
Jenkins | 0e205f7 | 2019-11-28 16:53:35 +0000 | [diff] [blame] | 270 | if 'armclang' in cpp_compiler: |
| 271 | pass |
| 272 | elif 'clang++' not in cpp_compiler: |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 273 | if env['arch'] == 'arm64-v8.2-a' and not version_at_least(compiler_ver, '6.2.1'): |
ggardet | e2542c9 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 274 | print("GCC 6.2.1 or newer is required to compile armv8.2-a code") |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 275 | Exit(1) |
| 276 | elif env['arch'] == 'arm64-v8a' and not version_at_least(compiler_ver, '4.9'): |
ggardet | e2542c9 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 277 | print("GCC 4.9 or newer is required to compile NEON code for AArch64") |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 278 | Exit(1) |
| 279 | |
| 280 | if version_at_least(compiler_ver, '6.1'): |
| 281 | env.Append(CXXFLAGS = ['-Wno-ignored-attributes']) |
| 282 | |
| 283 | if compiler_ver == '4.8.3': |
| 284 | env.Append(CXXFLAGS = ['-Wno-array-bounds']) |
| 285 | |
Jenkins | 49b8f90 | 2020-11-27 12:49:11 +0000 | [diff] [blame] | 286 | if not version_at_least(compiler_ver, '7.0.0') and env['os'] == 'bare_metal': |
| 287 | env.Append(LINKFLAGS = ['-fstack-protector-strong']) |
| 288 | |
| 289 | if env['data_type_support']: |
| 290 | if any(i in env['data_type_support'] for i in ['all', 'fp16']): |
| 291 | env.Append(CXXFLAGS = ['-DENABLE_FP16_KERNELS']) |
| 292 | if any(i in env['data_type_support'] for i in ['all', 'fp32']): |
| 293 | env.Append(CXXFLAGS = ['-DENABLE_FP32_KERNELS']) |
| 294 | if any(i in env['data_type_support'] for i in ['all', 'qasymm8']): |
| 295 | env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_KERNELS']) |
| 296 | if any(i in env['data_type_support'] for i in ['all', 'qasymm8_signed']): |
| 297 | env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_SIGNED_KERNELS']) |
| 298 | if any(i in env['data_type_support'] for i in ['all', 'qsymm16']): |
| 299 | env.Append(CXXFLAGS = ['-DENABLE_QSYMM16_KERNELS']) |
| 300 | |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 301 | if env['standalone']: |
| 302 | env.Append(CXXFLAGS = ['-fPIC']) |
| 303 | env.Append(LINKFLAGS = ['-static-libgcc','-static-libstdc++']) |
| 304 | |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 305 | if env['Werror']: |
| 306 | env.Append(CXXFLAGS = ['-Werror']) |
| 307 | |
| 308 | if env['os'] == 'android': |
| 309 | env.Append(CPPDEFINES = ['ANDROID']) |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 310 | env.Append(LINKFLAGS = ['-pie', '-static-libstdc++', '-ldl']) |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 311 | elif env['os'] == 'bare_metal': |
| 312 | env.Append(LINKFLAGS = ['-static']) |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 313 | env.Append(LINKFLAGS = ['-specs=rdimon.specs']) |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 314 | env.Append(CXXFLAGS = ['-fPIC']) |
| 315 | env.Append(CPPDEFINES = ['NO_MULTI_THREADING']) |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 316 | env.Append(CPPDEFINES = ['BARE_METAL']) |
Jenkins | 49b8f90 | 2020-11-27 12:49:11 +0000 | [diff] [blame] | 317 | if env['os'] == 'linux' and env['arch'] == 'armv7a': |
| 318 | env.Append(CXXFLAGS = [ '-Wno-psabi' ]) |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 319 | |
| 320 | if env['opencl']: |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 321 | if env['os'] in ['bare_metal'] or env['standalone']: |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 322 | print("Cannot link OpenCL statically, which is required for bare metal / standalone builds") |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 323 | Exit(1) |
| 324 | |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 325 | if env['gles_compute']: |
| 326 | if env['os'] in ['bare_metal'] or env['standalone']: |
| 327 | print("Cannot link OpenGLES statically, which is required for bare metal / standalone builds") |
| 328 | Exit(1) |
| 329 | |
| 330 | if env["os"] not in ["android", "bare_metal"] and (env['opencl'] or env['cppthreads']): |
| 331 | env.Append(LIBS = ['pthread']) |
| 332 | |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 333 | if env['opencl'] or env['gles_compute']: |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 334 | if env['embed_kernels']: |
| 335 | env.Append(CPPDEFINES = ['EMBEDDED_KERNELS']) |
| 336 | |
| 337 | if env['debug']: |
| 338 | env['asserts'] = True |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 339 | env['logging'] = True |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 340 | env.Append(CXXFLAGS = ['-O0','-g','-gdwarf-2']) |
| 341 | env.Append(CPPDEFINES = ['ARM_COMPUTE_DEBUG_ENABLED']) |
| 342 | else: |
Jenkins | 975dfe1 | 2019-09-02 11:47:54 +0100 | [diff] [blame] | 343 | env.Append(CXXFLAGS = ['-O3']) |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 344 | |
| 345 | if env['asserts']: |
| 346 | env.Append(CPPDEFINES = ['ARM_COMPUTE_ASSERTS_ENABLED']) |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 347 | env.Append(CXXFLAGS = ['-fstack-protector-strong']) |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 348 | |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 349 | if env['logging']: |
| 350 | env.Append(CPPDEFINES = ['ARM_COMPUTE_LOGGING_ENABLED']) |
| 351 | |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 352 | env.Append(CPPPATH = ['#/include', "#"]) |
| 353 | env.Append(CXXFLAGS = env['extra_cxx_flags']) |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame] | 354 | env.Append(LINKFLAGS = env['extra_link_flags']) |
| 355 | |
| 356 | Default( install_include("arm_compute")) |
| 357 | Default( install_include("support")) |
Jenkins | 4ba87db | 2019-05-23 17:11:51 +0100 | [diff] [blame] | 358 | Default( install_include("utils")) |
| 359 | for dirname in os.listdir("./include"): |
| 360 | Default( install_include("include/%s" % dirname)) |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 361 | |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 362 | Export('version_at_least') |
| 363 | |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 364 | if env['gles_compute'] and env['os'] != 'android': |
| 365 | env.Append(CPPPATH = ['#/include/linux']) |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 366 | |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame] | 367 | SConscript('./SConscript', variant_dir=build_path, duplicate=0) |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 368 | |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 369 | if env['examples'] and env['exceptions']: |
| 370 | if env['os'] == 'bare_metal' and env['arch'] == 'armv7a': |
| 371 | print("WARNING: Building examples for bare metal and armv7a is not supported. Use examples=0") |
| 372 | Return() |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame] | 373 | SConscript('./examples/SConscript', variant_dir='%s/examples' % build_path, duplicate=0) |
Anthony Barbier | dbdab85 | 2017-06-23 15:42:00 +0100 | [diff] [blame] | 374 | |
Jenkins | 36ccc90 | 2020-02-21 11:10:48 +0000 | [diff] [blame] | 375 | if env['exceptions']: |
| 376 | if env['os'] == 'bare_metal' and env['arch'] == 'armv7a': |
| 377 | print("WARNING: Building tests for bare metal and armv7a is not supported") |
| 378 | Return() |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame] | 379 | SConscript('./tests/SConscript', variant_dir='%s/tests' % build_path, duplicate=0) |