Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 1 | # Copyright (c) 2016, 2017 Arm Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [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 | |
| 23 | import SCons |
| 24 | import os |
| 25 | import subprocess |
| 26 | |
| 27 | def version_at_least(version, required): |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 28 | |
Michalis Spyrou | cfac305 | 2020-10-14 12:06:28 +0100 | [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 | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 34 | return False |
Michalis Spyrou | cfac305 | 2020-10-14 12:06:28 +0100 | [diff] [blame] | 35 | elif int(version_list[i]) > int(required_list[i]): |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 36 | return True |
| 37 | |
| 38 | return True |
| 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), |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 44 | BoolVariable("logging", "Logging (this flag is forced to 1 for debug=1)", False), |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 45 | EnumVariable("arch", "Target Architecture", "armv7a", |
Georgios Pinitas | 94672fb | 2020-01-22 18:36:27 +0000 | [diff] [blame] | 46 | allowed_values=("armv7a", "arm64-v8a", "arm64-v8.2-a", "arm64-v8.2-a-sve", "x86_32", "x86_64", |
Georgios Pinitas | 49c6ced | 2020-09-21 17:16:09 +0100 | [diff] [blame] | 47 | "armv8a", "armv8.2-a", "armv8.2-a-sve", "armv8.6-a", "armv8.6-a-sve", "x86")), |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 48 | EnumVariable("estate", "Execution State", "auto", allowed_values=("auto", "32", "64")), |
Inki Dae | 51a9558 | 2020-03-23 08:29:02 +0900 | [diff] [blame] | 49 | EnumVariable("os", "Target OS", "linux", allowed_values=("linux", "android", "tizen", "bare_metal")), |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 50 | EnumVariable("build", "Build type", "cross_compile", allowed_values=("native", "cross_compile", "embed_only")), |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 51 | BoolVariable("examples", "Build example programs", True), |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 52 | BoolVariable("gemm_tuner", "Build gemm_tuner programs", True), |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 53 | BoolVariable("Werror", "Enable/disable the -Werror compilation flag", True), |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 54 | BoolVariable("standalone", "Builds the tests as standalone executables, links statically with libgcc, libstdc++ and libarm_compute", False), |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 55 | BoolVariable("opencl", "Enable OpenCL support", True), |
| 56 | BoolVariable("neon", "Enable Neon support", False), |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 57 | BoolVariable("gles_compute", "Enable OpenGL ES Compute Shader support", False), |
Anthony Barbier | cc0a80b | 2017-12-15 11:37:29 +0000 | [diff] [blame] | 58 | BoolVariable("embed_kernels", "Embed OpenCL kernels and OpenGL ES compute shaders in library binary", True), |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 59 | BoolVariable("set_soname", "Set the library's soname and shlibversion (requires SCons 2.4 or above)", False), |
Anthony Barbier | b467021 | 2018-05-18 16:55:39 +0100 | [diff] [blame] | 60 | BoolVariable("tracing", "Enable runtime tracing", False), |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 61 | BoolVariable("openmp", "Enable OpenMP backend", False), |
| 62 | BoolVariable("cppthreads", "Enable C++11 threads backend", True), |
| 63 | PathVariable("build_dir", "Specify sub-folder for the build", ".", PathVariable.PathAccept), |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 64 | PathVariable("install_dir", "Specify sub-folder for the install", "", PathVariable.PathAccept), |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 65 | BoolVariable("exceptions", "Enable/disable C++ exception support", True), |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 66 | PathVariable("linker_script", "Use an external linker script", "", PathVariable.PathAccept), |
Anthony Barbier | a4e5e1e | 2017-10-05 14:55:34 +0100 | [diff] [blame] | 67 | #FIXME Remove before release (And remove all references to INTERNAL_ONLY) |
Georgios Pinitas | 3783116 | 2018-08-20 15:41:10 +0100 | [diff] [blame] | 68 | BoolVariable("internal_only", "Enable ARM internal only tests", False), |
Georgios Pinitas | 49c6ced | 2020-09-21 17:16:09 +0100 | [diff] [blame] | 69 | ListVariable("custom_options", "Custom options that can be used to turn on/off features", "none", ["disable_mmla_fp"]), |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 70 | ListVariable("data_type_support", "Enable a list of data types to support", "all", ["qasymm8", "qasymm8_signed", "qsymm16", "fp16", "fp32"]), |
Anthony Barbier | 149de5b | 2018-12-06 10:27:37 +0000 | [diff] [blame] | 71 | ("toolchain_prefix", "Override the toolchain prefix", ""), |
alered01 | d8872c1 | 2020-02-10 11:29:45 +0000 | [diff] [blame] | 72 | ("compiler_prefix", "Override the compiler prefix", ""), |
Anthony Barbier | 7390e05 | 2018-03-13 09:29:41 +0000 | [diff] [blame] | 73 | ("extra_cxx_flags", "Extra CXX flags to be appended to the build command", ""), |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 74 | ("extra_link_flags", "Extra LD flags to be appended to the build command", ""), |
Anthony Barbier | 7390e05 | 2018-03-13 09:29:41 +0000 | [diff] [blame] | 75 | ("compiler_cache", "Command to prefix to the C and C++ compiler (e.g ccache)", "") |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 76 | ) |
| 77 | |
| 78 | env = Environment(platform="posix", variables=vars, ENV = os.environ) |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 79 | build_path = env['build_dir'] |
| 80 | # If build_dir is a relative path then add a #build/ prefix: |
| 81 | if not env['build_dir'].startswith('/'): |
| 82 | SConsignFile('build/%s/.scons' % build_path) |
| 83 | build_path = "#build/%s" % build_path |
| 84 | else: |
| 85 | SConsignFile('%s/.scons' % build_path) |
| 86 | |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 87 | install_path = env['install_dir'] |
| 88 | #If the install_dir is a relative path then assume it's from inside build_dir |
| 89 | if not env['install_dir'].startswith('/') and install_path != "": |
| 90 | install_path = "%s/%s" % (build_path, install_path) |
| 91 | |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 92 | env.Append(LIBPATH = [build_path]) |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 93 | Export('env') |
| 94 | Export('vars') |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 95 | |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 96 | def install_lib( lib ): |
| 97 | # If there is no install folder, then there is nothing to do: |
| 98 | if install_path == "": |
| 99 | return lib |
| 100 | return env.Install( "%s/lib/" % install_path, lib) |
| 101 | def install_bin( bin ): |
| 102 | # If there is no install folder, then there is nothing to do: |
| 103 | if install_path == "": |
| 104 | return bin |
| 105 | return env.Install( "%s/bin/" % install_path, bin) |
| 106 | def install_include( inc ): |
| 107 | if install_path == "": |
| 108 | return inc |
| 109 | return env.Install( "%s/include/" % install_path, inc) |
| 110 | |
| 111 | Export('install_lib') |
| 112 | Export('install_bin') |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 113 | |
| 114 | Help(vars.GenerateHelpText(env)) |
| 115 | |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 116 | if env['linker_script'] and env['os'] != 'bare_metal': |
| 117 | print("Linker script is only supported for bare_metal builds") |
| 118 | Exit(1) |
| 119 | |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 120 | if env['build'] == "embed_only": |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 121 | SConscript('./SConscript', variant_dir=build_path, duplicate=0) |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 122 | Return() |
| 123 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 124 | if env['neon'] and 'x86' in env['arch']: |
ggardet | 767c9f7 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 125 | print("Cannot compile NEON for x86") |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 126 | Exit(1) |
| 127 | |
| 128 | if env['set_soname'] and not version_at_least(SCons.__version__, "2.4"): |
ggardet | 767c9f7 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 129 | print("Setting the library's SONAME / SHLIBVERSION requires SCons 2.4 or above") |
| 130 | print("Update your version of SCons or use set_soname=0") |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 131 | Exit(1) |
| 132 | |
| 133 | if env['os'] == 'bare_metal': |
| 134 | if env['cppthreads'] or env['openmp']: |
| 135 | print("ERROR: OpenMP and C++11 threads not supported in bare_metal. Use cppthreads=0 openmp=0") |
| 136 | Exit(1) |
| 137 | |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 138 | if not env['exceptions']: |
| 139 | if env['opencl'] or env['gles_compute']: |
| 140 | print("ERROR: OpenCL and GLES are not supported when building without exceptions. Use opencl=0 gles_compute=0") |
| 141 | Exit(1) |
| 142 | |
| 143 | env.Append(CPPDEFINES = ['ARM_COMPUTE_EXCEPTIONS_DISABLED']) |
| 144 | env.Append(CXXFLAGS = ['-fno-exceptions']) |
| 145 | |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 146 | env.Append(CXXFLAGS = ['-Wall','-DARCH_ARM', |
Michalis Spyrou | 7c60c99 | 2019-10-10 14:33:47 +0100 | [diff] [blame] | 147 | '-Wextra','-pedantic','-Wdisabled-optimization','-Wformat=2', |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 148 | '-Winit-self','-Wstrict-overflow=2','-Wswitch-default', |
Michalis Spyrou | 2d22c3f | 2020-02-12 14:50:19 +0000 | [diff] [blame] | 149 | '-std=gnu++11','-Woverloaded-virtual', '-Wformat-security', |
Michalis Spyrou | fae513c | 2019-10-16 17:41:33 +0100 | [diff] [blame] | 150 | '-Wctor-dtor-privacy','-Wsign-promo','-Weffc++','-Wno-overlength-strings']) |
Isabella Gottardi | b28f29d | 2017-11-09 17:05:07 +0000 | [diff] [blame] | 151 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 152 | env.Append(CPPDEFINES = ['_GLIBCXX_USE_NANOSLEEP']) |
| 153 | |
Anthony Barbier | a026e98 | 2018-01-18 10:57:52 +0000 | [diff] [blame] | 154 | default_cpp_compiler = 'g++' if env['os'] != 'android' else 'clang++' |
| 155 | default_c_compiler = 'gcc' if env['os'] != 'android' else 'clang' |
| 156 | cpp_compiler = os.environ.get('CXX', default_cpp_compiler) |
| 157 | c_compiler = os.environ.get('CC', default_c_compiler) |
| 158 | |
Anthony Barbier | dd66937 | 2018-03-01 17:08:54 +0000 | [diff] [blame] | 159 | if env['os'] == 'android' and ( 'clang++' not in cpp_compiler or 'clang' not in c_compiler ): |
ggardet | 767c9f7 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 160 | print( "WARNING: Only clang is officially supported to build the Compute Library for Android") |
Anthony Barbier | a026e98 | 2018-01-18 10:57:52 +0000 | [diff] [blame] | 161 | |
Anthony Barbier | dd66937 | 2018-03-01 17:08:54 +0000 | [diff] [blame] | 162 | if 'clang++' in cpp_compiler: |
Michalis Spyrou | 7c60c99 | 2019-10-10 14:33:47 +0100 | [diff] [blame] | 163 | env.Append(CXXFLAGS = ['-Wno-vla-extension']) |
Georgios Pinitas | e874ef9 | 2019-09-09 17:40:33 +0100 | [diff] [blame] | 164 | elif 'armclang' in cpp_compiler: |
| 165 | pass |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 166 | else: |
Michalis Spyrou | 7c60c99 | 2019-10-10 14:33:47 +0100 | [diff] [blame] | 167 | env.Append(CXXFLAGS = ['-Wlogical-op','-Wnoexcept','-Wstrict-null-sentinel']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 168 | |
| 169 | if env['cppthreads']: |
| 170 | env.Append(CPPDEFINES = [('ARM_COMPUTE_CPP_SCHEDULER', 1)]) |
| 171 | |
| 172 | if env['openmp']: |
Anthony Barbier | dd66937 | 2018-03-01 17:08:54 +0000 | [diff] [blame] | 173 | if 'clang++' in cpp_compiler: |
ggardet | 767c9f7 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 174 | print( "Clang does not support OpenMP. Use scheduler=cpp.") |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 175 | Exit(1) |
| 176 | |
| 177 | env.Append(CPPDEFINES = [('ARM_COMPUTE_OPENMP_SCHEDULER', 1)]) |
| 178 | env.Append(CXXFLAGS = ['-fopenmp']) |
| 179 | env.Append(LINKFLAGS = ['-fopenmp']) |
| 180 | |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 181 | # Validate and define state |
| 182 | if env['estate'] == 'auto': |
| 183 | if 'v7a' in env['arch']: |
| 184 | env['estate'] = '32' |
| 185 | else: |
| 186 | env['estate'] = '64' |
| 187 | |
| 188 | # Map legacy arch |
| 189 | if 'arm64' in env['arch']: |
| 190 | env['estate'] = '64' |
| 191 | |
| 192 | if 'v7a' in env['estate'] and env['estate'] == '64': |
| 193 | print("ERROR: armv7a architecture has only 32-bit execution state") |
| 194 | Exit(1) |
| 195 | |
Georgios Pinitas | e874ef9 | 2019-09-09 17:40:33 +0100 | [diff] [blame] | 196 | # Add architecture specific flags |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 197 | prefix = "" |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 198 | if 'v7a' in env['arch']: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 199 | env.Append(CXXFLAGS = ['-march=armv7-a', '-mthumb', '-mfpu=neon']) |
Inki Dae | 51a9558 | 2020-03-23 08:29:02 +0900 | [diff] [blame] | 200 | if env['os'] == 'android' or env['os'] == 'tizen': |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 201 | env.Append(CXXFLAGS = ['-mfloat-abi=softfp']) |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 202 | else: |
| 203 | env.Append(CXXFLAGS = ['-mfloat-abi=hard']) |
Georgios Pinitas | 94672fb | 2020-01-22 18:36:27 +0000 | [diff] [blame] | 204 | elif 'v8' in env['arch']: |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 205 | if 'sve' in env['arch']: |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 206 | env.Append(CXXFLAGS = ['-march=armv8.2-a+sve+fp16+dotprod']) |
Georgios Pinitas | 94672fb | 2020-01-22 18:36:27 +0000 | [diff] [blame] | 207 | elif 'v8.2-a' in env['arch']: |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 208 | env.Append(CXXFLAGS = ['-march=armv8.2-a+fp16']) # explicitly enable fp16 extension otherwise __ARM_FEATURE_FP16_VECTOR_ARITHMETIC is undefined |
Georgios Pinitas | 94672fb | 2020-01-22 18:36:27 +0000 | [diff] [blame] | 209 | else: |
| 210 | env.Append(CXXFLAGS = ['-march=armv8-a']) |
| 211 | |
| 212 | if 'v8.6-a' in env['arch']: |
Georgios Pinitas | 49c6ced | 2020-09-21 17:16:09 +0100 | [diff] [blame] | 213 | env.Append(CPPDEFINES = ['MMLA_INT8', 'V8P6', 'V8P6_BF', 'ARM_COMPUTE_FORCE_BF16']) |
| 214 | if "disable_mmla_fp" not in env['custom_options']: |
| 215 | env.Append(CPPDEFINES = ['MMLA_FP32']) |
Georgios Pinitas | 94672fb | 2020-01-22 18:36:27 +0000 | [diff] [blame] | 216 | |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 217 | elif 'x86' in env['arch']: |
| 218 | if env['estate'] == '32': |
| 219 | env.Append(CCFLAGS = ['-m32']) |
| 220 | env.Append(LINKFLAGS = ['-m32']) |
| 221 | else: |
| 222 | env.Append(CXXFLAGS = ['-fPIC']) |
| 223 | env.Append(CCFLAGS = ['-m64']) |
| 224 | env.Append(LINKFLAGS = ['-m64']) |
| 225 | |
| 226 | # Define toolchain |
| 227 | prefix = "" |
| 228 | if 'x86' not in env['arch']: |
| 229 | if env['estate'] == '32': |
| 230 | if env['os'] == 'linux': |
| 231 | prefix = "arm-linux-gnueabihf-" if 'v7' in env['arch'] else "armv8l-linux-gnueabihf-" |
| 232 | elif env['os'] == 'bare_metal': |
| 233 | prefix = "arm-eabi-" |
| 234 | elif env['os'] == 'android': |
| 235 | prefix = "arm-linux-androideabi-" |
Inki Dae | 51a9558 | 2020-03-23 08:29:02 +0900 | [diff] [blame] | 236 | elif env['os'] == 'tizen': |
| 237 | prefix = "armv7l-tizen-linux-gnueabi-" |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 238 | elif env['estate'] == '64' and 'v8' in env['arch']: |
| 239 | if env['os'] == 'linux': |
| 240 | prefix = "aarch64-linux-gnu-" |
| 241 | elif env['os'] == 'bare_metal': |
| 242 | prefix = "aarch64-elf-" |
| 243 | elif env['os'] == 'android': |
| 244 | prefix = "aarch64-linux-android-" |
Inki Dae | 51a9558 | 2020-03-23 08:29:02 +0900 | [diff] [blame] | 245 | elif env['os'] == 'tizen': |
| 246 | prefix = "aarch64-tizen-linux-gnu-" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 247 | |
| 248 | if env['build'] == 'native': |
| 249 | prefix = "" |
| 250 | |
Anthony Barbier | 149de5b | 2018-12-06 10:27:37 +0000 | [diff] [blame] | 251 | if env["toolchain_prefix"] != "": |
| 252 | prefix = env["toolchain_prefix"] |
| 253 | |
alered01 | d8872c1 | 2020-02-10 11:29:45 +0000 | [diff] [blame] | 254 | compiler_prefix = prefix |
| 255 | if env["compiler_prefix"] != "": |
| 256 | compiler_prefix = env["compiler_prefix"] |
| 257 | |
| 258 | env['CC'] = env['compiler_cache']+ " " + compiler_prefix + c_compiler |
| 259 | env['CXX'] = env['compiler_cache']+ " " + compiler_prefix + cpp_compiler |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 260 | env['LD'] = prefix + "ld" |
| 261 | env['AS'] = prefix + "as" |
| 262 | env['AR'] = prefix + "ar" |
| 263 | env['RANLIB'] = prefix + "ranlib" |
| 264 | |
| 265 | if not GetOption("help"): |
| 266 | try: |
SiCong Li | 3b9a564 | 2020-10-16 12:10:15 +0100 | [diff] [blame] | 267 | compiler_ver = subprocess.check_output(env['CXX'].split() + ["-dumpversion"]).decode().strip() |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 268 | except OSError: |
| 269 | print("ERROR: Compiler '%s' not found" % env['CXX']) |
| 270 | Exit(1) |
| 271 | |
Georgios Pinitas | e874ef9 | 2019-09-09 17:40:33 +0100 | [diff] [blame] | 272 | if 'armclang' in cpp_compiler: |
| 273 | pass |
| 274 | elif 'clang++' not in cpp_compiler: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 275 | if env['arch'] == 'arm64-v8.2-a' and not version_at_least(compiler_ver, '6.2.1'): |
ggardet | 767c9f7 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 276 | print("GCC 6.2.1 or newer is required to compile armv8.2-a code") |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 277 | Exit(1) |
| 278 | elif env['arch'] == 'arm64-v8a' and not version_at_least(compiler_ver, '4.9'): |
ggardet | 767c9f7 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 279 | print("GCC 4.9 or newer is required to compile NEON code for AArch64") |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 280 | Exit(1) |
| 281 | |
| 282 | if version_at_least(compiler_ver, '6.1'): |
| 283 | env.Append(CXXFLAGS = ['-Wno-ignored-attributes']) |
| 284 | |
| 285 | if compiler_ver == '4.8.3': |
| 286 | env.Append(CXXFLAGS = ['-Wno-array-bounds']) |
| 287 | |
Michalis Spyrou | cfac305 | 2020-10-14 12:06:28 +0100 | [diff] [blame] | 288 | if not version_at_least(compiler_ver, '7.0.0') and env['os'] == 'bare_metal': |
| 289 | env.Append(LINKFLAGS = ['-fstack-protector-strong']) |
| 290 | |
Georgios Pinitas | ff4fca0 | 2020-10-02 21:00:00 +0100 | [diff] [blame] | 291 | if env['data_type_support']: |
| 292 | if any(i in env['data_type_support'] for i in ['all', 'fp16']): |
| 293 | env.Append(CXXFLAGS = ['-DENABLE_FP16_KERNELS']) |
| 294 | if any(i in env['data_type_support'] for i in ['all', 'fp32']): |
| 295 | env.Append(CXXFLAGS = ['-DENABLE_FP32_KERNELS']) |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 296 | if any(i in env['data_type_support'] for i in ['all', 'qasymm8']): |
| 297 | env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_KERNELS']) |
| 298 | if any(i in env['data_type_support'] for i in ['all', 'qasymm8_signed']): |
| 299 | env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_SIGNED_KERNELS']) |
| 300 | if any(i in env['data_type_support'] for i in ['all', 'qsymm16']): |
| 301 | env.Append(CXXFLAGS = ['-DENABLE_QSYMM16_KERNELS']) |
Georgios Pinitas | ff4fca0 | 2020-10-02 21:00:00 +0100 | [diff] [blame] | 302 | |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 303 | if env['standalone']: |
| 304 | env.Append(CXXFLAGS = ['-fPIC']) |
Anthony Barbier | 665c89b | 2018-07-16 11:40:09 +0100 | [diff] [blame] | 305 | env.Append(LINKFLAGS = ['-static-libgcc','-static-libstdc++']) |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 306 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 307 | if env['Werror']: |
| 308 | env.Append(CXXFLAGS = ['-Werror']) |
| 309 | |
| 310 | if env['os'] == 'android': |
| 311 | env.Append(CPPDEFINES = ['ANDROID']) |
Michalis Spyrou | 2d22c3f | 2020-02-12 14:50:19 +0000 | [diff] [blame] | 312 | env.Append(LINKFLAGS = ['-pie', '-static-libstdc++', '-ldl']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 313 | elif env['os'] == 'bare_metal': |
| 314 | env.Append(LINKFLAGS = ['-static']) |
Michalis Spyrou | 07781ac | 2017-08-31 15:11:41 +0100 | [diff] [blame] | 315 | env.Append(LINKFLAGS = ['-specs=rdimon.specs']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 316 | env.Append(CXXFLAGS = ['-fPIC']) |
| 317 | env.Append(CPPDEFINES = ['NO_MULTI_THREADING']) |
Michalis Spyrou | 07781ac | 2017-08-31 15:11:41 +0100 | [diff] [blame] | 318 | env.Append(CPPDEFINES = ['BARE_METAL']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 319 | |
| 320 | if env['opencl']: |
Georgios Pinitas | e6032da | 2017-10-26 14:13:35 +0100 | [diff] [blame] | 321 | if env['os'] in ['bare_metal'] or env['standalone']: |
Anthony Barbier | 5f0124d | 2018-04-13 14:05:34 +0100 | [diff] [blame] | 322 | print("Cannot link OpenCL statically, which is required for bare metal / standalone builds") |
| 323 | Exit(1) |
| 324 | |
| 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") |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 328 | Exit(1) |
| 329 | |
Anthony Barbier | 9fb0cac | 2018-04-20 15:46:21 +0100 | [diff] [blame] | 330 | if env["os"] not in ["android", "bare_metal"] and (env['opencl'] or env['cppthreads']): |
| 331 | env.Append(LIBS = ['pthread']) |
| 332 | |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 333 | if env['opencl'] or env['gles_compute']: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 334 | if env['embed_kernels']: |
| 335 | env.Append(CPPDEFINES = ['EMBEDDED_KERNELS']) |
| 336 | |
| 337 | if env['debug']: |
| 338 | env['asserts'] = True |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 339 | env['logging'] = True |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 340 | env.Append(CXXFLAGS = ['-O0','-g','-gdwarf-2']) |
| 341 | env.Append(CPPDEFINES = ['ARM_COMPUTE_DEBUG_ENABLED']) |
| 342 | else: |
Ramana Radhakrishnan | d176d54 | 2019-07-04 11:38:45 +0100 | [diff] [blame] | 343 | env.Append(CXXFLAGS = ['-O3']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 344 | |
| 345 | if env['asserts']: |
| 346 | env.Append(CPPDEFINES = ['ARM_COMPUTE_ASSERTS_ENABLED']) |
Moritz Pflanzer | 8b74c78 | 2017-09-14 14:33:20 +0100 | [diff] [blame] | 347 | env.Append(CXXFLAGS = ['-fstack-protector-strong']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 348 | |
Georgios Pinitas | 7d3d1b9 | 2017-10-12 17:34:20 +0100 | [diff] [blame] | 349 | if env['logging']: |
| 350 | env.Append(CPPDEFINES = ['ARM_COMPUTE_LOGGING_ENABLED']) |
| 351 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 352 | env.Append(CPPPATH = ['#/include', "#"]) |
| 353 | env.Append(CXXFLAGS = env['extra_cxx_flags']) |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 354 | env.Append(LINKFLAGS = env['extra_link_flags']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 355 | |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 356 | Default( install_include("arm_compute")) |
Anthony Barbier | 1056595 | 2018-11-15 09:50:06 +0000 | [diff] [blame] | 357 | Default( install_include("support")) |
Michele Di Giorgio | 6afea90 | 2019-04-03 11:40:20 +0100 | [diff] [blame] | 358 | Default( install_include("utils")) |
| 359 | for dirname in os.listdir("./include"): |
| 360 | Default( install_include("include/%s" % dirname)) |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 361 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 362 | Export('version_at_least') |
| 363 | |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 364 | if env['gles_compute'] and env['os'] != 'android': |
Anthony Barbier | 14c86a9 | 2017-12-14 16:27:41 +0000 | [diff] [blame] | 365 | env.Append(CPPPATH = ['#/include/linux']) |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 366 | |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 367 | SConscript('./SConscript', variant_dir=build_path, duplicate=0) |
Anthony Barbier | 6c0348f | 2017-11-10 18:32:38 +0000 | [diff] [blame] | 368 | |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 369 | if env['examples'] and env['exceptions']: |
| 370 | if env['os'] == 'bare_metal' and env['arch'] == 'armv7a': |
Michalis Spyrou | 35f35a6 | 2019-12-23 11:29:52 +0000 | [diff] [blame] | 371 | print("WARNING: Building examples for bare metal and armv7a is not supported. Use examples=0") |
| 372 | Return() |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 373 | SConscript('./examples/SConscript', variant_dir='%s/examples' % build_path, duplicate=0) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 374 | |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [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() |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 379 | SConscript('./tests/SConscript', variant_dir='%s/tests' % build_path, duplicate=0) |