blob: 400228c71ac05dab8eb49b5f1fe3051b82d8a613 [file] [log] [blame]
Jenkinsf7399fd2021-05-18 15:04:27 +01001# -*- coding: utf-8 -*-
2
3# Copyright (c) 2016-2021 Arm Limited.
Anthony Barbier871448e2017-03-24 14:54:29 +00004#
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
Anthony Barbierdbdab852017-06-23 15:42:00 +010025import SCons
Jenkins91ee4d02021-11-15 14:37:16 +000026import json
Anthony Barbier46d59272017-05-04 09:15:15 +010027import os
Anthony Barbierdbdab852017-06-23 15:42:00 +010028import subprocess
Jenkins91ee4d02021-11-15 14:37:16 +000029import sys
Anthony Barbierdbdab852017-06-23 15:42:00 +010030
31def version_at_least(version, required):
Anthony Barbierdbdab852017-06-23 15:42:00 +010032
Jenkins49b8f902020-11-27 12:49:11 +000033 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 Barbierdbdab852017-06-23 15:42:00 +010038 return False
Jenkins49b8f902020-11-27 12:49:11 +000039 elif int(version_list[i]) > int(required_list[i]):
Anthony Barbierdbdab852017-06-23 15:42:00 +010040 return True
41
42 return True
Anthony Barbier46d59272017-05-04 09:15:15 +010043
Jenkins91ee4d02021-11-15 14:37:16 +000044def read_build_config_json(build_config):
45 build_config_contents = {}
46 custom_types = []
47 custom_layouts = []
48 if os.path.isfile(build_config):
49 with open(build_config) as f:
50 try:
51 build_config_contents = json.load(f)
52 except:
53 print("Warning: Build configuration file is of invalid JSON format!")
54 else:
55 try:
56 build_config_contents = json.loads(build_config)
57 except:
58 print("Warning: Build configuration string is of invalid JSON format!")
59 if build_config_contents:
60 custom_types = build_config_contents.get("data_types", [])
61 custom_layouts = build_config_contents.get("data_layouts", [])
62 return custom_types, custom_layouts
63
64def update_data_type_layout_flags(env, data_types, data_layouts):
65 # Manage data-types
66 if any(i in data_types for i in ['all', 'fp16']):
67 env.Append(CXXFLAGS = ['-DENABLE_FP16_KERNELS'])
68 if any(i in data_types for i in ['all', 'fp32']):
69 env.Append(CXXFLAGS = ['-DENABLE_FP32_KERNELS'])
70 if any(i in data_types for i in ['all', 'qasymm8']):
71 env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_KERNELS'])
72 if any(i in data_types for i in ['all', 'qasymm8_signed']):
73 env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_SIGNED_KERNELS'])
74 if any(i in data_types for i in ['all', 'qsymm16']):
75 env.Append(CXXFLAGS = ['-DENABLE_QSYMM16_KERNELS'])
76 if any(i in data_types for i in ['all', 'integer']):
77 env.Append(CXXFLAGS = ['-DENABLE_INTEGER_KERNELS'])
78
79 # Manage data-layouts
80 if any(i in data_layouts for i in ['all', 'nhwc']):
81 env.Append(CXXFLAGS = ['-DENABLE_NHWC_KERNELS'])
82 if any(i in data_layouts for i in ['all', 'nchw']):
83 env.Append(CXXFLAGS = ['-DENABLE_NCHW_KERNELS'])
84
85 return env
86
87
Anthony Barbier46d59272017-05-04 09:15:15 +010088vars = Variables("scons")
89vars.AddVariables(
90 BoolVariable("debug", "Debug", False),
91 BoolVariable("asserts", "Enable asserts (this flag is forced to 1 for debug=1)", False),
Jenkins91ee4d02021-11-15 14:37:16 +000092 BoolVariable("logging", "Enable Logging", False),
Jenkins36ccc902020-02-21 11:10:48 +000093 EnumVariable("arch", "Target Architecture", "armv7a",
Jenkinsf7399fd2021-05-18 15:04:27 +010094 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",
Jenkins7dcb9fa2021-02-23 22:45:28 +000095 "armv8a", "armv8.2-a", "armv8.2-a-sve", "armv8.6-a", "armv8.6-a-sve", "armv8.6-a-sve2", "armv8r64", "x86")),
Jenkins36ccc902020-02-21 11:10:48 +000096 EnumVariable("estate", "Execution State", "auto", allowed_values=("auto", "32", "64")),
Jenkins7dcb9fa2021-02-23 22:45:28 +000097 EnumVariable("os", "Target OS", "linux", allowed_values=("linux", "android", "tizen", "macos", "bare_metal")),
Anthony Barbier06ea0482018-02-22 15:45:35 +000098 EnumVariable("build", "Build type", "cross_compile", allowed_values=("native", "cross_compile", "embed_only")),
Anthony Barbierdbdab852017-06-23 15:42:00 +010099 BoolVariable("examples", "Build example programs", True),
Jenkins0e205f72019-11-28 16:53:35 +0000100 BoolVariable("gemm_tuner", "Build gemm_tuner programs", True),
Anthony Barbier46d59272017-05-04 09:15:15 +0100101 BoolVariable("Werror", "Enable/disable the -Werror compilation flag", True),
Jenkinsc66f0e02021-08-20 08:52:20 +0000102 BoolVariable("fat_binary", "Build fat binary version of library. Note works only for armv8.2-a", False),
Kaizen8938bd32017-09-28 14:38:23 +0100103 BoolVariable("standalone", "Builds the tests as standalone executables, links statically with libgcc, libstdc++ and libarm_compute", False),
Anthony Barbier46d59272017-05-04 09:15:15 +0100104 BoolVariable("opencl", "Enable OpenCL support", True),
Jenkinsf7399fd2021-05-18 15:04:27 +0100105 BoolVariable("neon", "Enable Arm® Neon™ support", False),
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000106 BoolVariable("embed_kernels", "Embed OpenCL kernels and OpenGL ES compute shaders in library binary", True),
Jenkins7dcb9fa2021-02-23 22:45:28 +0000107 BoolVariable("compress_kernels", "Compress embedded OpenCL kernels in library binary. Note embed_kernels should be enabled", False),
Anthony Barbier46d59272017-05-04 09:15:15 +0100108 BoolVariable("set_soname", "Set the library's soname and shlibversion (requires SCons 2.4 or above)", False),
109 BoolVariable("openmp", "Enable OpenMP backend", False),
110 BoolVariable("cppthreads", "Enable C++11 threads backend", True),
Anthony Barbierdbdab852017-06-23 15:42:00 +0100111 PathVariable("build_dir", "Specify sub-folder for the build", ".", PathVariable.PathAccept),
Jenkinsb9abeae2018-11-22 11:58:08 +0000112 PathVariable("install_dir", "Specify sub-folder for the install", "", PathVariable.PathAccept),
Jenkins514be652019-02-28 12:25:18 +0000113 BoolVariable("exceptions", "Enable/disable C++ exception support", True),
Jenkinsc66f0e02021-08-20 08:52:20 +0000114 BoolVariable("high_priority", "Generate a library containing only the high priority operators", False),
Jenkins36ccc902020-02-21 11:10:48 +0000115 PathVariable("linker_script", "Use an external linker script", "", PathVariable.PathAccept),
Jenkins7dcb9fa2021-02-23 22:45:28 +0000116 PathVariable("external_tests_dir", "Add examples, benchmarks and tests to the tests suite", "", PathVariable.PathAccept),
Jenkins49b8f902020-11-27 12:49:11 +0000117 ListVariable("custom_options", "Custom options that can be used to turn on/off features", "none", ["disable_mmla_fp"]),
Jenkins7dcb9fa2021-02-23 22:45:28 +0000118 ListVariable("data_type_support", "Enable a list of data types to support", "all", ["qasymm8", "qasymm8_signed", "qsymm16", "fp16", "fp32", "integer"]),
119 ListVariable("data_layout_support", "Enable a list of data layout to support", "all", ["nhwc", "nchw"]),
Jenkins514be652019-02-28 12:25:18 +0000120 ("toolchain_prefix", "Override the toolchain prefix", ""),
Jenkins36ccc902020-02-21 11:10:48 +0000121 ("compiler_prefix", "Override the compiler prefix", ""),
Jenkinsb3a371b2018-05-23 11:36:53 +0100122 ("extra_cxx_flags", "Extra CXX flags to be appended to the build command", ""),
Jenkinsb9abeae2018-11-22 11:58:08 +0000123 ("extra_link_flags", "Extra LD flags to be appended to the build command", ""),
Jenkins7dcb9fa2021-02-23 22:45:28 +0000124 ("compiler_cache", "Command to prefix to the C and C++ compiler (e.g ccache)", ""),
Jenkins91ee4d02021-11-15 14:37:16 +0000125 ("specs_file", "Specs file to use (e.g. rdimon.specs)", ""),
126 ("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 Barbier46d59272017-05-04 09:15:15 +0100127)
128
Anthony Barbierdbdab852017-06-23 15:42:00 +0100129env = Environment(platform="posix", variables=vars, ENV = os.environ)
Jenkinsb9abeae2018-11-22 11:58:08 +0000130build_path = env['build_dir']
131# If build_dir is a relative path then add a #build/ prefix:
132if not env['build_dir'].startswith('/'):
133 SConsignFile('build/%s/.scons' % build_path)
134 build_path = "#build/%s" % build_path
135else:
136 SConsignFile('%s/.scons' % build_path)
137
138install_path = env['install_dir']
139#If the install_dir is a relative path then assume it's from inside build_dir
140if not env['install_dir'].startswith('/') and install_path != "":
141 install_path = "%s/%s" % (build_path, install_path)
142
143env.Append(LIBPATH = [build_path])
Anthony Barbier06ea0482018-02-22 15:45:35 +0000144Export('env')
145Export('vars')
Anthony Barbierdbdab852017-06-23 15:42:00 +0100146
Jenkinsb9abeae2018-11-22 11:58:08 +0000147def install_lib( lib ):
148 # If there is no install folder, then there is nothing to do:
149 if install_path == "":
150 return lib
151 return env.Install( "%s/lib/" % install_path, lib)
152def install_bin( bin ):
153 # If there is no install folder, then there is nothing to do:
154 if install_path == "":
155 return bin
156 return env.Install( "%s/bin/" % install_path, bin)
157def install_include( inc ):
158 if install_path == "":
159 return inc
160 return env.Install( "%s/include/" % install_path, inc)
161
162Export('install_lib')
163Export('install_bin')
Anthony Barbier46d59272017-05-04 09:15:15 +0100164
165Help(vars.GenerateHelpText(env))
166
Jenkins36ccc902020-02-21 11:10:48 +0000167if env['linker_script'] and env['os'] != 'bare_metal':
168 print("Linker script is only supported for bare_metal builds")
169 Exit(1)
170
Anthony Barbier06ea0482018-02-22 15:45:35 +0000171if env['build'] == "embed_only":
Jenkinsb9abeae2018-11-22 11:58:08 +0000172 SConscript('./SConscript', variant_dir=build_path, duplicate=0)
Anthony Barbier06ea0482018-02-22 15:45:35 +0000173 Return()
174
Anthony Barbierdbdab852017-06-23 15:42:00 +0100175if env['neon'] and 'x86' in env['arch']:
Jenkinsf7399fd2021-05-18 15:04:27 +0100176 print("Cannot compile Arm® Neon™ for x86")
Anthony Barbierdbdab852017-06-23 15:42:00 +0100177 Exit(1)
178
179if env['set_soname'] and not version_at_least(SCons.__version__, "2.4"):
ggardete2542c92018-06-29 17:01:01 +0200180 print("Setting the library's SONAME / SHLIBVERSION requires SCons 2.4 or above")
181 print("Update your version of SCons or use set_soname=0")
Anthony Barbierdbdab852017-06-23 15:42:00 +0100182 Exit(1)
183
184if env['os'] == 'bare_metal':
185 if env['cppthreads'] or env['openmp']:
186 print("ERROR: OpenMP and C++11 threads not supported in bare_metal. Use cppthreads=0 openmp=0")
187 Exit(1)
188
Jenkins7dcb9fa2021-02-23 22:45:28 +0000189if env['opencl'] and env['embed_kernels'] and env['compress_kernels'] and env['os'] not in ['android']:
190 print("Compressed kernels are supported only for android builds")
191 Exit(1)
192
Jenkins514be652019-02-28 12:25:18 +0000193if not env['exceptions']:
Jenkinsf7399fd2021-05-18 15:04:27 +0100194 if env['opencl']:
195 print("ERROR: OpenCL is not supported when building without exceptions. Use opencl=0")
Jenkins514be652019-02-28 12:25:18 +0000196 Exit(1)
197
198 env.Append(CPPDEFINES = ['ARM_COMPUTE_EXCEPTIONS_DISABLED'])
199 env.Append(CXXFLAGS = ['-fno-exceptions'])
200
Jenkins0e205f72019-11-28 16:53:35 +0000201env.Append(CXXFLAGS = ['-Wall','-DARCH_ARM',
202 '-Wextra','-pedantic','-Wdisabled-optimization','-Wformat=2',
Anthony Barbierdbdab852017-06-23 15:42:00 +0100203 '-Winit-self','-Wstrict-overflow=2','-Wswitch-default',
Jenkins7dcb9fa2021-02-23 22:45:28 +0000204 '-std=c++14','-Woverloaded-virtual', '-Wformat-security',
Jenkins0e205f72019-11-28 16:53:35 +0000205 '-Wctor-dtor-privacy','-Wsign-promo','-Weffc++','-Wno-overlength-strings'])
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000206
Anthony Barbierdbdab852017-06-23 15:42:00 +0100207env.Append(CPPDEFINES = ['_GLIBCXX_USE_NANOSLEEP'])
208
Jenkins7dcb9fa2021-02-23 22:45:28 +0000209default_cpp_compiler = 'g++' if env['os'] not in ['android', 'macos'] else 'clang++'
210default_c_compiler = 'gcc' if env['os'] not in ['android', 'macos'] else 'clang'
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000211cpp_compiler = os.environ.get('CXX', default_cpp_compiler)
212c_compiler = os.environ.get('CC', default_c_compiler)
213
Jenkinsb3a371b2018-05-23 11:36:53 +0100214if env['os'] == 'android' and ( 'clang++' not in cpp_compiler or 'clang' not in c_compiler ):
ggardete2542c92018-06-29 17:01:01 +0200215 print( "WARNING: Only clang is officially supported to build the Compute Library for Android")
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000216
Jenkinsb3a371b2018-05-23 11:36:53 +0100217if 'clang++' in cpp_compiler:
Jenkins0e205f72019-11-28 16:53:35 +0000218 env.Append(CXXFLAGS = ['-Wno-vla-extension'])
219elif 'armclang' in cpp_compiler:
220 pass
Anthony Barbierdbdab852017-06-23 15:42:00 +0100221else:
Jenkins0e205f72019-11-28 16:53:35 +0000222 env.Append(CXXFLAGS = ['-Wlogical-op','-Wnoexcept','-Wstrict-null-sentinel'])
Anthony Barbierdbdab852017-06-23 15:42:00 +0100223
Jenkins7dcb9fa2021-02-23 22:45:28 +0000224if cpp_compiler == 'g++':
225 # Don't strip comments that could include markers
226 env.Append(CXXFLAGS = ['-C'])
227
Anthony Barbierdbdab852017-06-23 15:42:00 +0100228if env['cppthreads']:
229 env.Append(CPPDEFINES = [('ARM_COMPUTE_CPP_SCHEDULER', 1)])
230
231if env['openmp']:
Anthony Barbierdbdab852017-06-23 15:42:00 +0100232 env.Append(CPPDEFINES = [('ARM_COMPUTE_OPENMP_SCHEDULER', 1)])
233 env.Append(CXXFLAGS = ['-fopenmp'])
234 env.Append(LINKFLAGS = ['-fopenmp'])
235
Jenkins36ccc902020-02-21 11:10:48 +0000236# Validate and define state
237if env['estate'] == 'auto':
238 if 'v7a' in env['arch']:
239 env['estate'] = '32'
240 else:
241 env['estate'] = '64'
242
243# Map legacy arch
244if 'arm64' in env['arch']:
245 env['estate'] = '64'
246
247if 'v7a' in env['estate'] and env['estate'] == '64':
248 print("ERROR: armv7a architecture has only 32-bit execution state")
249 Exit(1)
250
Jenkins0e205f72019-11-28 16:53:35 +0000251# Add architecture specific flags
Anthony Barbierdbdab852017-06-23 15:42:00 +0100252prefix = ""
Jenkins36ccc902020-02-21 11:10:48 +0000253if 'v7a' in env['arch']:
Anthony Barbierdbdab852017-06-23 15:42:00 +0100254 env.Append(CXXFLAGS = ['-march=armv7-a', '-mthumb', '-mfpu=neon'])
Jenkinsf7399fd2021-05-18 15:04:27 +0100255 if (env['os'] == 'android' or env['os'] == 'tizen') and not 'hf' in env['arch']:
Anthony Barbierdbdab852017-06-23 15:42:00 +0100256 env.Append(CXXFLAGS = ['-mfloat-abi=softfp'])
Jenkinsb9abeae2018-11-22 11:58:08 +0000257 else:
Jenkins36ccc902020-02-21 11:10:48 +0000258 env.Append(CXXFLAGS = ['-mfloat-abi=hard'])
259elif 'v8' in env['arch']:
Jenkins7dcb9fa2021-02-23 22:45:28 +0000260 if 'sve2' in env['arch']:
261 env.Append(CXXFLAGS = ['-march=armv8.2-a+sve2+fp16+dotprod'])
Jenkinsc66f0e02021-08-20 08:52:20 +0000262 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVE2'])
Jenkins7dcb9fa2021-02-23 22:45:28 +0000263 elif 'sve' in env['arch']:
Jenkins36ccc902020-02-21 11:10:48 +0000264 env.Append(CXXFLAGS = ['-march=armv8.2-a+sve+fp16+dotprod'])
Jenkins7dcb9fa2021-02-23 22:45:28 +0000265 elif 'armv8r64' in env['arch']:
266 env.Append(CXXFLAGS = ['-march=armv8.4-a'])
267 elif 'v8.' in env['arch']:
Jenkinsb9abeae2018-11-22 11:58:08 +0000268 env.Append(CXXFLAGS = ['-march=armv8.2-a+fp16']) # explicitly enable fp16 extension otherwise __ARM_FEATURE_FP16_VECTOR_ARITHMETIC is undefined
Jenkins36ccc902020-02-21 11:10:48 +0000269 else:
270 env.Append(CXXFLAGS = ['-march=armv8-a'])
271
272 if 'v8.6-a' in env['arch']:
Jenkinsc66f0e02021-08-20 08:52:20 +0000273 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_I8MM', 'ARM_COMPUTE_ENABLE_BF16'])
Jenkins49b8f902020-11-27 12:49:11 +0000274 if "disable_mmla_fp" not in env['custom_options']:
Jenkinsc66f0e02021-08-20 08:52:20 +0000275 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVEF32MM'])
276 if 'v8.' in env['arch']:
277 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_FP16'])
278
Jenkins36ccc902020-02-21 11:10:48 +0000279elif 'x86' in env['arch']:
280 if env['estate'] == '32':
281 env.Append(CCFLAGS = ['-m32'])
282 env.Append(LINKFLAGS = ['-m32'])
283 else:
284 env.Append(CXXFLAGS = ['-fPIC'])
285 env.Append(CCFLAGS = ['-m64'])
286 env.Append(LINKFLAGS = ['-m64'])
287
288# Define toolchain
289prefix = ""
290if 'x86' not in env['arch']:
291 if env['estate'] == '32':
292 if env['os'] == 'linux':
293 prefix = "arm-linux-gnueabihf-" if 'v7' in env['arch'] else "armv8l-linux-gnueabihf-"
294 elif env['os'] == 'bare_metal':
295 prefix = "arm-eabi-"
296 elif env['os'] == 'android':
297 prefix = "arm-linux-androideabi-"
Jenkins6a7771e2020-05-28 11:28:36 +0100298 elif env['os'] == 'tizen':
299 prefix = "armv7l-tizen-linux-gnueabi-"
Jenkins36ccc902020-02-21 11:10:48 +0000300 elif env['estate'] == '64' and 'v8' in env['arch']:
301 if env['os'] == 'linux':
302 prefix = "aarch64-linux-gnu-"
303 elif env['os'] == 'bare_metal':
304 prefix = "aarch64-elf-"
305 elif env['os'] == 'android':
306 prefix = "aarch64-linux-android-"
Jenkins6a7771e2020-05-28 11:28:36 +0100307 elif env['os'] == 'tizen':
308 prefix = "aarch64-tizen-linux-gnu-"
Anthony Barbierdbdab852017-06-23 15:42:00 +0100309
Jenkinsc66f0e02021-08-20 08:52:20 +0000310if 'sve' in env['arch']:
311 env.Append(CXXFLAGS = ['-DENABLE_SVE', '-DARM_COMPUTE_ENABLE_SVE'])
312else:
313 env.Append(CXXFLAGS = ['-DENABLE_NEON', '-DARM_COMPUTE_ENABLE_NEON'])
314
Anthony Barbierdbdab852017-06-23 15:42:00 +0100315if env['build'] == 'native':
316 prefix = ""
317
Jenkins514be652019-02-28 12:25:18 +0000318if env["toolchain_prefix"] != "":
319 prefix = env["toolchain_prefix"]
320
Jenkins36ccc902020-02-21 11:10:48 +0000321compiler_prefix = prefix
322if env["compiler_prefix"] != "":
323 compiler_prefix = env["compiler_prefix"]
324
325env['CC'] = env['compiler_cache']+ " " + compiler_prefix + c_compiler
326env['CXX'] = env['compiler_cache']+ " " + compiler_prefix + cpp_compiler
Anthony Barbierdbdab852017-06-23 15:42:00 +0100327env['LD'] = prefix + "ld"
328env['AS'] = prefix + "as"
329env['AR'] = prefix + "ar"
330env['RANLIB'] = prefix + "ranlib"
Anthony Barbier46d59272017-05-04 09:15:15 +0100331
332if not GetOption("help"):
Anthony Barbierdbdab852017-06-23 15:42:00 +0100333 try:
Jenkins49b8f902020-11-27 12:49:11 +0000334 compiler_ver = subprocess.check_output(env['CXX'].split() + ["-dumpversion"]).decode().strip()
Anthony Barbierdbdab852017-06-23 15:42:00 +0100335 except OSError:
336 print("ERROR: Compiler '%s' not found" % env['CXX'])
337 Exit(1)
338
Jenkins0e205f72019-11-28 16:53:35 +0000339 if 'armclang' in cpp_compiler:
340 pass
341 elif 'clang++' not in cpp_compiler:
Anthony Barbierdbdab852017-06-23 15:42:00 +0100342 if env['arch'] == 'arm64-v8.2-a' and not version_at_least(compiler_ver, '6.2.1'):
ggardete2542c92018-06-29 17:01:01 +0200343 print("GCC 6.2.1 or newer is required to compile armv8.2-a code")
Anthony Barbierdbdab852017-06-23 15:42:00 +0100344 Exit(1)
345 elif env['arch'] == 'arm64-v8a' and not version_at_least(compiler_ver, '4.9'):
Jenkinsf7399fd2021-05-18 15:04:27 +0100346 print("GCC 4.9 or newer is required to compile Arm® Neon™ code for AArch64")
Anthony Barbierdbdab852017-06-23 15:42:00 +0100347 Exit(1)
348
349 if version_at_least(compiler_ver, '6.1'):
350 env.Append(CXXFLAGS = ['-Wno-ignored-attributes'])
351
352 if compiler_ver == '4.8.3':
353 env.Append(CXXFLAGS = ['-Wno-array-bounds'])
354
Jenkins49b8f902020-11-27 12:49:11 +0000355 if not version_at_least(compiler_ver, '7.0.0') and env['os'] == 'bare_metal':
356 env.Append(LINKFLAGS = ['-fstack-protector-strong'])
357
Jenkinsc66f0e02021-08-20 08:52:20 +0000358if env['fat_binary']:
359 if env['arch'] != 'armv8.2-a':
360 print("Currently fat binary is only supported with armv8.2-a")
361 Exit(1)
362 env.Append(CXXFLAGS = ['-DENABLE_NEON', '-DARM_COMPUTE_ENABLE_NEON',
363 '-DENABLE_SVE', '-DARM_COMPUTE_ENABLE_SVE',
364 '-DARM_COMPUTE_ENABLE_FP16', '-DARM_COMPUTE_ENABLE_BF16',
365 '-DARM_COMPUTE_ENABLE_I8MM', '-DARM_COMPUTE_ENABLE_SVEF32MM'])
366
Jenkins91ee4d02021-11-15 14:37:16 +0000367if env['high_priority'] and env['build_config']:
368 print("The high priority library cannot be built in conjuction with a user-specified build configuration")
369 Exit(1)
Jenkins7dcb9fa2021-02-23 22:45:28 +0000370
Jenkins91ee4d02021-11-15 14:37:16 +0000371if not env['high_priority'] and not env['build_config']:
372 env.Append(CPPDEFINES = ['ARM_COMPUTE_GRAPH_ENABLED'])
373
374data_types = []
375data_layouts = []
376
377# Set correct data types / layouts to build
378if env['high_priority']:
379 data_types = ['all']
380 data_layouts = ['all']
381elif env['build_config']:
382 data_types, data_layouts = read_build_config_json(env['build_config'])
383else:
384 data_types = env['data_type_support']
385 data_layouts = env['data_layout_support']
386
387env = update_data_type_layout_flags(env, data_types, data_layouts)
Jenkins49b8f902020-11-27 12:49:11 +0000388
Kaizen8938bd32017-09-28 14:38:23 +0100389if env['standalone']:
390 env.Append(CXXFLAGS = ['-fPIC'])
391 env.Append(LINKFLAGS = ['-static-libgcc','-static-libstdc++'])
392
Anthony Barbierdbdab852017-06-23 15:42:00 +0100393if env['Werror']:
394 env.Append(CXXFLAGS = ['-Werror'])
395
396if env['os'] == 'android':
397 env.Append(CPPDEFINES = ['ANDROID'])
Jenkins36ccc902020-02-21 11:10:48 +0000398 env.Append(LINKFLAGS = ['-pie', '-static-libstdc++', '-ldl'])
Anthony Barbierdbdab852017-06-23 15:42:00 +0100399elif env['os'] == 'bare_metal':
400 env.Append(LINKFLAGS = ['-static'])
401 env.Append(CXXFLAGS = ['-fPIC'])
Jenkins7dcb9fa2021-02-23 22:45:28 +0000402 if env['specs_file'] == "":
403 env.Append(LINKFLAGS = ['-specs=rdimon.specs'])
Anthony Barbierdbdab852017-06-23 15:42:00 +0100404 env.Append(CPPDEFINES = ['NO_MULTI_THREADING'])
Kaizen8938bd32017-09-28 14:38:23 +0100405 env.Append(CPPDEFINES = ['BARE_METAL'])
Jenkins49b8f902020-11-27 12:49:11 +0000406if env['os'] == 'linux' and env['arch'] == 'armv7a':
407 env.Append(CXXFLAGS = [ '-Wno-psabi' ])
Anthony Barbierdbdab852017-06-23 15:42:00 +0100408
Jenkins7dcb9fa2021-02-23 22:45:28 +0000409if env['specs_file'] != "":
410 env.Append(LINKFLAGS = ['-specs='+env['specs_file']])
411
Jenkinsf7399fd2021-05-18 15:04:27 +0100412if env['neon']:
413 env.Append(CPPDEFINES = ['ARM_COMPUTE_CPU_ENABLED'])
414
Anthony Barbierdbdab852017-06-23 15:42:00 +0100415if env['opencl']:
Jenkinsf7399fd2021-05-18 15:04:27 +0100416 env.Append(CPPDEFINES = ['ARM_COMPUTE_OPENCL_ENABLED'])
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000417 if env['os'] in ['bare_metal'] or env['standalone']:
Jenkinsb3a371b2018-05-23 11:36:53 +0100418 print("Cannot link OpenCL statically, which is required for bare metal / standalone builds")
Anthony Barbierdbdab852017-06-23 15:42:00 +0100419 Exit(1)
420
Jenkinsb3a371b2018-05-23 11:36:53 +0100421if env["os"] not in ["android", "bare_metal"] and (env['opencl'] or env['cppthreads']):
422 env.Append(LIBS = ['pthread'])
423
Jenkinsf7399fd2021-05-18 15:04:27 +0100424if env['opencl']:
Anthony Barbierdbdab852017-06-23 15:42:00 +0100425 if env['embed_kernels']:
426 env.Append(CPPDEFINES = ['EMBEDDED_KERNELS'])
Jenkins7dcb9fa2021-02-23 22:45:28 +0000427 if env['compress_kernels']:
428 env.Append(CPPDEFINES = ['ARM_COMPUTE_COMPRESSED_KERNELS'])
429 env.Append(LIBS = ['z'])
Anthony Barbierdbdab852017-06-23 15:42:00 +0100430
431if env['debug']:
432 env['asserts'] = True
433 env.Append(CXXFLAGS = ['-O0','-g','-gdwarf-2'])
434 env.Append(CPPDEFINES = ['ARM_COMPUTE_DEBUG_ENABLED'])
435else:
Jenkins975dfe12019-09-02 11:47:54 +0100436 env.Append(CXXFLAGS = ['-O3'])
Anthony Barbierdbdab852017-06-23 15:42:00 +0100437
438if env['asserts']:
439 env.Append(CPPDEFINES = ['ARM_COMPUTE_ASSERTS_ENABLED'])
Kaizen8938bd32017-09-28 14:38:23 +0100440 env.Append(CXXFLAGS = ['-fstack-protector-strong'])
Anthony Barbierdbdab852017-06-23 15:42:00 +0100441
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000442if env['logging']:
443 env.Append(CPPDEFINES = ['ARM_COMPUTE_LOGGING_ENABLED'])
444
Anthony Barbierdbdab852017-06-23 15:42:00 +0100445env.Append(CPPPATH = ['#/include', "#"])
446env.Append(CXXFLAGS = env['extra_cxx_flags'])
Jenkinsb9abeae2018-11-22 11:58:08 +0000447env.Append(LINKFLAGS = env['extra_link_flags'])
448
449Default( install_include("arm_compute"))
450Default( install_include("support"))
Jenkins4ba87db2019-05-23 17:11:51 +0100451Default( install_include("utils"))
452for dirname in os.listdir("./include"):
453 Default( install_include("include/%s" % dirname))
Anthony Barbierdbdab852017-06-23 15:42:00 +0100454
Anthony Barbierdbdab852017-06-23 15:42:00 +0100455Export('version_at_least')
456
Jenkinsb9abeae2018-11-22 11:58:08 +0000457SConscript('./SConscript', variant_dir=build_path, duplicate=0)
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000458
Jenkins91ee4d02021-11-15 14:37:16 +0000459if env['examples'] and (env['build_config'] or env['high_priority']):
460 print("WARNING: Building examples for selected operators not supported. Use examples=0")
461 Return()
462
Jenkins36ccc902020-02-21 11:10:48 +0000463if env['examples'] and env['exceptions']:
464 if env['os'] == 'bare_metal' and env['arch'] == 'armv7a':
465 print("WARNING: Building examples for bare metal and armv7a is not supported. Use examples=0")
466 Return()
Jenkinsb9abeae2018-11-22 11:58:08 +0000467 SConscript('./examples/SConscript', variant_dir='%s/examples' % build_path, duplicate=0)
Anthony Barbierdbdab852017-06-23 15:42:00 +0100468
Jenkins36ccc902020-02-21 11:10:48 +0000469if env['exceptions']:
Jenkins91ee4d02021-11-15 14:37:16 +0000470 if env['build_config'] or env['high_priority']:
471 print("WARNING: Building tests for selected operators not supported")
472 Return()
Jenkins36ccc902020-02-21 11:10:48 +0000473 if env['os'] == 'bare_metal' and env['arch'] == 'armv7a':
474 print("WARNING: Building tests for bare metal and armv7a is not supported")
475 Return()
Jenkinsb9abeae2018-11-22 11:58:08 +0000476 SConscript('./tests/SConscript', variant_dir='%s/tests' % build_path, duplicate=0)