blob: 4606159a0fb49f152f8155dfcba00a39ba757e7d [file] [log] [blame]
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01001# Copyright (c) 2016, 2017 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002#
3# SPDX-License-Identifier: MIT
4#
5# Permission is hereby granted, free of charge, to any person obtaining a copy
6# of this software and associated documentation files (the "Software"), to
7# deal in the Software without restriction, including without limitation the
8# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9# sell copies of the Software, and to permit persons to whom the Software is
10# furnished to do so, subject to the following conditions:
11#
12# The above copyright notice and this permission notice shall be included in all
13# copies or substantial portions of the Software.
14#
15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21# SOFTWARE.
22
23import SCons
24import os
25import subprocess
26
27def version_at_least(version, required):
Anthony Barbier6ff3b192017-09-04 18:44:23 +010028
Michalis Spyroucfac3052020-10-14 12:06:28 +010029 version_list = version.split('.')
30 required_list = required.split('.')
31 end = min(len(version_list), len(required_list))
32 for i in range(0, end):
33 if int(version_list[i]) < int(required_list[i]):
Anthony Barbier6ff3b192017-09-04 18:44:23 +010034 return False
Michalis Spyroucfac3052020-10-14 12:06:28 +010035 elif int(version_list[i]) > int(required_list[i]):
Anthony Barbier6ff3b192017-09-04 18:44:23 +010036 return True
37
38 return True
39
40vars = Variables("scons")
41vars.AddVariables(
42 BoolVariable("debug", "Debug", False),
43 BoolVariable("asserts", "Enable asserts (this flag is forced to 1 for debug=1)", False),
Georgios Pinitas3faea252017-10-30 14:13:50 +000044 BoolVariable("logging", "Logging (this flag is forced to 1 for debug=1)", False),
Georgios Pinitasf2cdce32019-12-09 18:35:57 +000045 EnumVariable("arch", "Target Architecture", "armv7a",
Manuel Bottinie5a9ad82020-11-18 16:22:16 +000046 allowed_values=("armv7a", "arm64-v8a", "arm64-v8.2-a", "arm64-v8.2-a-sve", "arm64-v8.2-a-sve2", "x86_32", "x86_64",
47 "armv8a", "armv8.2-a", "armv8.2-a-sve", "armv8.6-a", "armv8.6-a-sve", "armv8.6-a-sve2", "x86")),
Georgios Pinitasf2cdce32019-12-09 18:35:57 +000048 EnumVariable("estate", "Execution State", "auto", allowed_values=("auto", "32", "64")),
Georgios Pinitas45514032020-12-30 00:03:09 +000049 EnumVariable("os", "Target OS", "linux", allowed_values=("linux", "android", "tizen", "macos", "bare_metal")),
Anthony Barbier6a3daf12018-02-19 17:24:27 +000050 EnumVariable("build", "Build type", "cross_compile", allowed_values=("native", "cross_compile", "embed_only")),
Anthony Barbier6ff3b192017-09-04 18:44:23 +010051 BoolVariable("examples", "Build example programs", True),
SiCong Li8b4c7302019-09-19 12:18:15 +010052 BoolVariable("gemm_tuner", "Build gemm_tuner programs", True),
Anthony Barbier6ff3b192017-09-04 18:44:23 +010053 BoolVariable("Werror", "Enable/disable the -Werror compilation flag", True),
Pablo Telloc6cb35a2017-06-21 15:39:47 +010054 BoolVariable("standalone", "Builds the tests as standalone executables, links statically with libgcc, libstdc++ and libarm_compute", False),
Anthony Barbier6ff3b192017-09-04 18:44:23 +010055 BoolVariable("opencl", "Enable OpenCL support", True),
56 BoolVariable("neon", "Enable Neon support", False),
Anthony Barbier7068f992017-10-26 15:23:08 +010057 BoolVariable("gles_compute", "Enable OpenGL ES Compute Shader support", False),
Anthony Barbiercc0a80b2017-12-15 11:37:29 +000058 BoolVariable("embed_kernels", "Embed OpenCL kernels and OpenGL ES compute shaders in library binary", True),
Anthony Barbier6ff3b192017-09-04 18:44:23 +010059 BoolVariable("set_soname", "Set the library's soname and shlibversion (requires SCons 2.4 or above)", False),
Anthony Barbierb4670212018-05-18 16:55:39 +010060 BoolVariable("tracing", "Enable runtime tracing", False),
Anthony Barbier6ff3b192017-09-04 18:44:23 +010061 BoolVariable("openmp", "Enable OpenMP backend", False),
62 BoolVariable("cppthreads", "Enable C++11 threads backend", True),
63 PathVariable("build_dir", "Specify sub-folder for the build", ".", PathVariable.PathAccept),
Anthony Barbier01bbd5f2018-11-01 15:10:51 +000064 PathVariable("install_dir", "Specify sub-folder for the install", "", PathVariable.PathAccept),
Michalis Spyrou323ce0f2018-11-30 16:30:43 +000065 BoolVariable("exceptions", "Enable/disable C++ exception support", True),
Michalis Spyrou748a7c82019-10-07 13:00:44 +010066 PathVariable("linker_script", "Use an external linker script", "", PathVariable.PathAccept),
Michele Di Giorgio72610dc2020-11-18 15:29:08 +000067 PathVariable("external_tests_dir", "Add examples, benchmarks and tests to the tests suite", "", PathVariable.PathAccept),
Georgios Pinitas49c6ced2020-09-21 17:16:09 +010068 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 +000069 ListVariable("data_type_support", "Enable a list of data types to support", "all", ["qasymm8", "qasymm8_signed", "qsymm16", "fp16", "fp32", "integer"]),
Anthony Barbier149de5b2018-12-06 10:27:37 +000070 ("toolchain_prefix", "Override the toolchain prefix", ""),
alered01d8872c12020-02-10 11:29:45 +000071 ("compiler_prefix", "Override the compiler prefix", ""),
Anthony Barbier7390e052018-03-13 09:29:41 +000072 ("extra_cxx_flags", "Extra CXX flags to be appended to the build command", ""),
Georgios Pinitas421405b2018-10-26 19:05:32 +010073 ("extra_link_flags", "Extra LD flags to be appended to the build command", ""),
Manuel Bottinie5a9ad82020-11-18 16:22:16 +000074 ("compiler_cache", "Command to prefix to the C and C++ compiler (e.g ccache)", ""),
75 ("specs_file", "Specs file to use (e.g. rdimon.specs)", "")
Anthony Barbier6ff3b192017-09-04 18:44:23 +010076)
77
78env = Environment(platform="posix", variables=vars, ENV = os.environ)
Anthony Barbiere8a55df2018-10-26 09:05:01 +010079build_path = env['build_dir']
80# If build_dir is a relative path then add a #build/ prefix:
81if not env['build_dir'].startswith('/'):
82 SConsignFile('build/%s/.scons' % build_path)
83 build_path = "#build/%s" % build_path
84else:
85 SConsignFile('%s/.scons' % build_path)
86
Anthony Barbier01bbd5f2018-11-01 15:10:51 +000087install_path = env['install_dir']
88#If the install_dir is a relative path then assume it's from inside build_dir
89if not env['install_dir'].startswith('/') and install_path != "":
90 install_path = "%s/%s" % (build_path, install_path)
91
Anthony Barbiere8a55df2018-10-26 09:05:01 +010092env.Append(LIBPATH = [build_path])
Anthony Barbier6a3daf12018-02-19 17:24:27 +000093Export('env')
94Export('vars')
Anthony Barbier6ff3b192017-09-04 18:44:23 +010095
Anthony Barbier01bbd5f2018-11-01 15:10:51 +000096def install_lib( lib ):
97 # If there is no install folder, then there is nothing to do:
98 if install_path == "":
99 return lib
100 return env.Install( "%s/lib/" % install_path, lib)
101def install_bin( bin ):
102 # If there is no install folder, then there is nothing to do:
103 if install_path == "":
104 return bin
105 return env.Install( "%s/bin/" % install_path, bin)
106def install_include( inc ):
107 if install_path == "":
108 return inc
109 return env.Install( "%s/include/" % install_path, inc)
110
111Export('install_lib')
112Export('install_bin')
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100113
114Help(vars.GenerateHelpText(env))
115
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100116if env['linker_script'] and env['os'] != 'bare_metal':
117 print("Linker script is only supported for bare_metal builds")
118 Exit(1)
119
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000120if env['build'] == "embed_only":
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100121 SConscript('./SConscript', variant_dir=build_path, duplicate=0)
Anthony Barbier6a3daf12018-02-19 17:24:27 +0000122 Return()
123
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100124if env['neon'] and 'x86' in env['arch']:
ggardet767c9f72018-06-29 17:01:01 +0200125 print("Cannot compile NEON for x86")
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100126 Exit(1)
127
128if env['set_soname'] and not version_at_least(SCons.__version__, "2.4"):
ggardet767c9f72018-06-29 17:01:01 +0200129 print("Setting the library's SONAME / SHLIBVERSION requires SCons 2.4 or above")
130 print("Update your version of SCons or use set_soname=0")
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100131 Exit(1)
132
133if env['os'] == 'bare_metal':
134 if env['cppthreads'] or env['openmp']:
135 print("ERROR: OpenMP and C++11 threads not supported in bare_metal. Use cppthreads=0 openmp=0")
136 Exit(1)
137
Michalis Spyrou323ce0f2018-11-30 16:30:43 +0000138if not env['exceptions']:
139 if env['opencl'] or env['gles_compute']:
140 print("ERROR: OpenCL and GLES are not supported when building without exceptions. Use opencl=0 gles_compute=0")
141 Exit(1)
142
143 env.Append(CPPDEFINES = ['ARM_COMPUTE_EXCEPTIONS_DISABLED'])
144 env.Append(CXXFLAGS = ['-fno-exceptions'])
145
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100146env.Append(CXXFLAGS = ['-Wall','-DARCH_ARM',
Michalis Spyrou7c60c992019-10-10 14:33:47 +0100147 '-Wextra','-pedantic','-Wdisabled-optimization','-Wformat=2',
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100148 '-Winit-self','-Wstrict-overflow=2','-Wswitch-default',
Georgios Pinitas40f51a62020-11-21 03:04:18 +0000149 '-std=c++14','-Woverloaded-virtual', '-Wformat-security',
Michalis Spyroufae513c2019-10-16 17:41:33 +0100150 '-Wctor-dtor-privacy','-Wsign-promo','-Weffc++','-Wno-overlength-strings'])
Isabella Gottardib28f29d2017-11-09 17:05:07 +0000151
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100152env.Append(CPPDEFINES = ['_GLIBCXX_USE_NANOSLEEP'])
153
Georgios Pinitas45514032020-12-30 00:03:09 +0000154default_cpp_compiler = 'g++' if env['os'] not in ['android', 'macos'] else 'clang++'
155default_c_compiler = 'gcc' if env['os'] not in ['android', 'macos'] else 'clang'
Anthony Barbiera026e982018-01-18 10:57:52 +0000156cpp_compiler = os.environ.get('CXX', default_cpp_compiler)
157c_compiler = os.environ.get('CC', default_c_compiler)
158
Anthony Barbierdd669372018-03-01 17:08:54 +0000159if env['os'] == 'android' and ( 'clang++' not in cpp_compiler or 'clang' not in c_compiler ):
ggardet767c9f72018-06-29 17:01:01 +0200160 print( "WARNING: Only clang is officially supported to build the Compute Library for Android")
Anthony Barbiera026e982018-01-18 10:57:52 +0000161
Anthony Barbierdd669372018-03-01 17:08:54 +0000162if 'clang++' in cpp_compiler:
Michalis Spyrou7c60c992019-10-10 14:33:47 +0100163 env.Append(CXXFLAGS = ['-Wno-vla-extension'])
Georgios Pinitase874ef92019-09-09 17:40:33 +0100164elif 'armclang' in cpp_compiler:
165 pass
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100166else:
Michalis Spyrou7c60c992019-10-10 14:33:47 +0100167 env.Append(CXXFLAGS = ['-Wlogical-op','-Wnoexcept','-Wstrict-null-sentinel'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100168
SiCongLi410e21e2020-12-11 15:07:53 +0000169if cpp_compiler == 'g++':
170 # Don't strip comments that could include markers
171 env.Append(CXXFLAGS = ['-C'])
172
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100173if env['cppthreads']:
174 env.Append(CPPDEFINES = [('ARM_COMPUTE_CPP_SCHEDULER', 1)])
175
176if env['openmp']:
Anthony Barbierdd669372018-03-01 17:08:54 +0000177 if 'clang++' in cpp_compiler:
ggardet767c9f72018-06-29 17:01:01 +0200178 print( "Clang does not support OpenMP. Use scheduler=cpp.")
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100179 Exit(1)
180
181 env.Append(CPPDEFINES = [('ARM_COMPUTE_OPENMP_SCHEDULER', 1)])
182 env.Append(CXXFLAGS = ['-fopenmp'])
183 env.Append(LINKFLAGS = ['-fopenmp'])
184
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000185# Validate and define state
186if env['estate'] == 'auto':
187 if 'v7a' in env['arch']:
188 env['estate'] = '32'
189 else:
190 env['estate'] = '64'
191
192# Map legacy arch
193if 'arm64' in env['arch']:
194 env['estate'] = '64'
195
196if 'v7a' in env['estate'] and env['estate'] == '64':
197 print("ERROR: armv7a architecture has only 32-bit execution state")
198 Exit(1)
199
Georgios Pinitase874ef92019-09-09 17:40:33 +0100200# Add architecture specific flags
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100201prefix = ""
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000202if 'v7a' in env['arch']:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100203 env.Append(CXXFLAGS = ['-march=armv7-a', '-mthumb', '-mfpu=neon'])
Inki Dae51a95582020-03-23 08:29:02 +0900204 if env['os'] == 'android' or env['os'] == 'tizen':
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100205 env.Append(CXXFLAGS = ['-mfloat-abi=softfp'])
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000206 else:
207 env.Append(CXXFLAGS = ['-mfloat-abi=hard'])
Georgios Pinitas94672fb2020-01-22 18:36:27 +0000208elif 'v8' in env['arch']:
Manuel Bottinie5a9ad82020-11-18 16:22:16 +0000209 if 'sve2' in env['arch']:
210 env.Append(CXXFLAGS = ['-march=armv8.2-a+sve2+fp16+dotprod'])
Georgios Pinitas045d33c2020-12-07 20:52:55 +0000211 env.Append(CPPDEFINES = ['SVE2'])
Manuel Bottinie5a9ad82020-11-18 16:22:16 +0000212 elif 'sve' in env['arch']:
Georgios Pinitas421405b2018-10-26 19:05:32 +0100213 env.Append(CXXFLAGS = ['-march=armv8.2-a+sve+fp16+dotprod'])
Georgios Pinitasdeb5b772020-12-07 20:39:51 +0000214 elif 'v8.' in env['arch']:
Georgios Pinitas421405b2018-10-26 19:05:32 +0100215 env.Append(CXXFLAGS = ['-march=armv8.2-a+fp16']) # explicitly enable fp16 extension otherwise __ARM_FEATURE_FP16_VECTOR_ARITHMETIC is undefined
Georgios Pinitas94672fb2020-01-22 18:36:27 +0000216 else:
217 env.Append(CXXFLAGS = ['-march=armv8-a'])
218
219 if 'v8.6-a' in env['arch']:
Georgios Pinitas49c6ced2020-09-21 17:16:09 +0100220 env.Append(CPPDEFINES = ['MMLA_INT8', 'V8P6', 'V8P6_BF', 'ARM_COMPUTE_FORCE_BF16'])
221 if "disable_mmla_fp" not in env['custom_options']:
222 env.Append(CPPDEFINES = ['MMLA_FP32'])
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000223elif 'x86' in env['arch']:
224 if env['estate'] == '32':
225 env.Append(CCFLAGS = ['-m32'])
226 env.Append(LINKFLAGS = ['-m32'])
227 else:
228 env.Append(CXXFLAGS = ['-fPIC'])
229 env.Append(CCFLAGS = ['-m64'])
230 env.Append(LINKFLAGS = ['-m64'])
231
232# Define toolchain
233prefix = ""
234if 'x86' not in env['arch']:
235 if env['estate'] == '32':
236 if env['os'] == 'linux':
237 prefix = "arm-linux-gnueabihf-" if 'v7' in env['arch'] else "armv8l-linux-gnueabihf-"
238 elif env['os'] == 'bare_metal':
239 prefix = "arm-eabi-"
240 elif env['os'] == 'android':
241 prefix = "arm-linux-androideabi-"
Inki Dae51a95582020-03-23 08:29:02 +0900242 elif env['os'] == 'tizen':
243 prefix = "armv7l-tizen-linux-gnueabi-"
Georgios Pinitasf2cdce32019-12-09 18:35:57 +0000244 elif env['estate'] == '64' and 'v8' in env['arch']:
245 if env['os'] == 'linux':
246 prefix = "aarch64-linux-gnu-"
247 elif env['os'] == 'bare_metal':
248 prefix = "aarch64-elf-"
249 elif env['os'] == 'android':
250 prefix = "aarch64-linux-android-"
Inki Dae51a95582020-03-23 08:29:02 +0900251 elif env['os'] == 'tizen':
252 prefix = "aarch64-tizen-linux-gnu-"
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100253
254if env['build'] == 'native':
255 prefix = ""
256
Anthony Barbier149de5b2018-12-06 10:27:37 +0000257if env["toolchain_prefix"] != "":
258 prefix = env["toolchain_prefix"]
259
alered01d8872c12020-02-10 11:29:45 +0000260compiler_prefix = prefix
261if env["compiler_prefix"] != "":
262 compiler_prefix = env["compiler_prefix"]
263
264env['CC'] = env['compiler_cache']+ " " + compiler_prefix + c_compiler
265env['CXX'] = env['compiler_cache']+ " " + compiler_prefix + cpp_compiler
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100266env['LD'] = prefix + "ld"
267env['AS'] = prefix + "as"
268env['AR'] = prefix + "ar"
269env['RANLIB'] = prefix + "ranlib"
270
271if not GetOption("help"):
272 try:
SiCong Li3b9a5642020-10-16 12:10:15 +0100273 compiler_ver = subprocess.check_output(env['CXX'].split() + ["-dumpversion"]).decode().strip()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100274 except OSError:
275 print("ERROR: Compiler '%s' not found" % env['CXX'])
276 Exit(1)
277
Georgios Pinitase874ef92019-09-09 17:40:33 +0100278 if 'armclang' in cpp_compiler:
279 pass
280 elif 'clang++' not in cpp_compiler:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100281 if env['arch'] == 'arm64-v8.2-a' and not version_at_least(compiler_ver, '6.2.1'):
ggardet767c9f72018-06-29 17:01:01 +0200282 print("GCC 6.2.1 or newer is required to compile armv8.2-a code")
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100283 Exit(1)
284 elif env['arch'] == 'arm64-v8a' and not version_at_least(compiler_ver, '4.9'):
ggardet767c9f72018-06-29 17:01:01 +0200285 print("GCC 4.9 or newer is required to compile NEON code for AArch64")
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100286 Exit(1)
287
288 if version_at_least(compiler_ver, '6.1'):
289 env.Append(CXXFLAGS = ['-Wno-ignored-attributes'])
290
291 if compiler_ver == '4.8.3':
292 env.Append(CXXFLAGS = ['-Wno-array-bounds'])
293
Michalis Spyroucfac3052020-10-14 12:06:28 +0100294 if not version_at_least(compiler_ver, '7.0.0') and env['os'] == 'bare_metal':
295 env.Append(LINKFLAGS = ['-fstack-protector-strong'])
296
Georgios Pinitasff4fca02020-10-02 21:00:00 +0100297if env['data_type_support']:
298 if any(i in env['data_type_support'] for i in ['all', 'fp16']):
299 env.Append(CXXFLAGS = ['-DENABLE_FP16_KERNELS'])
300 if any(i in env['data_type_support'] for i in ['all', 'fp32']):
301 env.Append(CXXFLAGS = ['-DENABLE_FP32_KERNELS'])
Michalis Spyrouc4d45552020-10-19 12:41:30 +0100302 if any(i in env['data_type_support'] for i in ['all', 'qasymm8']):
303 env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_KERNELS'])
304 if any(i in env['data_type_support'] for i in ['all', 'qasymm8_signed']):
305 env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_SIGNED_KERNELS'])
306 if any(i in env['data_type_support'] for i in ['all', 'qsymm16']):
307 env.Append(CXXFLAGS = ['-DENABLE_QSYMM16_KERNELS'])
Michalis Spyroua3c9a3b2020-12-08 21:02:16 +0000308 if any(i in env['data_type_support'] for i in ['all', 'integer']):
309 env.Append(CXXFLAGS = ['-DENABLE_INTEGER_KERNELS'])
Georgios Pinitasff4fca02020-10-02 21:00:00 +0100310
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100311if env['standalone']:
312 env.Append(CXXFLAGS = ['-fPIC'])
Anthony Barbier665c89b2018-07-16 11:40:09 +0100313 env.Append(LINKFLAGS = ['-static-libgcc','-static-libstdc++'])
Pablo Telloc6cb35a2017-06-21 15:39:47 +0100314
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100315if env['Werror']:
316 env.Append(CXXFLAGS = ['-Werror'])
317
318if env['os'] == 'android':
319 env.Append(CPPDEFINES = ['ANDROID'])
Michalis Spyrou2d22c3f2020-02-12 14:50:19 +0000320 env.Append(LINKFLAGS = ['-pie', '-static-libstdc++', '-ldl'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100321elif env['os'] == 'bare_metal':
322 env.Append(LINKFLAGS = ['-static'])
323 env.Append(CXXFLAGS = ['-fPIC'])
Manuel Bottinie5a9ad82020-11-18 16:22:16 +0000324 if env['specs_file'] == "":
325 env.Append(LINKFLAGS = ['-specs=rdimon.specs'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100326 env.Append(CPPDEFINES = ['NO_MULTI_THREADING'])
Michalis Spyrou07781ac2017-08-31 15:11:41 +0100327 env.Append(CPPDEFINES = ['BARE_METAL'])
Manuel Bottini827817e2020-11-19 12:12:06 +0000328if env['os'] == 'linux' and env['arch'] == 'armv7a':
329 env.Append(CXXFLAGS = [ '-Wno-psabi' ])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100330
Manuel Bottinie5a9ad82020-11-18 16:22:16 +0000331if env['specs_file'] != "":
332 env.Append(LINKFLAGS = ['-specs='+env['specs_file']])
333
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100334if env['opencl']:
Georgios Pinitase6032da2017-10-26 14:13:35 +0100335 if env['os'] in ['bare_metal'] or env['standalone']:
Anthony Barbier5f0124d2018-04-13 14:05:34 +0100336 print("Cannot link OpenCL statically, which is required for bare metal / standalone builds")
337 Exit(1)
338
339if env['gles_compute']:
340 if env['os'] in ['bare_metal'] or env['standalone']:
341 print("Cannot link OpenGLES statically, which is required for bare metal / standalone builds")
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100342 Exit(1)
343
Anthony Barbier9fb0cac2018-04-20 15:46:21 +0100344if env["os"] not in ["android", "bare_metal"] and (env['opencl'] or env['cppthreads']):
345 env.Append(LIBS = ['pthread'])
346
Anthony Barbier7068f992017-10-26 15:23:08 +0100347if env['opencl'] or env['gles_compute']:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100348 if env['embed_kernels']:
349 env.Append(CPPDEFINES = ['EMBEDDED_KERNELS'])
350
351if env['debug']:
352 env['asserts'] = True
Georgios Pinitas3faea252017-10-30 14:13:50 +0000353 env['logging'] = True
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100354 env.Append(CXXFLAGS = ['-O0','-g','-gdwarf-2'])
355 env.Append(CPPDEFINES = ['ARM_COMPUTE_DEBUG_ENABLED'])
356else:
Ramana Radhakrishnand176d542019-07-04 11:38:45 +0100357 env.Append(CXXFLAGS = ['-O3'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100358
359if env['asserts']:
360 env.Append(CPPDEFINES = ['ARM_COMPUTE_ASSERTS_ENABLED'])
Moritz Pflanzer8b74c782017-09-14 14:33:20 +0100361 env.Append(CXXFLAGS = ['-fstack-protector-strong'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100362
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +0100363if env['logging']:
364 env.Append(CPPDEFINES = ['ARM_COMPUTE_LOGGING_ENABLED'])
365
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100366env.Append(CPPPATH = ['#/include', "#"])
367env.Append(CXXFLAGS = env['extra_cxx_flags'])
Georgios Pinitas421405b2018-10-26 19:05:32 +0100368env.Append(LINKFLAGS = env['extra_link_flags'])
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100369
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000370Default( install_include("arm_compute"))
Anthony Barbier10565952018-11-15 09:50:06 +0000371Default( install_include("support"))
Michele Di Giorgio6afea902019-04-03 11:40:20 +0100372Default( install_include("utils"))
373for dirname in os.listdir("./include"):
374 Default( install_include("include/%s" % dirname))
Anthony Barbier01bbd5f2018-11-01 15:10:51 +0000375
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100376Export('version_at_least')
377
Anthony Barbier7068f992017-10-26 15:23:08 +0100378if env['gles_compute'] and env['os'] != 'android':
Anthony Barbier14c86a92017-12-14 16:27:41 +0000379 env.Append(CPPPATH = ['#/include/linux'])
Anthony Barbier7068f992017-10-26 15:23:08 +0100380
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100381SConscript('./SConscript', variant_dir=build_path, duplicate=0)
Anthony Barbier6c0348f2017-11-10 18:32:38 +0000382
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100383if env['examples'] and env['exceptions']:
384 if env['os'] == 'bare_metal' and env['arch'] == 'armv7a':
Michalis Spyrou35f35a62019-12-23 11:29:52 +0000385 print("WARNING: Building examples for bare metal and armv7a is not supported. Use examples=0")
386 Return()
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100387 SConscript('./examples/SConscript', variant_dir='%s/examples' % build_path, duplicate=0)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100388
Michalis Spyrou748a7c82019-10-07 13:00:44 +0100389if env['exceptions']:
390 if env['os'] == 'bare_metal' and env['arch'] == 'armv7a':
391 print("WARNING: Building tests for bare metal and armv7a is not supported")
392 Return()
Anthony Barbiere8a55df2018-10-26 09:05:01 +0100393 SConscript('./tests/SConscript', variant_dir='%s/tests' % build_path, duplicate=0)