blob: 7591075cd12cb0f3c90db38a49d68d1a5cf9f456 [file] [log] [blame]
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +00001# -*- coding: utf-8 -*-
2
3# Copyright (c) 2016-2021 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01004#
5# SPDX-License-Identifier: MIT
6#
7# Permission is hereby granted, free of charge, to any person obtaining a copy
8# of this software and associated documentation files (the "Software"), to
9# deal in the Software without restriction, including without limitation the
10# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11# sell copies of the Software, and to permit persons to whom the Software is
12# furnished to do so, subject to the following conditions:
13#
14# The above copyright notice and this permission notice shall be included in all
15# copies or substantial portions of the Software.
16#
17# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23# SOFTWARE.
24
25import SCons
Georgios Pinitasb6af4822021-09-14 12:33:34 +010026import json
Anthony Barbier6ff3b192017-09-04 18:44:23 +010027import os
28import subprocess
Georgios Pinitasb6af4822021-09-14 12:33:34 +010029import sys
Anthony Barbier6ff3b192017-09-04 18:44:23 +010030
31def version_at_least(version, required):
Anthony Barbier6ff3b192017-09-04 18:44:23 +010032
Michalis Spyroucfac3052020-10-14 12:06:28 +010033 version_list = version.split('.')
34 required_list = required.split('.')
35 end = min(len(version_list), len(required_list))
36 for i in range(0, end):
37 if int(version_list[i]) < int(required_list[i]):
Anthony Barbier6ff3b192017-09-04 18:44:23 +010038 return False
Michalis Spyroucfac3052020-10-14 12:06:28 +010039 elif int(version_list[i]) > int(required_list[i]):
Anthony Barbier6ff3b192017-09-04 18:44:23 +010040 return True
41
42 return True
43
44vars = Variables("scons")
45vars.AddVariables(
46 BoolVariable("debug", "Debug", False),
47 BoolVariable("asserts", "Enable asserts (this flag is forced to 1 for debug=1)", False),
ramelg0193d6cf02021-09-23 13:59:22 +010048 BoolVariable("logging", "Enable Logging", False),
Georgios Pinitasf2cdce32019-12-09 18:35:57 +000049 EnumVariable("arch", "Target Architecture", "armv7a",
Slava Barinovdb0e2c82021-04-07 11:23:27 +030050 allowed_values=("armv7a", "armv7a-hf", "arm64-v8a", "arm64-v8.2-a", "arm64-v8.2-a-sve", "arm64-v8.2-a-sve2", "x86_32", "x86_64",
Sang-Hoon Park50e98bb2021-01-14 14:54:14 +000051 "armv8a", "armv8.2-a", "armv8.2-a-sve", "armv8.6-a", "armv8.6-a-sve", "armv8.6-a-sve2", "armv8r64", "x86")),
Georgios Pinitasf2cdce32019-12-09 18:35:57 +000052 EnumVariable("estate", "Execution State", "auto", allowed_values=("auto", "32", "64")),
Georgios Pinitas45514032020-12-30 00:03:09 +000053 EnumVariable("os", "Target OS", "linux", allowed_values=("linux", "android", "tizen", "macos", "bare_metal")),
Anthony Barbier6a3daf12018-02-19 17:24:27 +000054 EnumVariable("build", "Build type", "cross_compile", allowed_values=("native", "cross_compile", "embed_only")),
Anthony Barbier6ff3b192017-09-04 18:44:23 +010055 BoolVariable("examples", "Build example programs", True),
SiCong Li8b4c7302019-09-19 12:18:15 +010056 BoolVariable("gemm_tuner", "Build gemm_tuner programs", True),
Anthony Barbier6ff3b192017-09-04 18:44:23 +010057 BoolVariable("Werror", "Enable/disable the -Werror compilation flag", True),
Georgios Pinitasbdcdc392021-04-22 16:42:03 +010058 BoolVariable("fat_binary", "Build fat binary version of library. Note works only for armv8.2-a", False),
Pablo Telloc6cb35a2017-06-21 15:39:47 +010059 BoolVariable("standalone", "Builds the tests as standalone executables, links statically with libgcc, libstdc++ and libarm_compute", False),
Anthony Barbier6ff3b192017-09-04 18:44:23 +010060 BoolVariable("opencl", "Enable OpenCL support", True),
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +000061 BoolVariable("neon", "Enable Arm® Neon™ support", False),
Anthony Barbiercc0a80b2017-12-15 11:37:29 +000062 BoolVariable("embed_kernels", "Embed OpenCL kernels and OpenGL ES compute shaders in library binary", True),
Georgios Pinitasea857272021-01-22 05:47:37 +000063 BoolVariable("compress_kernels", "Compress embedded OpenCL kernels in library binary. Note embed_kernels should be enabled", False),
Anthony Barbier6ff3b192017-09-04 18:44:23 +010064 BoolVariable("set_soname", "Set the library's soname and shlibversion (requires SCons 2.4 or above)", False),
65 BoolVariable("openmp", "Enable OpenMP backend", False),
66 BoolVariable("cppthreads", "Enable C++11 threads backend", True),
67 PathVariable("build_dir", "Specify sub-folder for the build", ".", PathVariable.PathAccept),
Anthony Barbier01bbd5f2018-11-01 15:10:51 +000068 PathVariable("install_dir", "Specify sub-folder for the install", "", PathVariable.PathAccept),
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000069 BoolVariable("exceptions", "Enable/disable C++ exception support", True),
Michalis Spyrou62c2ad62021-06-21 17:40:09 +010070 BoolVariable("high_priority", "Generate a library containing only the high priority operators", False),
Michalis Spyrou748a7c82019-10-07 13:00:44 +010071 PathVariable("linker_script", "Use an external linker script", "", PathVariable.PathAccept),
Michele Di Giorgio72610dc2020-11-18 15:29:08 +000072 PathVariable("external_tests_dir", "Add examples, benchmarks and tests to the tests suite", "", PathVariable.PathAccept),
Georgios Pinitas49c6ced2020-09-21 17:16:09 +010073 ListVariable("custom_options", "Custom options that can be used to turn on/off features", "none", ["disable_mmla_fp"]),
Michalis Spyroua3c9a3b2020-12-08 21:02:16 +000074 ListVariable("data_type_support", "Enable a list of data types to support", "all", ["qasymm8", "qasymm8_signed", "qsymm16", "fp16", "fp32", "integer"]),
Sheri Zhang79144a62021-02-08 17:43:04 +000075 ListVariable("data_layout_support", "Enable a list of data layout to support", "all", ["nhwc", "nchw"]),
Anthony Barbier149de5b2018-12-06 10:27:37 +000076 ("toolchain_prefix", "Override the toolchain prefix", ""),
alered01d8872c12020-02-10 11:29:45 +000077 ("compiler_prefix", "Override the compiler prefix", ""),
Anthony Barbier7390e052018-03-13 09:29:41 +000078 ("extra_cxx_flags", "Extra CXX flags to be appended to the build command", ""),
Georgios Pinitas421405b2018-10-26 19:05:32 +010079 ("extra_link_flags", "Extra LD flags to be appended to the build command", ""),
Manuel Bottinie5a9ad82020-11-18 16:22:16 +000080 ("compiler_cache", "Command to prefix to the C and C++ compiler (e.g ccache)", ""),
Georgios Pinitasb6af4822021-09-14 12:33:34 +010081 ("specs_file", "Specs file to use (e.g. rdimon.specs)", ""),
82 ("build_config", "Operator/Data-type/Data-layout configuration to use for tailored ComputeLibrary builds. Can be a JSON file or a JSON formatted string", "")
Anthony Barbier6ff3b192017-09-04 18:44:23 +010083)
84
85env = Environment(platform="posix", variables=vars, ENV = os.environ)
Anthony Barbiere8a55df2018-10-26 09:05:01 +010086build_path = env['build_dir']
87# If build_dir is a relative path then add a #build/ prefix:
88if not env['build_dir'].startswith('/'):
89 SConsignFile('build/%s/.scons' % build_path)
90 build_path = "#build/%s" % build_path
91else:
92 SConsignFile('%s/.scons' % build_path)
93
Anthony Barbier01bbd5f2018-11-01 15:10:51 +000094install_path = env['install_dir']
95#If the install_dir is a relative path then assume it's from inside build_dir
96if not env['install_dir'].startswith('/') and install_path != "":
97 install_path = "%s/%s" % (build_path, install_path)
98
Anthony Barbiere8a55df2018-10-26 09:05:01 +010099env.Append(LIBPATH = [build_path])
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000100Export('env')
101Export('vars')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100102
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000103def install_lib( lib ):
104 # If there is no install folder, then there is nothing to do:
105 if install_path == "":
106 return lib
107 return env.Install( "%s/lib/" % install_path, lib)
108def install_bin( bin ):
109 # If there is no install folder, then there is nothing to do:
110 if install_path == "":
111 return bin
112 return env.Install( "%s/bin/" % install_path, bin)
113def install_include( inc ):
114 if install_path == "":
115 return inc
116 return env.Install( "%s/include/" % install_path, inc)
117
118Export('install_lib')
119Export('install_bin')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100120
121Help(vars.GenerateHelpText(env))
122
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100123if env['linker_script'] and env['os'] != 'bare_metal':
124 print("Linker script is only supported for bare_metal builds")
125 Exit(1)
126
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000127if env['build'] == "embed_only":
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100128 SConscript('./SConscript', variant_dir=build_path, duplicate=0)
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000129 Return()
130
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100131if env['neon'] and 'x86' in env['arch']:
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +0000132 print("Cannot compile Arm® Neon™ for x86")
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100133 Exit(1)
134
135if env['set_soname'] and not version_at_least(SCons.__version__, "2.4"):
ggardet767c9f72018-06-29 17:01:01 +0200136 print("Setting the library's SONAME / SHLIBVERSION requires SCons 2.4 or above")
137 print("Update your version of SCons or use set_soname=0")
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100138 Exit(1)
139
140if env['os'] == 'bare_metal':
141 if env['cppthreads'] or env['openmp']:
142 print("ERROR: OpenMP and C++11 threads not supported in bare_metal. Use cppthreads=0 openmp=0")
143 Exit(1)
144
Georgios Pinitasea857272021-01-22 05:47:37 +0000145if env['opencl'] and env['embed_kernels'] and env['compress_kernels'] and env['os'] not in ['android']:
146 print("Compressed kernels are supported only for android builds")
147 Exit(1)
148
Michalis Spyrou323ce0f2018-11-30 16:30:43 +0000149if not env['exceptions']:
Manuel Bottiniceaa0bf2021-02-16 15:15:19 +0000150 if env['opencl']:
151 print("ERROR: OpenCL is not supported when building without exceptions. Use opencl=0")
Michalis Spyrou323ce0f2018-11-30 16:30:43 +0000152 Exit(1)
153
154 env.Append(CPPDEFINES = ['ARM_COMPUTE_EXCEPTIONS_DISABLED'])
155 env.Append(CXXFLAGS = ['-fno-exceptions'])
156
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100157env.Append(CXXFLAGS = ['-Wall','-DARCH_ARM',
Michalis Spyrou7c60c992019-10-10 14:33:47 +0100158 '-Wextra','-pedantic','-Wdisabled-optimization','-Wformat=2',
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100159 '-Winit-self','-Wstrict-overflow=2','-Wswitch-default',
Georgios Pinitas40f51a62020-11-21 03:04:18 +0000160 '-std=c++14','-Woverloaded-virtual', '-Wformat-security',
Michalis Spyroufae513c2019-10-16 17:41:33 +0100161 '-Wctor-dtor-privacy','-Wsign-promo','-Weffc++','-Wno-overlength-strings'])
Isabella Gottardib28f29d2017-11-09 17:05:07 +0000162
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100163env.Append(CPPDEFINES = ['_GLIBCXX_USE_NANOSLEEP'])
164
Georgios Pinitas45514032020-12-30 00:03:09 +0000165default_cpp_compiler = 'g++' if env['os'] not in ['android', 'macos'] else 'clang++'
166default_c_compiler = 'gcc' if env['os'] not in ['android', 'macos'] else 'clang'
Anthony Barbiera026e982018-01-18 10:57:52 +0000167cpp_compiler = os.environ.get('CXX', default_cpp_compiler)
168c_compiler = os.environ.get('CC', default_c_compiler)
169
Anthony Barbierdd669372018-03-01 17:08:54 +0000170if env['os'] == 'android' and ( 'clang++' not in cpp_compiler or 'clang' not in c_compiler ):
ggardet767c9f72018-06-29 17:01:01 +0200171 print( "WARNING: Only clang is officially supported to build the Compute Library for Android")
Anthony Barbiera026e982018-01-18 10:57:52 +0000172
Anthony Barbierdd669372018-03-01 17:08:54 +0000173if 'clang++' in cpp_compiler:
Michalis Spyrou7c60c992019-10-10 14:33:47 +0100174 env.Append(CXXFLAGS = ['-Wno-vla-extension'])
Georgios Pinitase874ef92019-09-09 17:40:33 +0100175elif 'armclang' in cpp_compiler:
176 pass
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100177else:
Michalis Spyrou7c60c992019-10-10 14:33:47 +0100178 env.Append(CXXFLAGS = ['-Wlogical-op','-Wnoexcept','-Wstrict-null-sentinel'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100179
SiCongLi410e21e2020-12-11 15:07:53 +0000180if cpp_compiler == 'g++':
181 # Don't strip comments that could include markers
182 env.Append(CXXFLAGS = ['-C'])
183
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100184if env['cppthreads']:
185 env.Append(CPPDEFINES = [('ARM_COMPUTE_CPP_SCHEDULER', 1)])
186
187if env['openmp']:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100188 env.Append(CPPDEFINES = [('ARM_COMPUTE_OPENMP_SCHEDULER', 1)])
189 env.Append(CXXFLAGS = ['-fopenmp'])
190 env.Append(LINKFLAGS = ['-fopenmp'])
191
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000192# Validate and define state
193if env['estate'] == 'auto':
194 if 'v7a' in env['arch']:
195 env['estate'] = '32'
196 else:
197 env['estate'] = '64'
198
199# Map legacy arch
200if 'arm64' in env['arch']:
201 env['estate'] = '64'
202
203if 'v7a' in env['estate'] and env['estate'] == '64':
204 print("ERROR: armv7a architecture has only 32-bit execution state")
205 Exit(1)
206
Georgios Pinitase874ef92019-09-09 17:40:33 +0100207# Add architecture specific flags
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100208prefix = ""
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000209if 'v7a' in env['arch']:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100210 env.Append(CXXFLAGS = ['-march=armv7-a', '-mthumb', '-mfpu=neon'])
Slava Barinovdb0e2c82021-04-07 11:23:27 +0300211 if (env['os'] == 'android' or env['os'] == 'tizen') and not 'hf' in env['arch']:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100212 env.Append(CXXFLAGS = ['-mfloat-abi=softfp'])
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000213 else:
214 env.Append(CXXFLAGS = ['-mfloat-abi=hard'])
Georgios Pinitas94672fb2020-01-22 18:36:27 +0000215elif 'v8' in env['arch']:
Manuel Bottinie5a9ad82020-11-18 16:22:16 +0000216 if 'sve2' in env['arch']:
217 env.Append(CXXFLAGS = ['-march=armv8.2-a+sve2+fp16+dotprod'])
Michalis Spyrou20fca522021-06-07 14:23:57 +0100218 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVE2'])
Manuel Bottinie5a9ad82020-11-18 16:22:16 +0000219 elif 'sve' in env['arch']:
Georgios Pinitas421405b2018-10-26 19:05:32 +0100220 env.Append(CXXFLAGS = ['-march=armv8.2-a+sve+fp16+dotprod'])
Sang-Hoon Park50e98bb2021-01-14 14:54:14 +0000221 elif 'armv8r64' in env['arch']:
222 env.Append(CXXFLAGS = ['-march=armv8.4-a'])
Georgios Pinitasdeb5b772020-12-07 20:39:51 +0000223 elif 'v8.' in env['arch']:
Georgios Pinitas421405b2018-10-26 19:05:32 +0100224 env.Append(CXXFLAGS = ['-march=armv8.2-a+fp16']) # explicitly enable fp16 extension otherwise __ARM_FEATURE_FP16_VECTOR_ARITHMETIC is undefined
Georgios Pinitas94672fb2020-01-22 18:36:27 +0000225 else:
226 env.Append(CXXFLAGS = ['-march=armv8-a'])
227
Georgios Pinitas8e2f64f2021-07-28 13:18:46 +0100228 if 'v8.6-a' in env['arch']:
Michalis Spyrou20fca522021-06-07 14:23:57 +0100229 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_I8MM', 'ARM_COMPUTE_ENABLE_BF16'])
Georgios Pinitas49c6ced2020-09-21 17:16:09 +0100230 if "disable_mmla_fp" not in env['custom_options']:
Michalis Spyrou20fca522021-06-07 14:23:57 +0100231 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVEF32MM'])
Georgios Pinitas8e2f64f2021-07-28 13:18:46 +0100232 if 'v8.' in env['arch']:
233 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_FP16'])
234
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000235elif 'x86' in env['arch']:
236 if env['estate'] == '32':
237 env.Append(CCFLAGS = ['-m32'])
238 env.Append(LINKFLAGS = ['-m32'])
239 else:
240 env.Append(CXXFLAGS = ['-fPIC'])
241 env.Append(CCFLAGS = ['-m64'])
242 env.Append(LINKFLAGS = ['-m64'])
243
244# Define toolchain
245prefix = ""
246if 'x86' not in env['arch']:
247 if env['estate'] == '32':
248 if env['os'] == 'linux':
249 prefix = "arm-linux-gnueabihf-" if 'v7' in env['arch'] else "armv8l-linux-gnueabihf-"
250 elif env['os'] == 'bare_metal':
251 prefix = "arm-eabi-"
252 elif env['os'] == 'android':
253 prefix = "arm-linux-androideabi-"
Inki Dae51a95582020-03-23 08:29:02 +0900254 elif env['os'] == 'tizen':
255 prefix = "armv7l-tizen-linux-gnueabi-"
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000256 elif env['estate'] == '64' and 'v8' in env['arch']:
257 if env['os'] == 'linux':
258 prefix = "aarch64-linux-gnu-"
259 elif env['os'] == 'bare_metal':
260 prefix = "aarch64-elf-"
261 elif env['os'] == 'android':
262 prefix = "aarch64-linux-android-"
Inki Dae51a95582020-03-23 08:29:02 +0900263 elif env['os'] == 'tizen':
264 prefix = "aarch64-tizen-linux-gnu-"
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100265
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100266if 'sve' in env['arch']:
Michalis Spyrou20fca522021-06-07 14:23:57 +0100267 env.Append(CXXFLAGS = ['-DENABLE_SVE', '-DARM_COMPUTE_ENABLE_SVE'])
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100268else:
Michalis Spyrou20fca522021-06-07 14:23:57 +0100269 env.Append(CXXFLAGS = ['-DENABLE_NEON', '-DARM_COMPUTE_ENABLE_NEON'])
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100270
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100271if env['build'] == 'native':
272 prefix = ""
273
Anthony Barbier149de5b2018-12-06 10:27:37 +0000274if env["toolchain_prefix"] != "":
275 prefix = env["toolchain_prefix"]
276
alered01d8872c12020-02-10 11:29:45 +0000277compiler_prefix = prefix
278if env["compiler_prefix"] != "":
279 compiler_prefix = env["compiler_prefix"]
280
281env['CC'] = env['compiler_cache']+ " " + compiler_prefix + c_compiler
282env['CXX'] = env['compiler_cache']+ " " + compiler_prefix + cpp_compiler
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100283env['LD'] = prefix + "ld"
284env['AS'] = prefix + "as"
285env['AR'] = prefix + "ar"
286env['RANLIB'] = prefix + "ranlib"
287
288if not GetOption("help"):
289 try:
SiCong Li3b9a5642020-10-16 12:10:15 +0100290 compiler_ver = subprocess.check_output(env['CXX'].split() + ["-dumpversion"]).decode().strip()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100291 except OSError:
292 print("ERROR: Compiler '%s' not found" % env['CXX'])
293 Exit(1)
294
Georgios Pinitase874ef92019-09-09 17:40:33 +0100295 if 'armclang' in cpp_compiler:
296 pass
297 elif 'clang++' not in cpp_compiler:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100298 if env['arch'] == 'arm64-v8.2-a' and not version_at_least(compiler_ver, '6.2.1'):
ggardet767c9f72018-06-29 17:01:01 +0200299 print("GCC 6.2.1 or newer is required to compile armv8.2-a code")
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100300 Exit(1)
301 elif env['arch'] == 'arm64-v8a' and not version_at_least(compiler_ver, '4.9'):
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +0000302 print("GCC 4.9 or newer is required to compile Arm® Neon™ code for AArch64")
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100303 Exit(1)
304
305 if version_at_least(compiler_ver, '6.1'):
306 env.Append(CXXFLAGS = ['-Wno-ignored-attributes'])
307
308 if compiler_ver == '4.8.3':
309 env.Append(CXXFLAGS = ['-Wno-array-bounds'])
310
Michalis Spyroucfac3052020-10-14 12:06:28 +0100311 if not version_at_least(compiler_ver, '7.0.0') and env['os'] == 'bare_metal':
312 env.Append(LINKFLAGS = ['-fstack-protector-strong'])
313
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100314if env['fat_binary']:
315 if env['arch'] != 'armv8.2-a':
316 print("Currently fat binary is only supported with armv8.2-a")
317 Exit(1)
Georgios Pinitas8e2f64f2021-07-28 13:18:46 +0100318 env.Append(CXXFLAGS = ['-DENABLE_NEON', '-DARM_COMPUTE_ENABLE_NEON',
319 '-DENABLE_SVE', '-DARM_COMPUTE_ENABLE_SVE',
320 '-DARM_COMPUTE_ENABLE_FP16', '-DARM_COMPUTE_ENABLE_BF16',
321 '-DARM_COMPUTE_ENABLE_I8MM', '-DARM_COMPUTE_ENABLE_SVEF32MM'])
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100322
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100323if env['high_priority'] and env['build_config']:
324 print("The high priority library cannot be built in conjuction with a user-specified build configuration")
325 Exit(1)
326
327if not env['high_priority'] and not env['build_config']:
328 env.Append(CPPDEFINES = ['ARM_COMPUTE_GRAPH_ENABLED'])
329
Georgios Pinitasff4fca02020-10-02 21:00:00 +0100330if env['data_type_support']:
331 if any(i in env['data_type_support'] for i in ['all', 'fp16']):
332 env.Append(CXXFLAGS = ['-DENABLE_FP16_KERNELS'])
333 if any(i in env['data_type_support'] for i in ['all', 'fp32']):
334 env.Append(CXXFLAGS = ['-DENABLE_FP32_KERNELS'])
Michalis Spyrouc4d45552020-10-19 12:41:30 +0100335 if any(i in env['data_type_support'] for i in ['all', 'qasymm8']):
336 env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_KERNELS'])
337 if any(i in env['data_type_support'] for i in ['all', 'qasymm8_signed']):
338 env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_SIGNED_KERNELS'])
339 if any(i in env['data_type_support'] for i in ['all', 'qsymm16']):
340 env.Append(CXXFLAGS = ['-DENABLE_QSYMM16_KERNELS'])
Michalis Spyroua3c9a3b2020-12-08 21:02:16 +0000341 if any(i in env['data_type_support'] for i in ['all', 'integer']):
342 env.Append(CXXFLAGS = ['-DENABLE_INTEGER_KERNELS'])
Georgios Pinitasff4fca02020-10-02 21:00:00 +0100343
Sheri Zhang79144a62021-02-08 17:43:04 +0000344if env['data_layout_support']:
345 if any(i in env['data_layout_support'] for i in ['all', 'nhwc']):
346 env.Append(CXXFLAGS = ['-DENABLE_NHWC_KERNELS'])
347 if any(i in env['data_layout_support'] for i in ['all', 'nchw']):
348 env.Append(CXXFLAGS = ['-DENABLE_NCHW_KERNELS'])
349
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100350if env['standalone']:
351 env.Append(CXXFLAGS = ['-fPIC'])
Anthony Barbier665c89b2018-07-16 11:40:09 +0100352 env.Append(LINKFLAGS = ['-static-libgcc','-static-libstdc++'])
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100353
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100354if env['Werror']:
355 env.Append(CXXFLAGS = ['-Werror'])
356
357if env['os'] == 'android':
358 env.Append(CPPDEFINES = ['ANDROID'])
Michalis Spyrou2d22c3f2020-02-12 14:50:19 +0000359 env.Append(LINKFLAGS = ['-pie', '-static-libstdc++', '-ldl'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100360elif env['os'] == 'bare_metal':
361 env.Append(LINKFLAGS = ['-static'])
362 env.Append(CXXFLAGS = ['-fPIC'])
Manuel Bottinie5a9ad82020-11-18 16:22:16 +0000363 if env['specs_file'] == "":
364 env.Append(LINKFLAGS = ['-specs=rdimon.specs'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100365 env.Append(CPPDEFINES = ['NO_MULTI_THREADING'])
Michalis Spyrou07781ac2017-08-31 15:11:41 +0100366 env.Append(CPPDEFINES = ['BARE_METAL'])
Manuel Bottini827817e2020-11-19 12:12:06 +0000367if env['os'] == 'linux' and env['arch'] == 'armv7a':
368 env.Append(CXXFLAGS = [ '-Wno-psabi' ])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100369
Manuel Bottinie5a9ad82020-11-18 16:22:16 +0000370if env['specs_file'] != "":
371 env.Append(LINKFLAGS = ['-specs='+env['specs_file']])
372
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000373if env['neon']:
374 env.Append(CPPDEFINES = ['ARM_COMPUTE_CPU_ENABLED'])
375
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100376if env['opencl']:
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000377 env.Append(CPPDEFINES = ['ARM_COMPUTE_OPENCL_ENABLED'])
Georgios Pinitase6032da2017-10-26 14:13:35 +0100378 if env['os'] in ['bare_metal'] or env['standalone']:
Anthony Barbier5f0124d2018-04-13 14:05:34 +0100379 print("Cannot link OpenCL statically, which is required for bare metal / standalone builds")
380 Exit(1)
381
Anthony Barbier9fb0cac2018-04-20 15:46:21 +0100382if env["os"] not in ["android", "bare_metal"] and (env['opencl'] or env['cppthreads']):
383 env.Append(LIBS = ['pthread'])
384
Manuel Bottiniceaa0bf2021-02-16 15:15:19 +0000385if env['opencl']:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100386 if env['embed_kernels']:
387 env.Append(CPPDEFINES = ['EMBEDDED_KERNELS'])
Georgios Pinitasea857272021-01-22 05:47:37 +0000388 if env['compress_kernels']:
389 env.Append(CPPDEFINES = ['ARM_COMPUTE_COMPRESSED_KERNELS'])
390 env.Append(LIBS = ['z'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100391
392if env['debug']:
393 env['asserts'] = True
394 env.Append(CXXFLAGS = ['-O0','-g','-gdwarf-2'])
395 env.Append(CPPDEFINES = ['ARM_COMPUTE_DEBUG_ENABLED'])
396else:
Ramana Radhakrishnand176d542019-07-04 11:38:45 +0100397 env.Append(CXXFLAGS = ['-O3'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100398
399if env['asserts']:
400 env.Append(CPPDEFINES = ['ARM_COMPUTE_ASSERTS_ENABLED'])
Moritz Pflanzer8b74c782017-09-14 14:33:20 +0100401 env.Append(CXXFLAGS = ['-fstack-protector-strong'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100402
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +0100403if env['logging']:
404 env.Append(CPPDEFINES = ['ARM_COMPUTE_LOGGING_ENABLED'])
405
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100406env.Append(CPPPATH = ['#/include', "#"])
407env.Append(CXXFLAGS = env['extra_cxx_flags'])
Georgios Pinitas421405b2018-10-26 19:05:32 +0100408env.Append(LINKFLAGS = env['extra_link_flags'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100409
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000410Default( install_include("arm_compute"))
Anthony Barbier10565952018-11-15 09:50:06 +0000411Default( install_include("support"))
Michele Di Giorgio6afea902019-04-03 11:40:20 +0100412Default( install_include("utils"))
413for dirname in os.listdir("./include"):
414 Default( install_include("include/%s" % dirname))
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000415
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100416Export('version_at_least')
417
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100418SConscript('./SConscript', variant_dir=build_path, duplicate=0)
Anthony Barbier6c0348f2017-11-10 18:32:38 +0000419
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100420if env['examples'] and env['exceptions']:
421 if env['os'] == 'bare_metal' and env['arch'] == 'armv7a':
Michalis Spyrou35f35a62019-12-23 11:29:52 +0000422 print("WARNING: Building examples for bare metal and armv7a is not supported. Use examples=0")
423 Return()
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100424 SConscript('./examples/SConscript', variant_dir='%s/examples' % build_path, duplicate=0)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100425
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100426if env['exceptions']:
427 if env['os'] == 'bare_metal' and env['arch'] == 'armv7a':
428 print("WARNING: Building tests for bare metal and armv7a is not supported")
429 Return()
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100430 SConscript('./tests/SConscript', variant_dir='%s/tests' % build_path, duplicate=0)