blob: ec669f246e0cf34b5420027bcf57236f2524d967 [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
Freddie Liardet487d3902021-09-21 12:36:43 +010044def 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 Barbier6ff3b192017-09-04 18:44:23 +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),
ramelg0193d6cf02021-09-23 13:59:22 +010092 BoolVariable("logging", "Enable Logging", False),
Georgios Pinitasf2cdce32019-12-09 18:35:57 +000093 EnumVariable("arch", "Target Architecture", "armv7a",
Slava Barinovdb0e2c82021-04-07 11:23:27 +030094 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 +000095 "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 +000096 EnumVariable("estate", "Execution State", "auto", allowed_values=("auto", "32", "64")),
Kevin Lo7195f712022-01-07 15:46:02 +080097 EnumVariable("os", "Target OS", "linux", allowed_values=("linux", "android", "tizen", "macos", "bare_metal", "openbsd")),
Anthony Barbier6a3daf12018-02-19 17:24:27 +000098 EnumVariable("build", "Build type", "cross_compile", allowed_values=("native", "cross_compile", "embed_only")),
Anthony Barbier6ff3b192017-09-04 18:44:23 +010099 BoolVariable("examples", "Build example programs", True),
SiCong Li8b4c7302019-09-19 12:18:15 +0100100 BoolVariable("gemm_tuner", "Build gemm_tuner programs", True),
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100101 BoolVariable("Werror", "Enable/disable the -Werror compilation flag", True),
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200102 BoolVariable("multi_isa", "Build Multi ISA binary version of library. Note works only for armv8.2-a", False),
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100103 BoolVariable("standalone", "Builds the tests as standalone executables, links statically with libgcc, libstdc++ and libarm_compute", False),
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100104 BoolVariable("opencl", "Enable OpenCL support", True),
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +0000105 BoolVariable("neon", "Enable Arm® Neon™ support", False),
Anthony Barbiercc0a80b2017-12-15 11:37:29 +0000106 BoolVariable("embed_kernels", "Embed OpenCL kernels and OpenGL ES compute shaders in library binary", True),
Georgios Pinitasea857272021-01-22 05:47:37 +0000107 BoolVariable("compress_kernels", "Compress embedded OpenCL kernels in library binary. Note embed_kernels should be enabled", False),
Anthony Barbier6ff3b192017-09-04 18:44:23 +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),
111 PathVariable("build_dir", "Specify sub-folder for the build", ".", PathVariable.PathAccept),
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000112 PathVariable("install_dir", "Specify sub-folder for the install", "", PathVariable.PathAccept),
Michalis Spyrou323ce0f2018-11-30 16:30:43 +0000113 BoolVariable("exceptions", "Enable/disable C++ exception support", True),
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100114 BoolVariable("high_priority", "Generate a library containing only the high priority operators", False),
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100115 PathVariable("linker_script", "Use an external linker script", "", PathVariable.PathAccept),
Michele Di Giorgio72610dc2020-11-18 15:29:08 +0000116 PathVariable("external_tests_dir", "Add examples, benchmarks and tests to the tests suite", "", PathVariable.PathAccept),
Giorgio Arena232c4522022-03-03 10:09:01 +0000117 BoolVariable("experimental_dynamic_fusion", "Build the experimental dynamic fusion files", False),
Georgios Pinitas49c6ced2020-09-21 17:16:09 +0100118 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 +0000119 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 +0000120 ListVariable("data_layout_support", "Enable a list of data layout to support", "all", ["nhwc", "nchw"]),
Anthony Barbier149de5b2018-12-06 10:27:37 +0000121 ("toolchain_prefix", "Override the toolchain prefix", ""),
alered01d8872c12020-02-10 11:29:45 +0000122 ("compiler_prefix", "Override the compiler prefix", ""),
Anthony Barbier7390e052018-03-13 09:29:41 +0000123 ("extra_cxx_flags", "Extra CXX flags to be appended to the build command", ""),
Georgios Pinitas421405b2018-10-26 19:05:32 +0100124 ("extra_link_flags", "Extra LD flags to be appended to the build command", ""),
Manuel Bottinie5a9ad82020-11-18 16:22:16 +0000125 ("compiler_cache", "Command to prefix to the C and C++ compiler (e.g ccache)", ""),
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100126 ("specs_file", "Specs file to use (e.g. rdimon.specs)", ""),
127 ("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 +0100128)
129
Motti Gondabif76a5022021-12-21 13:19:29 +0200130
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100131env = Environment(platform="posix", variables=vars, ENV = os.environ)
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100132build_path = env['build_dir']
133# If build_dir is a relative path then add a #build/ prefix:
134if not env['build_dir'].startswith('/'):
135 SConsignFile('build/%s/.scons' % build_path)
136 build_path = "#build/%s" % build_path
137else:
138 SConsignFile('%s/.scons' % build_path)
139
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000140install_path = env['install_dir']
141#If the install_dir is a relative path then assume it's from inside build_dir
142if not env['install_dir'].startswith('/') and install_path != "":
143 install_path = "%s/%s" % (build_path, install_path)
144
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100145env.Append(LIBPATH = [build_path])
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000146Export('env')
147Export('vars')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100148
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000149def install_lib( lib ):
150 # If there is no install folder, then there is nothing to do:
151 if install_path == "":
152 return lib
153 return env.Install( "%s/lib/" % install_path, lib)
154def install_bin( bin ):
155 # If there is no install folder, then there is nothing to do:
156 if install_path == "":
157 return bin
158 return env.Install( "%s/bin/" % install_path, bin)
159def install_include( inc ):
160 if install_path == "":
161 return inc
162 return env.Install( "%s/include/" % install_path, inc)
163
164Export('install_lib')
165Export('install_bin')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100166
167Help(vars.GenerateHelpText(env))
168
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100169if env['linker_script'] and env['os'] != 'bare_metal':
170 print("Linker script is only supported for bare_metal builds")
171 Exit(1)
172
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000173if env['build'] == "embed_only":
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100174 SConscript('./SConscript', variant_dir=build_path, duplicate=0)
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000175 Return()
176
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100177if env['neon'] and 'x86' in env['arch']:
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +0000178 print("Cannot compile Arm® Neon™ for x86")
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100179 Exit(1)
180
181if env['set_soname'] and not version_at_least(SCons.__version__, "2.4"):
ggardet767c9f72018-06-29 17:01:01 +0200182 print("Setting the library's SONAME / SHLIBVERSION requires SCons 2.4 or above")
183 print("Update your version of SCons or use set_soname=0")
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100184 Exit(1)
185
186if env['os'] == 'bare_metal':
187 if env['cppthreads'] or env['openmp']:
188 print("ERROR: OpenMP and C++11 threads not supported in bare_metal. Use cppthreads=0 openmp=0")
189 Exit(1)
190
Georgios Pinitasea857272021-01-22 05:47:37 +0000191if env['opencl'] and env['embed_kernels'] and env['compress_kernels'] and env['os'] not in ['android']:
192 print("Compressed kernels are supported only for android builds")
193 Exit(1)
194
Michalis Spyrou323ce0f2018-11-30 16:30:43 +0000195if not env['exceptions']:
Manuel Bottiniceaa0bf2021-02-16 15:15:19 +0000196 if env['opencl']:
197 print("ERROR: OpenCL is not supported when building without exceptions. Use opencl=0")
Michalis Spyrou323ce0f2018-11-30 16:30:43 +0000198 Exit(1)
199
200 env.Append(CPPDEFINES = ['ARM_COMPUTE_EXCEPTIONS_DISABLED'])
201 env.Append(CXXFLAGS = ['-fno-exceptions'])
202
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100203env.Append(CXXFLAGS = ['-Wall','-DARCH_ARM',
Michalis Spyrou7c60c992019-10-10 14:33:47 +0100204 '-Wextra','-pedantic','-Wdisabled-optimization','-Wformat=2',
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100205 '-Winit-self','-Wstrict-overflow=2','-Wswitch-default',
Georgios Pinitas40f51a62020-11-21 03:04:18 +0000206 '-std=c++14','-Woverloaded-virtual', '-Wformat-security',
Michalis Spyroufae513c2019-10-16 17:41:33 +0100207 '-Wctor-dtor-privacy','-Wsign-promo','-Weffc++','-Wno-overlength-strings'])
Isabella Gottardib28f29d2017-11-09 17:05:07 +0000208
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100209env.Append(CPPDEFINES = ['_GLIBCXX_USE_NANOSLEEP'])
210
Kevin Lo7195f712022-01-07 15:46:02 +0800211default_cpp_compiler = 'g++' if env['os'] not in ['android', 'macos', 'openbsd'] else 'clang++'
212default_c_compiler = 'gcc' if env['os'] not in ['android', 'macos', 'openbsd'] else 'clang'
Anthony Barbiera026e982018-01-18 10:57:52 +0000213cpp_compiler = os.environ.get('CXX', default_cpp_compiler)
214c_compiler = os.environ.get('CC', default_c_compiler)
215
Anthony Barbierdd669372018-03-01 17:08:54 +0000216if env['os'] == 'android' and ( 'clang++' not in cpp_compiler or 'clang' not in c_compiler ):
ggardet767c9f72018-06-29 17:01:01 +0200217 print( "WARNING: Only clang is officially supported to build the Compute Library for Android")
Anthony Barbiera026e982018-01-18 10:57:52 +0000218
Anthony Barbierdd669372018-03-01 17:08:54 +0000219if 'clang++' in cpp_compiler:
Michalis Spyrou7c60c992019-10-10 14:33:47 +0100220 env.Append(CXXFLAGS = ['-Wno-vla-extension'])
Georgios Pinitase874ef92019-09-09 17:40:33 +0100221elif 'armclang' in cpp_compiler:
222 pass
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100223else:
Giorgio Arenad56d94d2022-02-07 16:19:55 +0000224 env.Append(CXXFLAGS = ['-Wlogical-op','-Wnoexcept','-Wstrict-null-sentinel', '-Wno-misleading-indentation'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100225
SiCongLi410e21e2020-12-11 15:07:53 +0000226if cpp_compiler == 'g++':
227 # Don't strip comments that could include markers
228 env.Append(CXXFLAGS = ['-C'])
229
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100230if env['cppthreads']:
231 env.Append(CPPDEFINES = [('ARM_COMPUTE_CPP_SCHEDULER', 1)])
232
233if env['openmp']:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100234 env.Append(CPPDEFINES = [('ARM_COMPUTE_OPENMP_SCHEDULER', 1)])
235 env.Append(CXXFLAGS = ['-fopenmp'])
236 env.Append(LINKFLAGS = ['-fopenmp'])
237
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000238# Validate and define state
239if env['estate'] == 'auto':
240 if 'v7a' in env['arch']:
241 env['estate'] = '32'
242 else:
243 env['estate'] = '64'
244
245# Map legacy arch
246if 'arm64' in env['arch']:
247 env['estate'] = '64'
248
249if 'v7a' in env['estate'] and env['estate'] == '64':
250 print("ERROR: armv7a architecture has only 32-bit execution state")
251 Exit(1)
252
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200253env.Append(CPPDEFINES = ['ENABLE_NEON', 'ARM_COMPUTE_ENABLE_NEON'])
254
Motti Gondabif76a5022021-12-21 13:19:29 +0200255if 'sve' in env['arch']:
256 env.Append(CPPDEFINES = ['ENABLE_SVE', 'ARM_COMPUTE_ENABLE_SVE'])
257 if 'sve2' in env['arch']:
258 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVE2'])
Motti Gondabif76a5022021-12-21 13:19:29 +0200259
Georgios Pinitase874ef92019-09-09 17:40:33 +0100260# Add architecture specific flags
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100261prefix = ""
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200262if env['multi_isa']:
263 # assert arch version is v8
264 if 'v8' not in env['arch']:
265 print("Currently Multi ISA binary is only supported for arm v8 family")
266 Exit(1)
Georgios Pinitas94672fb2020-01-22 18:36:27 +0000267
Georgios Pinitas8e2f64f2021-07-28 13:18:46 +0100268 if 'v8.6-a' in env['arch']:
Georgios Pinitas49c6ced2020-09-21 17:16:09 +0100269 if "disable_mmla_fp" not in env['custom_options']:
Michalis Spyrou20fca522021-06-07 14:23:57 +0100270 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVEF32MM'])
Georgios Pinitas8e2f64f2021-07-28 13:18:46 +0100271
Giorgio Arena73fa0a72022-02-10 15:06:51 +0000272 env.Append(CXXFLAGS = ['-march=armv8.2-a+fp16']) # explicitly enable fp16 extension otherwise __ARM_FEATURE_FP16_VECTOR_ARITHMETIC is undefined
273
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200274else: # NONE "multi_isa" builds
275
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200276 if 'v7a' in env['arch']:
277 env.Append(CXXFLAGS = ['-march=armv7-a', '-mthumb', '-mfpu=neon'])
278 if (env['os'] == 'android' or env['os'] == 'tizen') and not 'hf' in env['arch']:
279 env.Append(CXXFLAGS = ['-mfloat-abi=softfp'])
280 else:
281 env.Append(CXXFLAGS = ['-mfloat-abi=hard'])
282 elif 'v8' in env['arch']:
283 # Preserve the V8 archs for non-multi-ISA variants
284 if 'sve2' in env['arch']:
285 env.Append(CXXFLAGS = ['-march=armv8.2-a+sve2+fp16+dotprod'])
286 elif 'sve' in env['arch']:
287 env.Append(CXXFLAGS = ['-march=armv8.2-a+sve+fp16+dotprod'])
288 elif 'armv8r64' in env['arch']:
289 env.Append(CXXFLAGS = ['-march=armv8.4-a'])
290 elif 'v8.' in env['arch']:
291 env.Append(CXXFLAGS = ['-march=armv8.2-a+fp16']) # explicitly enable fp16 extension otherwise __ARM_FEATURE_FP16_VECTOR_ARITHMETIC is undefined
292 else:
293 env.Append(CXXFLAGS = ['-march=armv8-a'])
294
295 if 'v8.6-a' in env['arch']:
296 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_I8MM', 'ARM_COMPUTE_ENABLE_BF16'])
297 if "disable_mmla_fp" not in env['custom_options']:
298 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVEF32MM'])
299 if 'v8.' in env['arch']:
300 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_FP16'])
301
302 elif 'x86' in env['arch']:
303 if env['estate'] == '32':
304 env.Append(CCFLAGS = ['-m32'])
305 env.Append(LINKFLAGS = ['-m32'])
306 else:
307 env.Append(CXXFLAGS = ['-fPIC'])
308 env.Append(CCFLAGS = ['-m64'])
309 env.Append(LINKFLAGS = ['-m64'])
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000310
311# Define toolchain
312prefix = ""
313if 'x86' not in env['arch']:
314 if env['estate'] == '32':
315 if env['os'] == 'linux':
316 prefix = "arm-linux-gnueabihf-" if 'v7' in env['arch'] else "armv8l-linux-gnueabihf-"
317 elif env['os'] == 'bare_metal':
318 prefix = "arm-eabi-"
319 elif env['os'] == 'android':
320 prefix = "arm-linux-androideabi-"
Inki Dae51a95582020-03-23 08:29:02 +0900321 elif env['os'] == 'tizen':
322 prefix = "armv7l-tizen-linux-gnueabi-"
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000323 elif env['estate'] == '64' and 'v8' in env['arch']:
324 if env['os'] == 'linux':
325 prefix = "aarch64-linux-gnu-"
326 elif env['os'] == 'bare_metal':
327 prefix = "aarch64-elf-"
328 elif env['os'] == 'android':
329 prefix = "aarch64-linux-android-"
Inki Dae51a95582020-03-23 08:29:02 +0900330 elif env['os'] == 'tizen':
331 prefix = "aarch64-tizen-linux-gnu-"
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100332
333if env['build'] == 'native':
334 prefix = ""
335
Anthony Barbier149de5b2018-12-06 10:27:37 +0000336if env["toolchain_prefix"] != "":
337 prefix = env["toolchain_prefix"]
338
alered01d8872c12020-02-10 11:29:45 +0000339compiler_prefix = prefix
340if env["compiler_prefix"] != "":
341 compiler_prefix = env["compiler_prefix"]
342
343env['CC'] = env['compiler_cache']+ " " + compiler_prefix + c_compiler
344env['CXX'] = env['compiler_cache']+ " " + compiler_prefix + cpp_compiler
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100345env['LD'] = prefix + "ld"
346env['AS'] = prefix + "as"
347env['AR'] = prefix + "ar"
348env['RANLIB'] = prefix + "ranlib"
349
350if not GetOption("help"):
351 try:
SiCong Li3b9a5642020-10-16 12:10:15 +0100352 compiler_ver = subprocess.check_output(env['CXX'].split() + ["-dumpversion"]).decode().strip()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100353 except OSError:
354 print("ERROR: Compiler '%s' not found" % env['CXX'])
355 Exit(1)
356
Georgios Pinitase874ef92019-09-09 17:40:33 +0100357 if 'armclang' in cpp_compiler:
358 pass
359 elif 'clang++' not in cpp_compiler:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100360 if env['arch'] == 'arm64-v8.2-a' and not version_at_least(compiler_ver, '6.2.1'):
ggardet767c9f72018-06-29 17:01:01 +0200361 print("GCC 6.2.1 or newer is required to compile armv8.2-a code")
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100362 Exit(1)
363 elif env['arch'] == 'arm64-v8a' and not version_at_least(compiler_ver, '4.9'):
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +0000364 print("GCC 4.9 or newer is required to compile Arm® Neon™ code for AArch64")
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100365 Exit(1)
366
367 if version_at_least(compiler_ver, '6.1'):
368 env.Append(CXXFLAGS = ['-Wno-ignored-attributes'])
369
370 if compiler_ver == '4.8.3':
371 env.Append(CXXFLAGS = ['-Wno-array-bounds'])
372
Michalis Spyroucfac3052020-10-14 12:06:28 +0100373 if not version_at_least(compiler_ver, '7.0.0') and env['os'] == 'bare_metal':
374 env.Append(LINKFLAGS = ['-fstack-protector-strong'])
375
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100376if env['high_priority'] and env['build_config']:
SiCongLidc85d782021-12-17 13:22:55 +0000377 print("The high priority library cannot be built in conjunction with a user-specified build configuration")
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100378 Exit(1)
379
380if not env['high_priority'] and not env['build_config']:
381 env.Append(CPPDEFINES = ['ARM_COMPUTE_GRAPH_ENABLED'])
382
Freddie Liardet487d3902021-09-21 12:36:43 +0100383data_types = []
384data_layouts = []
Georgios Pinitasff4fca02020-10-02 21:00:00 +0100385
Freddie Liardet487d3902021-09-21 12:36:43 +0100386# Set correct data types / layouts to build
387if env['high_priority']:
388 data_types = ['all']
389 data_layouts = ['all']
390elif env['build_config']:
391 data_types, data_layouts = read_build_config_json(env['build_config'])
392else:
393 data_types = env['data_type_support']
394 data_layouts = env['data_layout_support']
395
396env = update_data_type_layout_flags(env, data_types, data_layouts)
Sheri Zhang79144a62021-02-08 17:43:04 +0000397
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100398if env['standalone']:
399 env.Append(CXXFLAGS = ['-fPIC'])
Anthony Barbier665c89b2018-07-16 11:40:09 +0100400 env.Append(LINKFLAGS = ['-static-libgcc','-static-libstdc++'])
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100401
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100402if env['Werror']:
403 env.Append(CXXFLAGS = ['-Werror'])
404
405if env['os'] == 'android':
406 env.Append(CPPDEFINES = ['ANDROID'])
Michalis Spyrou2d22c3f2020-02-12 14:50:19 +0000407 env.Append(LINKFLAGS = ['-pie', '-static-libstdc++', '-ldl'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100408elif env['os'] == 'bare_metal':
409 env.Append(LINKFLAGS = ['-static'])
410 env.Append(CXXFLAGS = ['-fPIC'])
Manuel Bottinie5a9ad82020-11-18 16:22:16 +0000411 if env['specs_file'] == "":
412 env.Append(LINKFLAGS = ['-specs=rdimon.specs'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100413 env.Append(CPPDEFINES = ['NO_MULTI_THREADING'])
Michalis Spyrou07781ac2017-08-31 15:11:41 +0100414 env.Append(CPPDEFINES = ['BARE_METAL'])
Manuel Bottini827817e2020-11-19 12:12:06 +0000415if env['os'] == 'linux' and env['arch'] == 'armv7a':
416 env.Append(CXXFLAGS = [ '-Wno-psabi' ])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100417
Manuel Bottinie5a9ad82020-11-18 16:22:16 +0000418if env['specs_file'] != "":
419 env.Append(LINKFLAGS = ['-specs='+env['specs_file']])
420
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000421if env['neon']:
422 env.Append(CPPDEFINES = ['ARM_COMPUTE_CPU_ENABLED'])
423
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100424if env['opencl']:
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000425 env.Append(CPPDEFINES = ['ARM_COMPUTE_OPENCL_ENABLED'])
Georgios Pinitase6032da2017-10-26 14:13:35 +0100426 if env['os'] in ['bare_metal'] or env['standalone']:
Anthony Barbier5f0124d2018-04-13 14:05:34 +0100427 print("Cannot link OpenCL statically, which is required for bare metal / standalone builds")
428 Exit(1)
429
Anthony Barbier9fb0cac2018-04-20 15:46:21 +0100430if env["os"] not in ["android", "bare_metal"] and (env['opencl'] or env['cppthreads']):
431 env.Append(LIBS = ['pthread'])
432
Kevin Lo7195f712022-01-07 15:46:02 +0800433if env['os'] == 'openbsd':
434 env.Append(LIBS = ['c'])
435 env.Append(CXXFLAGS = ['-fPIC'])
436
Manuel Bottiniceaa0bf2021-02-16 15:15:19 +0000437if env['opencl']:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100438 if env['embed_kernels']:
439 env.Append(CPPDEFINES = ['EMBEDDED_KERNELS'])
Georgios Pinitasea857272021-01-22 05:47:37 +0000440 if env['compress_kernels']:
441 env.Append(CPPDEFINES = ['ARM_COMPUTE_COMPRESSED_KERNELS'])
442 env.Append(LIBS = ['z'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100443
444if env['debug']:
445 env['asserts'] = True
446 env.Append(CXXFLAGS = ['-O0','-g','-gdwarf-2'])
447 env.Append(CPPDEFINES = ['ARM_COMPUTE_DEBUG_ENABLED'])
448else:
Ramana Radhakrishnand176d542019-07-04 11:38:45 +0100449 env.Append(CXXFLAGS = ['-O3'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100450
451if env['asserts']:
452 env.Append(CPPDEFINES = ['ARM_COMPUTE_ASSERTS_ENABLED'])
Moritz Pflanzer8b74c782017-09-14 14:33:20 +0100453 env.Append(CXXFLAGS = ['-fstack-protector-strong'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100454
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +0100455if env['logging']:
456 env.Append(CPPDEFINES = ['ARM_COMPUTE_LOGGING_ENABLED'])
457
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100458env.Append(CPPPATH = ['#/include', "#"])
459env.Append(CXXFLAGS = env['extra_cxx_flags'])
Georgios Pinitas421405b2018-10-26 19:05:32 +0100460env.Append(LINKFLAGS = env['extra_link_flags'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100461
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000462Default( install_include("arm_compute"))
Anthony Barbier10565952018-11-15 09:50:06 +0000463Default( install_include("support"))
Michele Di Giorgio6afea902019-04-03 11:40:20 +0100464Default( install_include("utils"))
465for dirname in os.listdir("./include"):
466 Default( install_include("include/%s" % dirname))
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000467
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100468Export('version_at_least')
469
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100470SConscript('./SConscript', variant_dir=build_path, duplicate=0)
Anthony Barbier6c0348f2017-11-10 18:32:38 +0000471
Freddie Liardet487d3902021-09-21 12:36:43 +0100472if env['examples'] and (env['build_config'] or env['high_priority']):
473 print("WARNING: Building examples for selected operators not supported. Use examples=0")
474 Return()
475
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100476if env['examples'] and env['exceptions']:
477 if env['os'] == 'bare_metal' and env['arch'] == 'armv7a':
Michalis Spyrou35f35a62019-12-23 11:29:52 +0000478 print("WARNING: Building examples for bare metal and armv7a is not supported. Use examples=0")
479 Return()
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100480 SConscript('./examples/SConscript', variant_dir='%s/examples' % build_path, duplicate=0)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100481
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100482if env['exceptions']:
Freddie Liardet487d3902021-09-21 12:36:43 +0100483 if env['build_config'] or env['high_priority']:
484 print("WARNING: Building tests for selected operators not supported")
485 Return()
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100486 if env['os'] == 'bare_metal' and env['arch'] == 'armv7a':
487 print("WARNING: Building tests for bare metal and armv7a is not supported")
488 Return()
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100489 SConscript('./tests/SConscript', variant_dir='%s/tests' % build_path, duplicate=0)
Motti Gondabif76a5022021-12-21 13:19:29 +0200490
491# Unknown variables are not allowed
492# Note: we must delay the call of UnknownVariables until after
493# we have applied the Variables object to the construction environment
494unknown = vars.UnknownVariables()
495if unknown:
496 print("Unknown variables: %s" % " ".join(unknown.keys()))
Ramy Elgammal451c3092022-02-01 23:01:27 +0000497 Exit(1)