blob: 746d4a6afe0c612631308b23dbed09c7bbb38ea5 [file] [log] [blame]
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +00001# -*- coding: utf-8 -*-
2
Pablo Marquez Tello6bcdc572023-01-11 09:54:00 +00003# Copyright (c) 2016-2023 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
Jakub Sujak78a17a12023-06-09 09:51:31 +010028import subprocess
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
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +010065 if env['multi_isa']:
66 if any(i in data_types for i in ['all', 'fp16']):
67 env.Append(CXXFLAGS = ['-DENABLE_FP16_KERNELS'])
68 else:
Pablo Marquez Tello23158b02023-11-28 16:58:02 +000069 if not 'v8a' in env['arch'] and not 'v7a' in env['arch'] and not 'armv8r64' in env['arch']:
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +010070 if any(i in data_types for i in ['all', 'fp16']):
71 env.Append(CXXFLAGS = ['-DENABLE_FP16_KERNELS'])
72
Freddie Liardet487d3902021-09-21 12:36:43 +010073 if any(i in data_types for i in ['all', 'fp32']):
74 env.Append(CXXFLAGS = ['-DENABLE_FP32_KERNELS'])
75 if any(i in data_types for i in ['all', 'qasymm8']):
76 env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_KERNELS'])
77 if any(i in data_types for i in ['all', 'qasymm8_signed']):
78 env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_SIGNED_KERNELS'])
79 if any(i in data_types for i in ['all', 'qsymm16']):
80 env.Append(CXXFLAGS = ['-DENABLE_QSYMM16_KERNELS'])
81 if any(i in data_types for i in ['all', 'integer']):
82 env.Append(CXXFLAGS = ['-DENABLE_INTEGER_KERNELS'])
83
84 # Manage data-layouts
85 if any(i in data_layouts for i in ['all', 'nhwc']):
86 env.Append(CXXFLAGS = ['-DENABLE_NHWC_KERNELS'])
87 if any(i in data_layouts for i in ['all', 'nchw']):
88 env.Append(CXXFLAGS = ['-DENABLE_NCHW_KERNELS'])
89
90 return env
91
92
Anthony Barbier6ff3b192017-09-04 18:44:23 +010093vars = Variables("scons")
94vars.AddVariables(
95 BoolVariable("debug", "Debug", False),
96 BoolVariable("asserts", "Enable asserts (this flag is forced to 1 for debug=1)", False),
ramelg0193d6cf02021-09-23 13:59:22 +010097 BoolVariable("logging", "Enable Logging", False),
Michalis Spyroua3f7cd22022-07-04 15:32:02 +010098 EnumVariable("arch", "Target Architecture. The x86_32 and x86_64 targets can only be used with neon=0 and opencl=1.", "armv7a",
Slava Barinovdb0e2c82021-04-07 11:23:27 +030099 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",
Viet-Hoa Do03b29712022-06-01 11:47:14 +0100100 "armv8a", "armv8.2-a", "armv8.2-a-sve", "armv8.6-a", "armv8.6-a-sve", "armv8.6-a-sve2", "armv8.6-a-sve2-sme2", "armv8r64", "x86")),
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000101 EnumVariable("estate", "Execution State", "auto", allowed_values=("auto", "32", "64")),
Michalis Spyroua3f7cd22022-07-04 15:32:02 +0100102 EnumVariable("os", "Target OS. With bare metal selected, only Arm® Neon™ (not OpenCL) can be used, static libraries get built and Neon™'s multi-threading support is disabled.", "linux", allowed_values=("linux", "android", "tizen", "macos", "bare_metal", "openbsd","windows")),
103 EnumVariable("build", "Either build directly on your device (native) or cross compile from your desktop machine (cross-compile). In both cases make sure the compiler is available in your path.", "cross_compile", allowed_values=("native", "cross_compile", "embed_only")),
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100104 BoolVariable("examples", "Build example programs", True),
SiCong Li8b4c7302019-09-19 12:18:15 +0100105 BoolVariable("gemm_tuner", "Build gemm_tuner programs", True),
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100106 BoolVariable("Werror", "Enable/disable the -Werror compilation flag", True),
Sunita Nadampalli911d5722023-05-02 14:05:39 +0000107 BoolVariable("multi_isa", "Build Multi ISA binary version of library. Works for armv8a without the support for FP16 vector arithmetic. Use armv8.2-a or beyond to enable FP16 vector arithmetic support", False),
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100108 BoolVariable("standalone", "Builds the tests as standalone executables, links statically with libgcc, libstdc++ and libarm_compute", False),
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100109 BoolVariable("opencl", "Enable OpenCL support", True),
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +0000110 BoolVariable("neon", "Enable Arm® Neon™ support", False),
Michalis Spyroua3f7cd22022-07-04 15:32:02 +0100111 BoolVariable("embed_kernels", "Enable if you want the OpenCL kernels to be built in the library's binaries instead of being read from separate '.cl' / '.cs' files. If embed_kernels is set to 0 then the application can set the path to the folder containing the OpenCL kernel files by calling CLKernelLibrary::init(). By default the path is set to './cl_kernels'.", True),
112 BoolVariable("compress_kernels", "Compress embedded OpenCL kernels in library binary using zlib. Useful for reducing the binary size. embed_kernels should be enabled", False),
113 BoolVariable("set_soname", "If enabled the library will contain a SONAME and SHLIBVERSION and some symlinks will automatically be created between the objects. (requires SCons 2.4 or above)", False),
114 BoolVariable("openmp", "Enable OpenMP backend. Only works when building with g++ and not clang++", False),
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100115 BoolVariable("cppthreads", "Enable C++11 threads backend", True),
116 PathVariable("build_dir", "Specify sub-folder for the build", ".", PathVariable.PathAccept),
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000117 PathVariable("install_dir", "Specify sub-folder for the install", "", PathVariable.PathAccept),
Michalis Spyrou323ce0f2018-11-30 16:30:43 +0000118 BoolVariable("exceptions", "Enable/disable C++ exception support", True),
Michalis Spyrou62c2ad62021-06-21 17:40:09 +0100119 BoolVariable("high_priority", "Generate a library containing only the high priority operators", False),
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100120 PathVariable("linker_script", "Use an external linker script", "", PathVariable.PathAccept),
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100121 PathVariable("external_tests_dir", """Add examples, benchmarks and tests to the tests suite from an external path. In order to use this option, the external tests directory must have the following structure:
Michalis Spyroua3f7cd22022-07-04 15:32:02 +0100122 EXTERNAL_TESTS_DIR:
123 └── tests
124 ├── benchmark
125 │   ├── CL
126 │   ├── datasets
127 │   ├── fixtures
128 │   └── Neon
129 └── validation
130     ├── CL
131     ├── datasets
132     ├── fixtures
133     └── Neon\n""", "", PathVariable.PathAccept),
SiCong Li19844f62023-05-16 16:46:34 +0100134 BoolVariable("experimental_dynamic_fusion", "Build the experimental dynamic fusion files. This option also enables opencl=1 on which it has a direct dependency.", False),
Nathan John Sircombed7113e42023-04-26 15:02:43 +0100135 BoolVariable("fixed_format_kernels", "Enable fixed format kernels for GEMM", False),
Pablo Marquez Tello299d3a12022-10-12 14:58:24 +0100136 BoolVariable("mapfile", "Generate a map file", False),
Georgios Pinitas49c6ced2020-09-21 17:16:09 +0100137 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 +0000138 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 +0000139 ListVariable("data_layout_support", "Enable a list of data layout to support", "all", ["nhwc", "nchw"]),
SiCong Life1b1f62022-05-19 18:58:31 +0100140 ("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"),
141 ("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"),
Matthew Bentham0a59e692023-07-19 15:01:00 +0000142 BoolVariable("thread_sanitizer", "Enable ThreadSanitizer", False),
Anthony Barbier7390e052018-03-13 09:29:41 +0000143 ("extra_cxx_flags", "Extra CXX flags to be appended to the build command", ""),
Georgios Pinitas421405b2018-10-26 19:05:32 +0100144 ("extra_link_flags", "Extra LD flags to be appended to the build command", ""),
Manuel Bottinie5a9ad82020-11-18 16:22:16 +0000145 ("compiler_cache", "Command to prefix to the C and C++ compiler (e.g ccache)", ""),
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100146 ("specs_file", "Specs file to use (e.g. rdimon.specs)", ""),
147 ("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 +0100148)
149
Viet-Hoa Do36dc77d2023-03-03 10:44:58 +0000150if version_at_least(SCons.__version__, "4.0"):
151 vars.Add(BoolVariable("export_compile_commands", "Export compile_commands.json file.", False))
152
Motti Gondabif76a5022021-12-21 13:19:29 +0200153
Pablo Tello4e66d702022-03-07 18:20:12 +0000154env = Environment(variables=vars, ENV = os.environ)
155
156
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100157build_path = env['build_dir']
158# If build_dir is a relative path then add a #build/ prefix:
159if not env['build_dir'].startswith('/'):
160 SConsignFile('build/%s/.scons' % build_path)
161 build_path = "#build/%s" % build_path
162else:
163 SConsignFile('%s/.scons' % build_path)
164
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000165install_path = env['install_dir']
166#If the install_dir is a relative path then assume it's from inside build_dir
167if not env['install_dir'].startswith('/') and install_path != "":
168 install_path = "%s/%s" % (build_path, install_path)
169
Viet-Hoa Doce3c48c2023-07-03 13:44:43 +0100170env.Append(LIBPATH = [build_path, os.path.join(build_path, "prototype")])
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000171Export('env')
172Export('vars')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100173
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000174def install_lib( lib ):
175 # If there is no install folder, then there is nothing to do:
176 if install_path == "":
177 return lib
178 return env.Install( "%s/lib/" % install_path, lib)
179def install_bin( bin ):
180 # If there is no install folder, then there is nothing to do:
181 if install_path == "":
182 return bin
183 return env.Install( "%s/bin/" % install_path, bin)
184def install_include( inc ):
185 if install_path == "":
186 return inc
187 return env.Install( "%s/include/" % install_path, inc)
188
189Export('install_lib')
190Export('install_bin')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100191
192Help(vars.GenerateHelpText(env))
193
Viet-Hoa Do36dc77d2023-03-03 10:44:58 +0000194# Export compile_commands.json file
195if env.get("export_compile_commands", False):
196 env.Tool("compilation_db")
197 env.CompilationDatabase("%s/compile_commands.json" % build_path)
198
Michalis Spyrou14ce0942022-06-13 15:40:35 +0100199if 'armv7a' in env['arch'] and env['os'] == 'android':
SiCong Li13f96d02022-06-21 10:06:51 +0100200 print("WARNING: armv7a on Android is no longer maintained")
Michalis Spyrou14ce0942022-06-13 15:40:35 +0100201
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100202if env['linker_script'] and env['os'] != 'bare_metal':
203 print("Linker script is only supported for bare_metal builds")
204 Exit(1)
205
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000206if env['build'] == "embed_only":
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100207 SConscript('./SConscript', variant_dir=build_path, duplicate=0)
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000208 Return()
209
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100210if env['neon'] and 'x86' in env['arch']:
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +0000211 print("Cannot compile Arm® Neon™ for x86")
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100212 Exit(1)
213
214if env['set_soname'] and not version_at_least(SCons.__version__, "2.4"):
ggardet767c9f72018-06-29 17:01:01 +0200215 print("Setting the library's SONAME / SHLIBVERSION requires SCons 2.4 or above")
216 print("Update your version of SCons or use set_soname=0")
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100217 Exit(1)
218
219if env['os'] == 'bare_metal':
220 if env['cppthreads'] or env['openmp']:
221 print("ERROR: OpenMP and C++11 threads not supported in bare_metal. Use cppthreads=0 openmp=0")
222 Exit(1)
223
Jakub Sujak8c49f162023-06-16 09:52:50 +0100224if env['experimental_dynamic_fusion']:
225 # Dynamic Fusion on GPU has a direct dependency on OpenCL and Compute Kernel Writer
226 env['opencl'] = 1
Jakub Sujak8c49f162023-06-16 09:52:50 +0100227
Georgios Pinitasea857272021-01-22 05:47:37 +0000228if env['opencl'] and env['embed_kernels'] and env['compress_kernels'] and env['os'] not in ['android']:
229 print("Compressed kernels are supported only for android builds")
230 Exit(1)
231
Michalis Spyrou323ce0f2018-11-30 16:30:43 +0000232if not env['exceptions']:
Manuel Bottiniceaa0bf2021-02-16 15:15:19 +0000233 if env['opencl']:
234 print("ERROR: OpenCL is not supported when building without exceptions. Use opencl=0")
Michalis Spyrou323ce0f2018-11-30 16:30:43 +0000235 Exit(1)
236
237 env.Append(CPPDEFINES = ['ARM_COMPUTE_EXCEPTIONS_DISABLED'])
238 env.Append(CXXFLAGS = ['-fno-exceptions'])
239
Pablo Tello29cab362022-03-10 17:05:34 +0000240env.Append(CXXFLAGS = ['-DARCH_ARM',
Pablo Tello4e66d702022-03-07 18:20:12 +0000241 '-Wextra','-Wdisabled-optimization','-Wformat=2',
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100242 '-Winit-self','-Wstrict-overflow=2','-Wswitch-default',
Pablo Tello4e66d702022-03-07 18:20:12 +0000243 '-Woverloaded-virtual', '-Wformat-security',
Michalis Spyroufae513c2019-10-16 17:41:33 +0100244 '-Wctor-dtor-privacy','-Wsign-promo','-Weffc++','-Wno-overlength-strings'])
Isabella Gottardib28f29d2017-11-09 17:05:07 +0000245
Pablo Tello4e66d702022-03-07 18:20:12 +0000246if not 'windows' in env['os']:
Pablo Tello29cab362022-03-10 17:05:34 +0000247 env.Append(CXXFLAGS = ['-Wall','-std=c++14', '-pedantic' ])
Pablo Tello4e66d702022-03-07 18:20:12 +0000248
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100249
Pablo Tello4e66d702022-03-07 18:20:12 +0000250cpp_tool = {'linux': 'g++', 'android' : 'clang++',
251 'tizen': 'g++', 'macos':'clang++',
252 'bare_metal':'g++', 'openbsd':'g++','windows':'clang-cl'}
253
254c_tool = {'linux':'gcc', 'android': 'clang', 'tizen':'gcc',
255 'macos':'clang','bare_metal':'gcc',
256 'openbsd':'gcc','windows':'clang-cl'}
257
258default_cpp_compiler = cpp_tool[env['os']]
259default_c_compiler = c_tool[env['os']]
Anthony Barbiera026e982018-01-18 10:57:52 +0000260cpp_compiler = os.environ.get('CXX', default_cpp_compiler)
261c_compiler = os.environ.get('CC', default_c_compiler)
262
Anthony Barbierdd669372018-03-01 17:08:54 +0000263if env['os'] == 'android' and ( 'clang++' not in cpp_compiler or 'clang' not in c_compiler ):
ggardet767c9f72018-06-29 17:01:01 +0200264 print( "WARNING: Only clang is officially supported to build the Compute Library for Android")
Anthony Barbiera026e982018-01-18 10:57:52 +0000265
Anthony Barbierdd669372018-03-01 17:08:54 +0000266if 'clang++' in cpp_compiler:
Michalis Spyrou7c60c992019-10-10 14:33:47 +0100267 env.Append(CXXFLAGS = ['-Wno-vla-extension'])
Georgios Pinitase874ef92019-09-09 17:40:33 +0100268elif 'armclang' in cpp_compiler:
269 pass
Pablo Tello4e66d702022-03-07 18:20:12 +0000270elif not 'windows' in env['os']:
Giorgio Arenab83e6722022-03-24 14:23:07 +0000271 env.Append(CXXFLAGS = ['-Wlogical-op','-Wnoexcept','-Wstrict-null-sentinel','-Wno-misleading-indentation'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100272
SiCongLi410e21e2020-12-11 15:07:53 +0000273if cpp_compiler == 'g++':
274 # Don't strip comments that could include markers
275 env.Append(CXXFLAGS = ['-C'])
276
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100277if env['cppthreads']:
278 env.Append(CPPDEFINES = [('ARM_COMPUTE_CPP_SCHEDULER', 1)])
279
280if env['openmp']:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100281 env.Append(CPPDEFINES = [('ARM_COMPUTE_OPENMP_SCHEDULER', 1)])
282 env.Append(CXXFLAGS = ['-fopenmp'])
283 env.Append(LINKFLAGS = ['-fopenmp'])
284
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000285# Validate and define state
286if env['estate'] == 'auto':
287 if 'v7a' in env['arch']:
288 env['estate'] = '32'
289 else:
290 env['estate'] = '64'
291
292# Map legacy arch
293if 'arm64' in env['arch']:
294 env['estate'] = '64'
295
296if 'v7a' in env['estate'] and env['estate'] == '64':
297 print("ERROR: armv7a architecture has only 32-bit execution state")
298 Exit(1)
299
Motti Gondabi9d9ad332022-01-23 12:42:24 +0200300env.Append(CPPDEFINES = ['ENABLE_NEON', 'ARM_COMPUTE_ENABLE_NEON'])
301
Motti Gondabif76a5022021-12-21 13:19:29 +0200302if 'sve' in env['arch']:
303 env.Append(CPPDEFINES = ['ENABLE_SVE', 'ARM_COMPUTE_ENABLE_SVE'])
304 if 'sve2' in env['arch']:
305 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVE2'])
Motti Gondabif76a5022021-12-21 13:19:29 +0200306
Viet-Hoa Do03b29712022-06-01 11:47:14 +0100307if 'sme' in env['arch']:
308 env.Append(CPPDEFINES = ['ENABLE_SME', 'ARM_COMPUTE_ENABLE_SME'])
309 if 'sme2' in env['arch']:
310 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SME2'])
311
Georgios Pinitase874ef92019-09-09 17:40:33 +0100312# Add architecture specific flags
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200313if env['multi_isa']:
314 # assert arch version is v8
315 if 'v8' not in env['arch']:
316 print("Currently Multi ISA binary is only supported for arm v8 family")
317 Exit(1)
Georgios Pinitas94672fb2020-01-22 18:36:27 +0000318
Sunita Nadampalli911d5722023-05-02 14:05:39 +0000319 if 'v8a' in env['arch']:
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100320 env.Append(CXXFLAGS = ['-march=armv8-a'])
Sunita Nadampalli911d5722023-05-02 14:05:39 +0000321 else:
322 if 'v8.6-a' in env['arch']:
323 if "disable_mmla_fp" not in env['custom_options']:
324 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVEF32MM'])
Georgios Pinitas8e2f64f2021-07-28 13:18:46 +0100325
Sunita Nadampalli911d5722023-05-02 14:05:39 +0000326 env.Append(CXXFLAGS = ['-march=armv8.2-a+fp16']) # explicitly enable fp16 extension otherwise __ARM_FEATURE_FP16_VECTOR_ARITHMETIC is undefined
Giorgio Arena73fa0a72022-02-10 15:06:51 +0000327
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200328else: # NONE "multi_isa" builds
329
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200330 if 'v7a' in env['arch']:
331 env.Append(CXXFLAGS = ['-march=armv7-a', '-mthumb', '-mfpu=neon'])
332 if (env['os'] == 'android' or env['os'] == 'tizen') and not 'hf' in env['arch']:
333 env.Append(CXXFLAGS = ['-mfloat-abi=softfp'])
334 else:
335 env.Append(CXXFLAGS = ['-mfloat-abi=hard'])
Pablo Marquez Tellod208f4f2022-07-19 12:19:46 +0100336 elif 'v8.6-a' in env['arch']:
Viet-Hoa Do03b29712022-06-01 11:47:14 +0100337 if 'armv8.6-a-sve2' in env['arch']:
Pablo Marquez Tellod208f4f2022-07-19 12:19:46 +0100338 env.Append(CXXFLAGS = ['-march=armv8.6-a+sve2'])
339 elif 'armv8.6-a-sve' == env['arch']:
340 env.Append(CXXFLAGS = ['-march=armv8.6-a+sve'])
341 elif 'armv8.6-a' == env['arch']:
Pablo Marquez Tellocf07d112022-09-28 21:37:37 +0100342 env.Append(CXXFLAGS = ['-march=armv8.6-a+fp16'])
Pablo Marquez Tellod208f4f2022-07-19 12:19:46 +0100343
344 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_I8MM', 'ARM_COMPUTE_ENABLE_BF16','ARM_COMPUTE_ENABLE_FP16'])
345 if "disable_mmla_fp" not in env['custom_options']:
346 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVEF32MM'])
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200347 elif 'v8' in env['arch']:
348 # Preserve the V8 archs for non-multi-ISA variants
349 if 'sve2' in env['arch']:
350 env.Append(CXXFLAGS = ['-march=armv8.2-a+sve2+fp16+dotprod'])
351 elif 'sve' in env['arch']:
352 env.Append(CXXFLAGS = ['-march=armv8.2-a+sve+fp16+dotprod'])
353 elif 'armv8r64' in env['arch']:
354 env.Append(CXXFLAGS = ['-march=armv8.4-a'])
355 elif 'v8.' in env['arch']:
356 env.Append(CXXFLAGS = ['-march=armv8.2-a+fp16']) # explicitly enable fp16 extension otherwise __ARM_FEATURE_FP16_VECTOR_ARITHMETIC is undefined
357 else:
358 env.Append(CXXFLAGS = ['-march=armv8-a'])
359
Motti Gondabi6f3a9f52021-11-09 15:47:17 +0200360 if 'v8.' in env['arch']:
361 env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_FP16'])
362
363 elif 'x86' in env['arch']:
364 if env['estate'] == '32':
365 env.Append(CCFLAGS = ['-m32'])
366 env.Append(LINKFLAGS = ['-m32'])
367 else:
368 env.Append(CXXFLAGS = ['-fPIC'])
369 env.Append(CCFLAGS = ['-m64'])
370 env.Append(LINKFLAGS = ['-m64'])
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000371
372# Define toolchain
SiCongLifecdb8f2022-01-04 18:33:17 +0000373# The reason why we distinguish toolchain_prefix from compiler_prefix is for cases where the linkers/archivers use a
374# different prefix than the compilers. An example is the NDK r20 toolchain
SiCong Life1b1f62022-05-19 18:58:31 +0100375auto_toolchain_prefix = ""
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000376if 'x86' not in env['arch']:
377 if env['estate'] == '32':
378 if env['os'] == 'linux':
SiCong Life1b1f62022-05-19 18:58:31 +0100379 auto_toolchain_prefix = "arm-linux-gnueabihf-" if 'v7' in env['arch'] else "armv8l-linux-gnueabihf-"
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000380 elif env['os'] == 'bare_metal':
SiCong Life1b1f62022-05-19 18:58:31 +0100381 auto_toolchain_prefix = "arm-eabi-"
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000382 elif env['os'] == 'android':
SiCong Life1b1f62022-05-19 18:58:31 +0100383 auto_toolchain_prefix = "arm-linux-androideabi-"
Inki Dae51a95582020-03-23 08:29:02 +0900384 elif env['os'] == 'tizen':
SiCong Life1b1f62022-05-19 18:58:31 +0100385 auto_toolchain_prefix = "armv7l-tizen-linux-gnueabi-"
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000386 elif env['estate'] == '64' and 'v8' in env['arch']:
387 if env['os'] == 'linux':
SiCong Life1b1f62022-05-19 18:58:31 +0100388 auto_toolchain_prefix = "aarch64-linux-gnu-"
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000389 elif env['os'] == 'bare_metal':
SiCong Life1b1f62022-05-19 18:58:31 +0100390 auto_toolchain_prefix = "aarch64-elf-"
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000391 elif env['os'] == 'android':
SiCong Life1b1f62022-05-19 18:58:31 +0100392 auto_toolchain_prefix = "aarch64-linux-android-"
Inki Dae51a95582020-03-23 08:29:02 +0900393 elif env['os'] == 'tizen':
SiCong Life1b1f62022-05-19 18:58:31 +0100394 auto_toolchain_prefix = "aarch64-tizen-linux-gnu-"
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100395
Pablo Marquez Telloddf2f6c2022-06-28 12:56:27 +0100396if env['build'] == 'native' or env["toolchain_prefix"] == "":
SiCong Life1b1f62022-05-19 18:58:31 +0100397 toolchain_prefix = ""
398elif env["toolchain_prefix"] == "auto":
399 toolchain_prefix = auto_toolchain_prefix
400else:
SiCongLifecdb8f2022-01-04 18:33:17 +0000401 toolchain_prefix = env["toolchain_prefix"]
Anthony Barbier149de5b2018-12-06 10:27:37 +0000402
Pablo Marquez Telloddf2f6c2022-06-28 12:56:27 +0100403if env['build'] == 'native' or env["compiler_prefix"] == "":
SiCong Life1b1f62022-05-19 18:58:31 +0100404 compiler_prefix = ""
405elif env["compiler_prefix"] == "auto":
406 compiler_prefix = toolchain_prefix
407else:
alered01d8872c12020-02-10 11:29:45 +0000408 compiler_prefix = env["compiler_prefix"]
409
410env['CC'] = env['compiler_cache']+ " " + compiler_prefix + c_compiler
411env['CXX'] = env['compiler_cache']+ " " + compiler_prefix + cpp_compiler
SiCongLifecdb8f2022-01-04 18:33:17 +0000412env['LD'] = toolchain_prefix + "ld"
413env['AS'] = toolchain_prefix + "as"
Pablo Tello29cab362022-03-10 17:05:34 +0000414
Pablo Tello4e66d702022-03-07 18:20:12 +0000415if env['os'] == 'windows':
Pablo Tello29cab362022-03-10 17:05:34 +0000416 env['AR'] = "llvm-lib"
417 env['RANLIB'] = "llvm-ranlib"
Pablo Tello4e66d702022-03-07 18:20:12 +0000418else:
SiCongLifecdb8f2022-01-04 18:33:17 +0000419 env['AR'] = toolchain_prefix + "ar"
Pablo Tello29cab362022-03-10 17:05:34 +0000420
SiCongLifecdb8f2022-01-04 18:33:17 +0000421env['RANLIB'] = toolchain_prefix + "ranlib"
Pablo Tello4e66d702022-03-07 18:20:12 +0000422
SiCong Life1b1f62022-05-19 18:58:31 +0100423print("Using compilers:")
424print("CC", env['CC'])
425print("CXX", env['CXX'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100426
Jakub Sujak78a17a12023-06-09 09:51:31 +0100427"""Build the Compute Kernel Writer subproject"""
SiCong Li19844f62023-05-16 16:46:34 +0100428if env['experimental_dynamic_fusion']:
Jakub Sujak7a698a32023-06-21 09:45:41 +0100429 # Strip ccache prefix from CC and CXX to obtain only the target triple
Jakub Sujak78a17a12023-06-09 09:51:31 +0100430 CKW_CC = env['CC'].replace(env['compiler_cache'] + " ", "")
431 CKW_CXX = env['CXX'].replace(env['compiler_cache'] + " ", "")
432 CKW_CCACHE = 1 if env['compiler_cache'] else 0
433
434 CKW_BUILD_TYPE = "Debug" if env['debug'] else "Release"
435
436 CKW_ENABLE_OPENCL = env['opencl']
437 CKW_ENABLE_ASSERTS = env['debug'] or env['asserts']
438
439 CKW_PROJECT_DIR = Dir('.').path + "/compute_kernel_writer"
Viet-Hoa Doce3c48c2023-07-03 13:44:43 +0100440 CKW_INCLUDE_DIR = CKW_PROJECT_DIR + "/prototype/include"
Jakub Sujak78a17a12023-06-09 09:51:31 +0100441 CKW_BUILD_DIR = build_path.replace("#", "")
442
Jakub Sujakbec9b032023-06-09 14:13:30 +0100443 CKW_CMAKE_CMD = "CC={CKW_CC} CXX={CKW_CXX} cmake -G \"Unix Makefiles\" " \
Jakub Sujak78a17a12023-06-09 09:51:31 +0100444 "-S {CKW_PROJECT_DIR} -B {CKW_BUILD_DIR} " \
445 "-DCMAKE_BUILD_TYPE={CKW_BUILD_TYPE} " \
446 "-DCKW_ENABLE_OPENCL={CKW_ENABLE_OPENCL} " \
447 "-DCKW_ENABLE_ASSERTS={CKW_ENABLE_ASSERTS} " \
Viet-Hoa Doce3c48c2023-07-03 13:44:43 +0100448 "-DCKW_BUILD_PROTOTYPE=ON " \
Jakub Sujak78a17a12023-06-09 09:51:31 +0100449 "-DCKW_CCACHE={CKW_CCACHE} ".format(CKW_CC=CKW_CC,
450 CKW_CXX=CKW_CXX,
451 CKW_PROJECT_DIR=CKW_PROJECT_DIR,
452 CKW_BUILD_DIR=CKW_BUILD_DIR,
453 CKW_BUILD_TYPE=CKW_BUILD_TYPE,
454 CKW_ENABLE_OPENCL=CKW_ENABLE_OPENCL,
455 CKW_ENABLE_ASSERTS=CKW_ENABLE_ASSERTS,
456 CKW_CCACHE=CKW_CCACHE
457 )
458
Jakub Sujak7a698a32023-06-21 09:45:41 +0100459 # Configure CKW static objects with -fPIC (CMAKE_POSITION_INDEPENDENT_CODE) option to enable linking statically to ACL
460 CKW_CMAKE_CONFIGURE_STATIC = CKW_CMAKE_CMD + "-DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON"
Jakub Sujake86f9922023-07-05 17:30:02 +0100461 CKW_CMAKE_BUILD = "cmake --build {CKW_BUILD_DIR} --target ckw_prototype -j{NUM_JOBS}".format(CKW_BUILD_DIR=CKW_BUILD_DIR,
462 NUM_JOBS=GetOption('num_jobs')
463 )
Jakub Sujak78a17a12023-06-09 09:51:31 +0100464
465 # Build Compute Kernel Writer Static Library
466 subprocess.check_call(CKW_CMAKE_CONFIGURE_STATIC, stderr=subprocess.STDOUT, shell=True)
467 subprocess.check_call(CKW_CMAKE_BUILD, stderr=subprocess.STDOUT, shell=True)
468
Jakub Sujak7a698a32023-06-21 09:45:41 +0100469 # Let ACL know where to find CKW headers
Jakub Sujak78a17a12023-06-09 09:51:31 +0100470 env.Append(CPPPATH = CKW_INCLUDE_DIR)
471
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100472if not GetOption("help"):
473 try:
Pablo Tello4e66d702022-03-07 18:20:12 +0000474 if env['os'] == 'windows':
Jakub Sujak78a17a12023-06-09 09:51:31 +0100475 compiler_ver = subprocess.check_output("clang++ -dumpversion").decode().strip()
Pablo Tello4e66d702022-03-07 18:20:12 +0000476 else:
Jakub Sujak78a17a12023-06-09 09:51:31 +0100477 compiler_ver = subprocess.check_output(env['CXX'].split() + ["-dumpversion"]).decode().strip()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100478 except OSError:
479 print("ERROR: Compiler '%s' not found" % env['CXX'])
480 Exit(1)
481
Georgios Pinitase874ef92019-09-09 17:40:33 +0100482 if 'armclang' in cpp_compiler:
483 pass
484 elif 'clang++' not in cpp_compiler:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100485 if env['arch'] == 'arm64-v8.2-a' and not version_at_least(compiler_ver, '6.2.1'):
ggardet767c9f72018-06-29 17:01:01 +0200486 print("GCC 6.2.1 or newer is required to compile armv8.2-a code")
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100487 Exit(1)
488 elif env['arch'] == 'arm64-v8a' and not version_at_least(compiler_ver, '4.9'):
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +0000489 print("GCC 4.9 or newer is required to compile Arm® Neon™ code for AArch64")
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100490 Exit(1)
491
492 if version_at_least(compiler_ver, '6.1'):
493 env.Append(CXXFLAGS = ['-Wno-ignored-attributes'])
494
495 if compiler_ver == '4.8.3':
496 env.Append(CXXFLAGS = ['-Wno-array-bounds'])
497
Michalis Spyroucfac3052020-10-14 12:06:28 +0100498 if not version_at_least(compiler_ver, '7.0.0') and env['os'] == 'bare_metal':
499 env.Append(LINKFLAGS = ['-fstack-protector-strong'])
500
SiCong Libf5274d2022-07-20 17:45:36 +0100501 # Add Android NDK toolchain specific flags
502 if 'clang++' in cpp_compiler and env['os'] == 'android':
503 # For NDK >= r21, clang 9 or above is used
504 if version_at_least(compiler_ver, '9.0.0'):
505 env['ndk_above_r21'] = True
Giorgio Arenab83e6722022-03-24 14:23:07 +0000506
SiCong Libf5274d2022-07-20 17:45:36 +0100507 if env['openmp']:
508 env.Append(LINKFLAGS = ['-static-openmp'])
509
510 # For NDK >= r23, clang 12 or above is used. This condition detects NDK < r23
511 if not version_at_least(compiler_ver, '12.0.0'):
512 # System assembler is deprecated and integrated assembler is preferred since r23.
513 # However integrated assembler has always been suppressed for NDK < r23.
514 # Thus for backward compatibility, we include this flag only for NDK < r23
515 env.Append(CXXFLAGS = ['-no-integrated-as'])
Giorgio Arenab83e6722022-03-24 14:23:07 +0000516
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100517if env['high_priority'] and env['build_config']:
SiCongLidc85d782021-12-17 13:22:55 +0000518 print("The high priority library cannot be built in conjunction with a user-specified build configuration")
Georgios Pinitasb6af4822021-09-14 12:33:34 +0100519 Exit(1)
520
521if not env['high_priority'] and not env['build_config']:
522 env.Append(CPPDEFINES = ['ARM_COMPUTE_GRAPH_ENABLED'])
523
Freddie Liardet487d3902021-09-21 12:36:43 +0100524data_types = []
525data_layouts = []
Georgios Pinitasff4fca02020-10-02 21:00:00 +0100526
Freddie Liardet487d3902021-09-21 12:36:43 +0100527# Set correct data types / layouts to build
528if env['high_priority']:
529 data_types = ['all']
530 data_layouts = ['all']
531elif env['build_config']:
532 data_types, data_layouts = read_build_config_json(env['build_config'])
533else:
534 data_types = env['data_type_support']
535 data_layouts = env['data_layout_support']
536
537env = update_data_type_layout_flags(env, data_types, data_layouts)
Sheri Zhang79144a62021-02-08 17:43:04 +0000538
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100539if env['standalone']:
Pablo Tello29cab362022-03-10 17:05:34 +0000540 if not 'windows' in env['os']:
Pablo Tello4e66d702022-03-07 18:20:12 +0000541 env.Append(CXXFLAGS = ['-fPIC'])
Pablo Tello29cab362022-03-10 17:05:34 +0000542 env.Append(LINKFLAGS = ['-static-libgcc','-static-libstdc++'])
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100543
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100544if env['Werror']:
545 env.Append(CXXFLAGS = ['-Werror'])
546
547if env['os'] == 'android':
548 env.Append(CPPDEFINES = ['ANDROID'])
Michalis Spyrou2d22c3f2020-02-12 14:50:19 +0000549 env.Append(LINKFLAGS = ['-pie', '-static-libstdc++', '-ldl'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100550elif env['os'] == 'bare_metal':
551 env.Append(LINKFLAGS = ['-static'])
552 env.Append(CXXFLAGS = ['-fPIC'])
Manuel Bottinie5a9ad82020-11-18 16:22:16 +0000553 if env['specs_file'] == "":
554 env.Append(LINKFLAGS = ['-specs=rdimon.specs'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100555 env.Append(CPPDEFINES = ['NO_MULTI_THREADING'])
Michalis Spyrou07781ac2017-08-31 15:11:41 +0100556 env.Append(CPPDEFINES = ['BARE_METAL'])
Manuel Bottini827817e2020-11-19 12:12:06 +0000557if env['os'] == 'linux' and env['arch'] == 'armv7a':
558 env.Append(CXXFLAGS = [ '-Wno-psabi' ])
Pablo Tello4e66d702022-03-07 18:20:12 +0000559if env['os'] == 'windows':
560 env.Append(CXXFLAGS = [ '/std:c++14','/EHa'])
561 env.Append(CXXFLAGS = [ '-Wno-c++98-compat', '-Wno-covered-switch-default','-Wno-c++98-compat-pedantic'])
562 env.Append(CXXFLAGS = [ '-Wno-shorten-64-to-32', '-Wno-sign-conversion','-Wno-documentation'])
563 env.Append(CXXFLAGS = [ '-Wno-extra-semi-stmt', '-Wno-float-equal','-Wno-implicit-int-conversion'])
564 env.Append(CXXFLAGS = [ '-Wno-documentation-pedantic', '-Wno-extra-semi','-Wno-shadow-field-in-constructor'])
565 env.Append(CXXFLAGS = [ '-Wno-float-conversion', '-Wno-switch-enum','-Wno-comma'])
566 env.Append(CXXFLAGS = [ '-Wno-implicit-float-conversion', '-Wno-deprecated-declarations','-Wno-old-style-cast'])
567 env.Append(CXXFLAGS = [ '-Wno-zero-as-null-pointer-constant', '-Wno-inconsistent-missing-destructor-override'])
Pablo Tellofbbfa532023-01-26 16:24:04 +0000568 env.Append(CXXFLAGS = [ '-Wno-asm-operand-widths'])
569
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100570
Manuel Bottinie5a9ad82020-11-18 16:22:16 +0000571if env['specs_file'] != "":
572 env.Append(LINKFLAGS = ['-specs='+env['specs_file']])
573
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000574if env['neon']:
575 env.Append(CPPDEFINES = ['ARM_COMPUTE_CPU_ENABLED'])
576
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100577if env['opencl']:
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000578 env.Append(CPPDEFINES = ['ARM_COMPUTE_OPENCL_ENABLED'])
Georgios Pinitase6032da2017-10-26 14:13:35 +0100579 if env['os'] in ['bare_metal'] or env['standalone']:
Anthony Barbier5f0124d2018-04-13 14:05:34 +0100580 print("Cannot link OpenCL statically, which is required for bare metal / standalone builds")
581 Exit(1)
582
Pablo Tello29cab362022-03-10 17:05:34 +0000583if env["os"] not in ["windows","android", "bare_metal"] and (env['opencl'] or env['cppthreads']):
Anthony Barbier9fb0cac2018-04-20 15:46:21 +0100584 env.Append(LIBS = ['pthread'])
585
Kevin Lo7195f712022-01-07 15:46:02 +0800586if env['os'] == 'openbsd':
587 env.Append(LIBS = ['c'])
588 env.Append(CXXFLAGS = ['-fPIC'])
589
Manuel Bottiniceaa0bf2021-02-16 15:15:19 +0000590if env['opencl']:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100591 if env['embed_kernels']:
592 env.Append(CPPDEFINES = ['EMBEDDED_KERNELS'])
Georgios Pinitasea857272021-01-22 05:47:37 +0000593 if env['compress_kernels']:
594 env.Append(CPPDEFINES = ['ARM_COMPUTE_COMPRESSED_KERNELS'])
595 env.Append(LIBS = ['z'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100596
597if env['debug']:
598 env['asserts'] = True
Pablo Tello29cab362022-03-10 17:05:34 +0000599 if not 'windows' in env['os']:
600 env.Append(CXXFLAGS = ['-O0','-g','-gdwarf-2'])
601 else:
602 env.Append(CXXFLAGS = ['-Z7','-MTd','-fms-compatibility','-fdelayed-template-parsing'])
603 env.Append(LINKFLAGS = ['-DEBUG'])
Pablo Marquez Tello9f7aca92023-08-16 15:21:44 +0100604
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100605 env.Append(CPPDEFINES = ['ARM_COMPUTE_DEBUG_ENABLED'])
606else:
Pablo Tello4e66d702022-03-07 18:20:12 +0000607 if not 'windows' in env['os']:
608 env.Append(CXXFLAGS = ['-O3'])
609 else:
610 # on windows we use clang-cl which does not support the option -O3
611 env.Append(CXXFLAGS = ['-O2'])
Pablo Tello29cab362022-03-10 17:05:34 +0000612
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100613if env['asserts']:
614 env.Append(CPPDEFINES = ['ARM_COMPUTE_ASSERTS_ENABLED'])
Pablo Tello29cab362022-03-10 17:05:34 +0000615 if not 'windows' in env['os']:
616 env.Append(CXXFLAGS = ['-fstack-protector-strong'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100617
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +0100618if env['logging']:
619 env.Append(CPPDEFINES = ['ARM_COMPUTE_LOGGING_ENABLED'])
620
Matthew Bentham0a59e692023-07-19 15:01:00 +0000621if env['thread_sanitizer']:
622 env.Append(CXXFLAGS = ['-fsanitize=thread'])
623 env.Append(LINKFLAGS = ['-fsanitize=thread'])
624
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100625env.Append(CPPPATH = ['#/include', "#"])
626env.Append(CXXFLAGS = env['extra_cxx_flags'])
Georgios Pinitas421405b2018-10-26 19:05:32 +0100627env.Append(LINKFLAGS = env['extra_link_flags'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100628
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000629Default( install_include("arm_compute"))
Anthony Barbier10565952018-11-15 09:50:06 +0000630Default( install_include("support"))
Michele Di Giorgio6afea902019-04-03 11:40:20 +0100631Default( install_include("utils"))
632for dirname in os.listdir("./include"):
633 Default( install_include("include/%s" % dirname))
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000634
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100635Export('version_at_least')
636
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100637SConscript('./SConscript', variant_dir=build_path, duplicate=0)
Anthony Barbier6c0348f2017-11-10 18:32:38 +0000638
Freddie Liardet487d3902021-09-21 12:36:43 +0100639if env['examples'] and (env['build_config'] or env['high_priority']):
640 print("WARNING: Building examples for selected operators not supported. Use examples=0")
641 Return()
642
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100643if env['examples'] and env['exceptions']:
644 if env['os'] == 'bare_metal' and env['arch'] == 'armv7a':
Michalis Spyrou35f35a62019-12-23 11:29:52 +0000645 print("WARNING: Building examples for bare metal and armv7a is not supported. Use examples=0")
646 Return()
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100647 SConscript('./examples/SConscript', variant_dir='%s/examples' % build_path, duplicate=0)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100648
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100649if env['exceptions']:
Freddie Liardet487d3902021-09-21 12:36:43 +0100650 if env['build_config'] or env['high_priority']:
651 print("WARNING: Building tests for selected operators not supported")
652 Return()
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100653 if env['os'] == 'bare_metal' and env['arch'] == 'armv7a':
654 print("WARNING: Building tests for bare metal and armv7a is not supported")
655 Return()
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100656 SConscript('./tests/SConscript', variant_dir='%s/tests' % build_path, duplicate=0)
Motti Gondabif76a5022021-12-21 13:19:29 +0200657
658# Unknown variables are not allowed
659# Note: we must delay the call of UnknownVariables until after
660# we have applied the Variables object to the construction environment
661unknown = vars.UnknownVariables()
662if unknown:
663 print("Unknown variables: %s" % " ".join(unknown.keys()))
Ramy Elgammal451c3092022-02-01 23:01:27 +0000664 Exit(1)