blob: be438e05f39ee7f2a6285ef41bb88731a5b20c69 [file] [log] [blame]
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +00001# -*- coding: utf-8 -*-
2
Pablo Tello4e66d702022-03-07 18:20:12 +00003# Copyright (c) 2016-2022 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
Giorgio Arenab83e6722022-03-24 14:23:07 +000028from subprocess import check_output
Anthony Barbier6ff3b192017-09-04 18:44:23 +010029
30def version_at_least(version, required):
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031
Michalis Spyroucfac3052020-10-14 12:06:28 +010032 version_list = version.split('.')
33 required_list = required.split('.')
34 end = min(len(version_list), len(required_list))
35 for i in range(0, end):
36 if int(version_list[i]) < int(required_list[i]):
Anthony Barbier6ff3b192017-09-04 18:44:23 +010037 return False
Michalis Spyroucfac3052020-10-14 12:06:28 +010038 elif int(version_list[i]) > int(required_list[i]):
Anthony Barbier6ff3b192017-09-04 18:44:23 +010039 return True
40
41 return True
42
Freddie Liardet487d3902021-09-21 12:36:43 +010043def read_build_config_json(build_config):
44 build_config_contents = {}
45 custom_types = []
46 custom_layouts = []
47 if os.path.isfile(build_config):
48 with open(build_config) as f:
49 try:
50 build_config_contents = json.load(f)
51 except:
52 print("Warning: Build configuration file is of invalid JSON format!")
53 else:
54 try:
55 build_config_contents = json.loads(build_config)
56 except:
57 print("Warning: Build configuration string is of invalid JSON format!")
58 if build_config_contents:
59 custom_types = build_config_contents.get("data_types", [])
60 custom_layouts = build_config_contents.get("data_layouts", [])
61 return custom_types, custom_layouts
62
63def update_data_type_layout_flags(env, data_types, data_layouts):
64 # Manage data-types
65 if any(i in data_types for i in ['all', 'fp16']):
66 env.Append(CXXFLAGS = ['-DENABLE_FP16_KERNELS'])
67 if any(i in data_types for i in ['all', 'fp32']):
68 env.Append(CXXFLAGS = ['-DENABLE_FP32_KERNELS'])
69 if any(i in data_types for i in ['all', 'qasymm8']):
70 env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_KERNELS'])
71 if any(i in data_types for i in ['all', 'qasymm8_signed']):
72 env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_SIGNED_KERNELS'])
73 if any(i in data_types for i in ['all', 'qsymm16']):
74 env.Append(CXXFLAGS = ['-DENABLE_QSYMM16_KERNELS'])
75 if any(i in data_types for i in ['all', 'integer']):
76 env.Append(CXXFLAGS = ['-DENABLE_INTEGER_KERNELS'])
77
78 # Manage data-layouts
79 if any(i in data_layouts for i in ['all', 'nhwc']):
80 env.Append(CXXFLAGS = ['-DENABLE_NHWC_KERNELS'])
81 if any(i in data_layouts for i in ['all', 'nchw']):
82 env.Append(CXXFLAGS = ['-DENABLE_NCHW_KERNELS'])
83
84 return env
85
86
Anthony Barbier6ff3b192017-09-04 18:44:23 +010087vars = Variables("scons")
88vars.AddVariables(
89 BoolVariable("debug", "Debug", False),
90 BoolVariable("asserts", "Enable asserts (this flag is forced to 1 for debug=1)", False),
ramelg0193d6cf02021-09-23 13:59:22 +010091 BoolVariable("logging", "Enable Logging", False),
Georgios Pinitasf2cdce32019-12-09 18:35:57 +000092 EnumVariable("arch", "Target Architecture", "armv7a",
Slava Barinovdb0e2c82021-04-07 11:23:27 +030093 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 +000094 "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 +000095 EnumVariable("estate", "Execution State", "auto", allowed_values=("auto", "32", "64")),
Pablo Tello4e66d702022-03-07 18:20:12 +000096 EnumVariable("os", "Target OS", "linux", allowed_values=("linux", "android", "tizen", "macos", "bare_metal", "openbsd","windows")),
Anthony Barbier6a3daf12018-02-19 17:24:27 +000097 EnumVariable("build", "Build type", "cross_compile", allowed_values=("native", "cross_compile", "embed_only")),
Anthony Barbier6ff3b192017-09-04 18:44:23 +010098 BoolVariable("examples", "Build example programs", True),
SiCong Li8b4c7302019-09-19 12:18:15 +010099 BoolVariable("gemm_tuner", "Build gemm_tuner programs", True),
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100100 BoolVariable("Werror", "Enable/disable the -Werror compilation flag", True),
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200101 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 +0100102 BoolVariable("standalone", "Builds the tests as standalone executables, links statically with libgcc, libstdc++ and libarm_compute", False),
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100103 BoolVariable("opencl", "Enable OpenCL support", True),
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +0000104 BoolVariable("neon", "Enable Arm® Neon™ support", False),
Anthony Barbiercc0a80b2017-12-15 11:37:29 +0000105 BoolVariable("embed_kernels", "Embed OpenCL kernels and OpenGL ES compute shaders in library binary", True),
Georgios Pinitasea857272021-01-22 05:47:37 +0000106 BoolVariable("compress_kernels", "Compress embedded OpenCL kernels in library binary. Note embed_kernels should be enabled", False),
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100107 BoolVariable("set_soname", "Set the library's soname and shlibversion (requires SCons 2.4 or above)", False),
108 BoolVariable("openmp", "Enable OpenMP backend", False),
109 BoolVariable("cppthreads", "Enable C++11 threads backend", True),
110 PathVariable("build_dir", "Specify sub-folder for the build", ".", PathVariable.PathAccept),
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000111 PathVariable("install_dir", "Specify sub-folder for the install", "", PathVariable.PathAccept),
Michalis Spyrou323ce0f2018-11-30 16:30:43 +0000112 BoolVariable("exceptions", "Enable/disable C++ exception support", True),
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100113 BoolVariable("high_priority", "Generate a library containing only the high priority operators", False),
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100114 PathVariable("linker_script", "Use an external linker script", "", PathVariable.PathAccept),
Michele Di Giorgio72610dc2020-11-18 15:29:08 +0000115 PathVariable("external_tests_dir", "Add examples, benchmarks and tests to the tests suite", "", PathVariable.PathAccept),
Giorgio Arena232c4522022-03-03 10:09:01 +0000116 BoolVariable("experimental_dynamic_fusion", "Build the experimental dynamic fusion files", False),
Francesco.Petrogalli@arm.com5fcf22d2022-04-05 10:31:08 +0000117 BoolVariable("experimental_fixed_format_kernels", "Enable fixed format kernels for GEMM", 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"]),
SiCong Life1b1f62022-05-19 18:58:31 +0100121 ("toolchain_prefix", "Override the toolchain prefix; used by all toolchain components: compilers, linker, assembler etc. If unspecified, use default(auto) prefixes; if passed an empty string '' prefixes would be disabled", "auto"),
122 ("compiler_prefix", "Override the compiler prefix; used by just compilers (CC,CXX); further overrides toolchain_prefix for compilers; this is for when the compiler prefixes are different from that of the linkers, archivers etc. If unspecified, this is the same as toolchain_prefix; if passed an empty string '' prefixes would be disabled", "auto"),
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
Pablo Tello4e66d702022-03-07 18:20:12 +0000131env = Environment(variables=vars, ENV = os.environ)
132
133
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100134build_path = env['build_dir']
135# If build_dir is a relative path then add a #build/ prefix:
136if not env['build_dir'].startswith('/'):
137 SConsignFile('build/%s/.scons' % build_path)
138 build_path = "#build/%s" % build_path
139else:
140 SConsignFile('%s/.scons' % build_path)
141
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000142install_path = env['install_dir']
143#If the install_dir is a relative path then assume it's from inside build_dir
144if not env['install_dir'].startswith('/') and install_path != "":
145 install_path = "%s/%s" % (build_path, install_path)
146
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100147env.Append(LIBPATH = [build_path])
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000148Export('env')
149Export('vars')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100150
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000151def install_lib( lib ):
152 # If there is no install folder, then there is nothing to do:
153 if install_path == "":
154 return lib
155 return env.Install( "%s/lib/" % install_path, lib)
156def install_bin( bin ):
157 # If there is no install folder, then there is nothing to do:
158 if install_path == "":
159 return bin
160 return env.Install( "%s/bin/" % install_path, bin)
161def install_include( inc ):
162 if install_path == "":
163 return inc
164 return env.Install( "%s/include/" % install_path, inc)
165
166Export('install_lib')
167Export('install_bin')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100168
169Help(vars.GenerateHelpText(env))
170
Michalis Spyrou14ce0942022-06-13 15:40:35 +0100171if 'armv7a' in env['arch'] and env['os'] == 'android':
SiCong Li13f96d02022-06-21 10:06:51 +0100172 print("WARNING: armv7a on Android is no longer maintained")
Michalis Spyrou14ce0942022-06-13 15:40:35 +0100173
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100174if env['linker_script'] and env['os'] != 'bare_metal':
175 print("Linker script is only supported for bare_metal builds")
176 Exit(1)
177
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000178if env['build'] == "embed_only":
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100179 SConscript('./SConscript', variant_dir=build_path, duplicate=0)
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000180 Return()
181
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100182if env['neon'] and 'x86' in env['arch']:
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +0000183 print("Cannot compile Arm® Neon™ for x86")
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100184 Exit(1)
185
186if env['set_soname'] and not version_at_least(SCons.__version__, "2.4"):
ggardet767c9f72018-06-29 17:01:01 +0200187 print("Setting the library's SONAME / SHLIBVERSION requires SCons 2.4 or above")
188 print("Update your version of SCons or use set_soname=0")
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100189 Exit(1)
190
191if env['os'] == 'bare_metal':
192 if env['cppthreads'] or env['openmp']:
193 print("ERROR: OpenMP and C++11 threads not supported in bare_metal. Use cppthreads=0 openmp=0")
194 Exit(1)
195
Georgios Pinitasea857272021-01-22 05:47:37 +0000196if env['opencl'] and env['embed_kernels'] and env['compress_kernels'] and env['os'] not in ['android']:
197 print("Compressed kernels are supported only for android builds")
198 Exit(1)
199
Michalis Spyrou323ce0f2018-11-30 16:30:43 +0000200if not env['exceptions']:
Manuel Bottiniceaa0bf2021-02-16 15:15:19 +0000201 if env['opencl']:
202 print("ERROR: OpenCL is not supported when building without exceptions. Use opencl=0")
Michalis Spyrou323ce0f2018-11-30 16:30:43 +0000203 Exit(1)
204
205 env.Append(CPPDEFINES = ['ARM_COMPUTE_EXCEPTIONS_DISABLED'])
206 env.Append(CXXFLAGS = ['-fno-exceptions'])
207
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100208env.Append(CXXFLAGS = ['-Wall','-DARCH_ARM',
Pablo Tello4e66d702022-03-07 18:20:12 +0000209 '-Wextra','-Wdisabled-optimization','-Wformat=2',
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100210 '-Winit-self','-Wstrict-overflow=2','-Wswitch-default',
Pablo Tello4e66d702022-03-07 18:20:12 +0000211 '-Woverloaded-virtual', '-Wformat-security',
Michalis Spyroufae513c2019-10-16 17:41:33 +0100212 '-Wctor-dtor-privacy','-Wsign-promo','-Weffc++','-Wno-overlength-strings'])
Isabella Gottardib28f29d2017-11-09 17:05:07 +0000213
Pablo Tello4e66d702022-03-07 18:20:12 +0000214if not 'windows' in env['os']:
215 env.Append(CXXFLAGS = ['-std=c++14', '-pedantic' ])
216
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100217env.Append(CPPDEFINES = ['_GLIBCXX_USE_NANOSLEEP'])
218
Pablo Tello4e66d702022-03-07 18:20:12 +0000219cpp_tool = {'linux': 'g++', 'android' : 'clang++',
220 'tizen': 'g++', 'macos':'clang++',
221 'bare_metal':'g++', 'openbsd':'g++','windows':'clang-cl'}
222
223c_tool = {'linux':'gcc', 'android': 'clang', 'tizen':'gcc',
224 'macos':'clang','bare_metal':'gcc',
225 'openbsd':'gcc','windows':'clang-cl'}
226
227default_cpp_compiler = cpp_tool[env['os']]
228default_c_compiler = c_tool[env['os']]
Anthony Barbiera026e982018-01-18 10:57:52 +0000229cpp_compiler = os.environ.get('CXX', default_cpp_compiler)
230c_compiler = os.environ.get('CC', default_c_compiler)
231
Anthony Barbierdd669372018-03-01 17:08:54 +0000232if env['os'] == 'android' and ( 'clang++' not in cpp_compiler or 'clang' not in c_compiler ):
ggardet767c9f72018-06-29 17:01:01 +0200233 print( "WARNING: Only clang is officially supported to build the Compute Library for Android")
Anthony Barbiera026e982018-01-18 10:57:52 +0000234
Anthony Barbierdd669372018-03-01 17:08:54 +0000235if 'clang++' in cpp_compiler:
Michalis Spyrou7c60c992019-10-10 14:33:47 +0100236 env.Append(CXXFLAGS = ['-Wno-vla-extension'])
Georgios Pinitase874ef92019-09-09 17:40:33 +0100237elif 'armclang' in cpp_compiler:
238 pass
Pablo Tello4e66d702022-03-07 18:20:12 +0000239elif not 'windows' in env['os']:
Giorgio Arenab83e6722022-03-24 14:23:07 +0000240 env.Append(CXXFLAGS = ['-Wlogical-op','-Wnoexcept','-Wstrict-null-sentinel','-Wno-misleading-indentation'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100241
SiCongLi410e21e2020-12-11 15:07:53 +0000242if cpp_compiler == 'g++':
243 # Don't strip comments that could include markers
244 env.Append(CXXFLAGS = ['-C'])
245
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100246if env['cppthreads']:
247 env.Append(CPPDEFINES = [('ARM_COMPUTE_CPP_SCHEDULER', 1)])
248
249if env['openmp']:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100250 env.Append(CPPDEFINES = [('ARM_COMPUTE_OPENMP_SCHEDULER', 1)])
251 env.Append(CXXFLAGS = ['-fopenmp'])
252 env.Append(LINKFLAGS = ['-fopenmp'])
253
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000254# Validate and define state
255if env['estate'] == 'auto':
256 if 'v7a' in env['arch']:
257 env['estate'] = '32'
258 else:
259 env['estate'] = '64'
260
261# Map legacy arch
262if 'arm64' in env['arch']:
263 env['estate'] = '64'
264
265if 'v7a' in env['estate'] and env['estate'] == '64':
266 print("ERROR: armv7a architecture has only 32-bit execution state")
267 Exit(1)
268
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200269env.Append(CPPDEFINES = ['ENABLE_NEON', 'ARM_COMPUTE_ENABLE_NEON'])
270
Motti Gondabif76a5022021-12-21 13:19:29 +0200271if 'sve' in env['arch']:
272 env.Append(CPPDEFINES = ['ENABLE_SVE', 'ARM_COMPUTE_ENABLE_SVE'])
273 if 'sve2' in env['arch']:
274 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVE2'])
Motti Gondabif76a5022021-12-21 13:19:29 +0200275
Georgios Pinitase874ef92019-09-09 17:40:33 +0100276# Add architecture specific flags
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200277if env['multi_isa']:
278 # assert arch version is v8
279 if 'v8' not in env['arch']:
280 print("Currently Multi ISA binary is only supported for arm v8 family")
281 Exit(1)
Georgios Pinitas94672fb2020-01-22 18:36:27 +0000282
Georgios Pinitas8e2f64f2021-07-28 13:18:46 +0100283 if 'v8.6-a' in env['arch']:
Georgios Pinitas49c6ced2020-09-21 17:16:09 +0100284 if "disable_mmla_fp" not in env['custom_options']:
Michalis Spyrou20fca522021-06-07 14:23:57 +0100285 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVEF32MM'])
Georgios Pinitas8e2f64f2021-07-28 13:18:46 +0100286
Giorgio Arena73fa0a72022-02-10 15:06:51 +0000287 env.Append(CXXFLAGS = ['-march=armv8.2-a+fp16']) # explicitly enable fp16 extension otherwise __ARM_FEATURE_FP16_VECTOR_ARITHMETIC is undefined
288
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200289else: # NONE "multi_isa" builds
290
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200291 if 'v7a' in env['arch']:
292 env.Append(CXXFLAGS = ['-march=armv7-a', '-mthumb', '-mfpu=neon'])
293 if (env['os'] == 'android' or env['os'] == 'tizen') and not 'hf' in env['arch']:
294 env.Append(CXXFLAGS = ['-mfloat-abi=softfp'])
295 else:
296 env.Append(CXXFLAGS = ['-mfloat-abi=hard'])
297 elif 'v8' in env['arch']:
298 # Preserve the V8 archs for non-multi-ISA variants
299 if 'sve2' in env['arch']:
300 env.Append(CXXFLAGS = ['-march=armv8.2-a+sve2+fp16+dotprod'])
301 elif 'sve' in env['arch']:
302 env.Append(CXXFLAGS = ['-march=armv8.2-a+sve+fp16+dotprod'])
303 elif 'armv8r64' in env['arch']:
304 env.Append(CXXFLAGS = ['-march=armv8.4-a'])
305 elif 'v8.' in env['arch']:
306 env.Append(CXXFLAGS = ['-march=armv8.2-a+fp16']) # explicitly enable fp16 extension otherwise __ARM_FEATURE_FP16_VECTOR_ARITHMETIC is undefined
307 else:
308 env.Append(CXXFLAGS = ['-march=armv8-a'])
309
310 if 'v8.6-a' in env['arch']:
311 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_I8MM', 'ARM_COMPUTE_ENABLE_BF16'])
312 if "disable_mmla_fp" not in env['custom_options']:
313 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVEF32MM'])
314 if 'v8.' in env['arch']:
315 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_FP16'])
316
317 elif 'x86' in env['arch']:
318 if env['estate'] == '32':
319 env.Append(CCFLAGS = ['-m32'])
320 env.Append(LINKFLAGS = ['-m32'])
321 else:
322 env.Append(CXXFLAGS = ['-fPIC'])
323 env.Append(CCFLAGS = ['-m64'])
324 env.Append(LINKFLAGS = ['-m64'])
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000325
326# Define toolchain
SiCongLifecdb8f2022-01-04 18:33:17 +0000327# The reason why we distinguish toolchain_prefix from compiler_prefix is for cases where the linkers/archivers use a
328# different prefix than the compilers. An example is the NDK r20 toolchain
SiCong Life1b1f62022-05-19 18:58:31 +0100329auto_toolchain_prefix = ""
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000330if 'x86' not in env['arch']:
331 if env['estate'] == '32':
332 if env['os'] == 'linux':
SiCong Life1b1f62022-05-19 18:58:31 +0100333 auto_toolchain_prefix = "arm-linux-gnueabihf-" if 'v7' in env['arch'] else "armv8l-linux-gnueabihf-"
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000334 elif env['os'] == 'bare_metal':
SiCong Life1b1f62022-05-19 18:58:31 +0100335 auto_toolchain_prefix = "arm-eabi-"
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000336 elif env['os'] == 'android':
SiCong Life1b1f62022-05-19 18:58:31 +0100337 auto_toolchain_prefix = "arm-linux-androideabi-"
Inki Dae51a95582020-03-23 08:29:02 +0900338 elif env['os'] == 'tizen':
SiCong Life1b1f62022-05-19 18:58:31 +0100339 auto_toolchain_prefix = "armv7l-tizen-linux-gnueabi-"
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000340 elif env['estate'] == '64' and 'v8' in env['arch']:
341 if env['os'] == 'linux':
SiCong Life1b1f62022-05-19 18:58:31 +0100342 auto_toolchain_prefix = "aarch64-linux-gnu-"
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000343 elif env['os'] == 'bare_metal':
SiCong Life1b1f62022-05-19 18:58:31 +0100344 auto_toolchain_prefix = "aarch64-elf-"
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000345 elif env['os'] == 'android':
SiCong Life1b1f62022-05-19 18:58:31 +0100346 auto_toolchain_prefix = "aarch64-linux-android-"
Inki Dae51a95582020-03-23 08:29:02 +0900347 elif env['os'] == 'tizen':
SiCong Life1b1f62022-05-19 18:58:31 +0100348 auto_toolchain_prefix = "aarch64-tizen-linux-gnu-"
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100349
350if env['build'] == 'native':
SiCongLifecdb8f2022-01-04 18:33:17 +0000351 toolchain_prefix = ""
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100352
SiCong Life1b1f62022-05-19 18:58:31 +0100353if env["toolchain_prefix"] == "":
354 toolchain_prefix = ""
355elif env["toolchain_prefix"] == "auto":
356 toolchain_prefix = auto_toolchain_prefix
357else:
SiCongLifecdb8f2022-01-04 18:33:17 +0000358 toolchain_prefix = env["toolchain_prefix"]
Anthony Barbier149de5b2018-12-06 10:27:37 +0000359
SiCong Life1b1f62022-05-19 18:58:31 +0100360if env["compiler_prefix"] == "":
361 compiler_prefix = ""
362elif env["compiler_prefix"] == "auto":
363 compiler_prefix = toolchain_prefix
364else:
alered01d8872c12020-02-10 11:29:45 +0000365 compiler_prefix = env["compiler_prefix"]
366
367env['CC'] = env['compiler_cache']+ " " + compiler_prefix + c_compiler
368env['CXX'] = env['compiler_cache']+ " " + compiler_prefix + cpp_compiler
SiCongLifecdb8f2022-01-04 18:33:17 +0000369env['LD'] = toolchain_prefix + "ld"
370env['AS'] = toolchain_prefix + "as"
Pablo Tello4e66d702022-03-07 18:20:12 +0000371if env['os'] == 'windows':
372 env['AR'] = "LIB"
373else:
SiCongLifecdb8f2022-01-04 18:33:17 +0000374 env['AR'] = toolchain_prefix + "ar"
375env['RANLIB'] = toolchain_prefix + "ranlib"
Pablo Tello4e66d702022-03-07 18:20:12 +0000376
SiCong Life1b1f62022-05-19 18:58:31 +0100377print("Using compilers:")
378print("CC", env['CC'])
379print("CXX", env['CXX'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100380
381if not GetOption("help"):
382 try:
Pablo Tello4e66d702022-03-07 18:20:12 +0000383 if env['os'] == 'windows':
Giorgio Arenab83e6722022-03-24 14:23:07 +0000384 compiler_ver = check_output("clang++ -dumpversion").decode().strip()
Pablo Tello4e66d702022-03-07 18:20:12 +0000385 else:
Giorgio Arenab83e6722022-03-24 14:23:07 +0000386 compiler_ver = check_output(env['CXX'].split() + ["-dumpversion"]).decode().strip()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100387 except OSError:
388 print("ERROR: Compiler '%s' not found" % env['CXX'])
389 Exit(1)
390
Georgios Pinitase874ef92019-09-09 17:40:33 +0100391 if 'armclang' in cpp_compiler:
392 pass
393 elif 'clang++' not in cpp_compiler:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100394 if env['arch'] == 'arm64-v8.2-a' and not version_at_least(compiler_ver, '6.2.1'):
ggardet767c9f72018-06-29 17:01:01 +0200395 print("GCC 6.2.1 or newer is required to compile armv8.2-a code")
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100396 Exit(1)
397 elif env['arch'] == 'arm64-v8a' and not version_at_least(compiler_ver, '4.9'):
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +0000398 print("GCC 4.9 or newer is required to compile Arm® Neon™ code for AArch64")
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100399 Exit(1)
400
401 if version_at_least(compiler_ver, '6.1'):
402 env.Append(CXXFLAGS = ['-Wno-ignored-attributes'])
403
404 if compiler_ver == '4.8.3':
405 env.Append(CXXFLAGS = ['-Wno-array-bounds'])
406
Michalis Spyroucfac3052020-10-14 12:06:28 +0100407 if not version_at_least(compiler_ver, '7.0.0') and env['os'] == 'bare_metal':
408 env.Append(LINKFLAGS = ['-fstack-protector-strong'])
409
Giorgio Arenab83e6722022-03-24 14:23:07 +0000410 # For NDK >= r21, clang 9 or above is used
411 if env['os'] == 'android' and version_at_least(compiler_ver, '9.0.0'):
412 env['ndk_above_r21'] = True
413
414 if env['openmp']:
415 env.Append(LINKFLAGS = ['-static-openmp'])
416
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100417if env['high_priority'] and env['build_config']:
SiCongLidc85d782021-12-17 13:22:55 +0000418 print("The high priority library cannot be built in conjunction with a user-specified build configuration")
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100419 Exit(1)
420
421if not env['high_priority'] and not env['build_config']:
422 env.Append(CPPDEFINES = ['ARM_COMPUTE_GRAPH_ENABLED'])
423
Freddie Liardet487d3902021-09-21 12:36:43 +0100424data_types = []
425data_layouts = []
Georgios Pinitasff4fca02020-10-02 21:00:00 +0100426
Freddie Liardet487d3902021-09-21 12:36:43 +0100427# Set correct data types / layouts to build
428if env['high_priority']:
429 data_types = ['all']
430 data_layouts = ['all']
431elif env['build_config']:
432 data_types, data_layouts = read_build_config_json(env['build_config'])
433else:
434 data_types = env['data_type_support']
435 data_layouts = env['data_layout_support']
436
437env = update_data_type_layout_flags(env, data_types, data_layouts)
Sheri Zhang79144a62021-02-08 17:43:04 +0000438
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100439if env['standalone']:
Pablo Tello4e66d702022-03-07 18:20:12 +0000440 if not 'windows' in env['os']:
441 env.Append(CXXFLAGS = ['-fPIC'])
Anthony Barbier665c89b2018-07-16 11:40:09 +0100442 env.Append(LINKFLAGS = ['-static-libgcc','-static-libstdc++'])
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100443
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100444if env['Werror']:
445 env.Append(CXXFLAGS = ['-Werror'])
446
447if env['os'] == 'android':
448 env.Append(CPPDEFINES = ['ANDROID'])
Michalis Spyrou2d22c3f2020-02-12 14:50:19 +0000449 env.Append(LINKFLAGS = ['-pie', '-static-libstdc++', '-ldl'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100450elif env['os'] == 'bare_metal':
451 env.Append(LINKFLAGS = ['-static'])
452 env.Append(CXXFLAGS = ['-fPIC'])
Manuel Bottinie5a9ad82020-11-18 16:22:16 +0000453 if env['specs_file'] == "":
454 env.Append(LINKFLAGS = ['-specs=rdimon.specs'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100455 env.Append(CPPDEFINES = ['NO_MULTI_THREADING'])
Michalis Spyrou07781ac2017-08-31 15:11:41 +0100456 env.Append(CPPDEFINES = ['BARE_METAL'])
Manuel Bottini827817e2020-11-19 12:12:06 +0000457if env['os'] == 'linux' and env['arch'] == 'armv7a':
458 env.Append(CXXFLAGS = [ '-Wno-psabi' ])
Pablo Tello4e66d702022-03-07 18:20:12 +0000459if env['os'] == 'windows':
460 env.Append(CXXFLAGS = [ '/std:c++14','/EHa'])
461 env.Append(CXXFLAGS = [ '-Wno-c++98-compat', '-Wno-covered-switch-default','-Wno-c++98-compat-pedantic'])
462 env.Append(CXXFLAGS = [ '-Wno-shorten-64-to-32', '-Wno-sign-conversion','-Wno-documentation'])
463 env.Append(CXXFLAGS = [ '-Wno-extra-semi-stmt', '-Wno-float-equal','-Wno-implicit-int-conversion'])
464 env.Append(CXXFLAGS = [ '-Wno-documentation-pedantic', '-Wno-extra-semi','-Wno-shadow-field-in-constructor'])
465 env.Append(CXXFLAGS = [ '-Wno-float-conversion', '-Wno-switch-enum','-Wno-comma'])
466 env.Append(CXXFLAGS = [ '-Wno-implicit-float-conversion', '-Wno-deprecated-declarations','-Wno-old-style-cast'])
467 env.Append(CXXFLAGS = [ '-Wno-zero-as-null-pointer-constant', '-Wno-inconsistent-missing-destructor-override'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100468
Manuel Bottinie5a9ad82020-11-18 16:22:16 +0000469if env['specs_file'] != "":
470 env.Append(LINKFLAGS = ['-specs='+env['specs_file']])
471
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000472if env['neon']:
473 env.Append(CPPDEFINES = ['ARM_COMPUTE_CPU_ENABLED'])
474
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100475if env['opencl']:
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000476 env.Append(CPPDEFINES = ['ARM_COMPUTE_OPENCL_ENABLED'])
Georgios Pinitase6032da2017-10-26 14:13:35 +0100477 if env['os'] in ['bare_metal'] or env['standalone']:
Anthony Barbier5f0124d2018-04-13 14:05:34 +0100478 print("Cannot link OpenCL statically, which is required for bare metal / standalone builds")
479 Exit(1)
480
Anthony Barbier9fb0cac2018-04-20 15:46:21 +0100481if env["os"] not in ["android", "bare_metal"] and (env['opencl'] or env['cppthreads']):
482 env.Append(LIBS = ['pthread'])
483
Kevin Lo7195f712022-01-07 15:46:02 +0800484if env['os'] == 'openbsd':
485 env.Append(LIBS = ['c'])
486 env.Append(CXXFLAGS = ['-fPIC'])
487
Manuel Bottiniceaa0bf2021-02-16 15:15:19 +0000488if env['opencl']:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100489 if env['embed_kernels']:
490 env.Append(CPPDEFINES = ['EMBEDDED_KERNELS'])
Georgios Pinitasea857272021-01-22 05:47:37 +0000491 if env['compress_kernels']:
492 env.Append(CPPDEFINES = ['ARM_COMPUTE_COMPRESSED_KERNELS'])
493 env.Append(LIBS = ['z'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100494
495if env['debug']:
496 env['asserts'] = True
497 env.Append(CXXFLAGS = ['-O0','-g','-gdwarf-2'])
498 env.Append(CPPDEFINES = ['ARM_COMPUTE_DEBUG_ENABLED'])
499else:
Pablo Tello4e66d702022-03-07 18:20:12 +0000500 if not 'windows' in env['os']:
501 env.Append(CXXFLAGS = ['-O3'])
502 else:
503 # on windows we use clang-cl which does not support the option -O3
504 env.Append(CXXFLAGS = ['-O2'])
505
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100506if env['asserts']:
507 env.Append(CPPDEFINES = ['ARM_COMPUTE_ASSERTS_ENABLED'])
Moritz Pflanzer8b74c782017-09-14 14:33:20 +0100508 env.Append(CXXFLAGS = ['-fstack-protector-strong'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100509
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +0100510if env['logging']:
511 env.Append(CPPDEFINES = ['ARM_COMPUTE_LOGGING_ENABLED'])
512
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100513env.Append(CPPPATH = ['#/include', "#"])
514env.Append(CXXFLAGS = env['extra_cxx_flags'])
Georgios Pinitas421405b2018-10-26 19:05:32 +0100515env.Append(LINKFLAGS = env['extra_link_flags'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100516
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000517Default( install_include("arm_compute"))
Anthony Barbier10565952018-11-15 09:50:06 +0000518Default( install_include("support"))
Michele Di Giorgio6afea902019-04-03 11:40:20 +0100519Default( install_include("utils"))
520for dirname in os.listdir("./include"):
521 Default( install_include("include/%s" % dirname))
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000522
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100523Export('version_at_least')
524
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100525SConscript('./SConscript', variant_dir=build_path, duplicate=0)
Anthony Barbier6c0348f2017-11-10 18:32:38 +0000526
Freddie Liardet487d3902021-09-21 12:36:43 +0100527if env['examples'] and (env['build_config'] or env['high_priority']):
528 print("WARNING: Building examples for selected operators not supported. Use examples=0")
529 Return()
530
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100531if env['examples'] and env['exceptions']:
532 if env['os'] == 'bare_metal' and env['arch'] == 'armv7a':
Michalis Spyrou35f35a62019-12-23 11:29:52 +0000533 print("WARNING: Building examples for bare metal and armv7a is not supported. Use examples=0")
534 Return()
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100535 SConscript('./examples/SConscript', variant_dir='%s/examples' % build_path, duplicate=0)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100536
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100537if env['exceptions']:
Freddie Liardet487d3902021-09-21 12:36:43 +0100538 if env['build_config'] or env['high_priority']:
539 print("WARNING: Building tests for selected operators not supported")
540 Return()
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100541 if env['os'] == 'bare_metal' and env['arch'] == 'armv7a':
542 print("WARNING: Building tests for bare metal and armv7a is not supported")
543 Return()
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100544 SConscript('./tests/SConscript', variant_dir='%s/tests' % build_path, duplicate=0)
Motti Gondabif76a5022021-12-21 13:19:29 +0200545
546# Unknown variables are not allowed
547# Note: we must delay the call of UnknownVariables until after
548# we have applied the Variables object to the construction environment
549unknown = vars.UnknownVariables()
550if unknown:
551 print("Unknown variables: %s" % " ".join(unknown.keys()))
Ramy Elgammal451c3092022-02-01 23:01:27 +0000552 Exit(1)