Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 1 | # Copyright (c) 2016, 2017 Arm Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 2 | # |
| 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 | |
| 23 | import SCons |
| 24 | import os |
| 25 | import subprocess |
| 26 | |
| 27 | def version_at_least(version, required): |
| 28 | end = min(len(version), len(required)) |
| 29 | |
| 30 | for i in range(0, end, 2): |
| 31 | if int(version[i]) < int(required[i]): |
| 32 | return False |
| 33 | elif int(version[i]) > int(required[i]): |
| 34 | return True |
| 35 | |
| 36 | return True |
| 37 | |
| 38 | vars = Variables("scons") |
| 39 | vars.AddVariables( |
| 40 | BoolVariable("debug", "Debug", False), |
| 41 | BoolVariable("asserts", "Enable asserts (this flag is forced to 1 for debug=1)", False), |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 42 | BoolVariable("logging", "Logging (this flag is forced to 1 for debug=1)", False), |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 43 | EnumVariable("arch", "Target Architecture", "armv7a", |
Georgios Pinitas | 94672fb | 2020-01-22 18:36:27 +0000 | [diff] [blame] | 44 | allowed_values=("armv7a", "arm64-v8a", "arm64-v8.2-a", "arm64-v8.2-a-sve", "x86_32", "x86_64", |
| 45 | "armv8a", "armv8.2-a", "armv8.2-a-sve", "armv8.6-a", "x86")), |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 46 | EnumVariable("estate", "Execution State", "auto", allowed_values=("auto", "32", "64")), |
Inki Dae | 51a9558 | 2020-03-23 08:29:02 +0900 | [diff] [blame] | 47 | EnumVariable("os", "Target OS", "linux", allowed_values=("linux", "android", "tizen", "bare_metal")), |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 48 | EnumVariable("build", "Build type", "cross_compile", allowed_values=("native", "cross_compile", "embed_only")), |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 49 | BoolVariable("examples", "Build example programs", True), |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 50 | BoolVariable("gemm_tuner", "Build gemm_tuner programs", True), |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 51 | BoolVariable("Werror", "Enable/disable the -Werror compilation flag", True), |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 52 | BoolVariable("standalone", "Builds the tests as standalone executables, links statically with libgcc, libstdc++ and libarm_compute", False), |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 53 | BoolVariable("opencl", "Enable OpenCL support", True), |
| 54 | BoolVariable("neon", "Enable Neon support", False), |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 55 | BoolVariable("gles_compute", "Enable OpenGL ES Compute Shader support", False), |
Anthony Barbier | cc0a80b | 2017-12-15 11:37:29 +0000 | [diff] [blame] | 56 | BoolVariable("embed_kernels", "Embed OpenCL kernels and OpenGL ES compute shaders in library binary", True), |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 57 | BoolVariable("set_soname", "Set the library's soname and shlibversion (requires SCons 2.4 or above)", False), |
Anthony Barbier | b467021 | 2018-05-18 16:55:39 +0100 | [diff] [blame] | 58 | BoolVariable("tracing", "Enable runtime tracing", False), |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 59 | BoolVariable("openmp", "Enable OpenMP backend", False), |
| 60 | BoolVariable("cppthreads", "Enable C++11 threads backend", True), |
| 61 | PathVariable("build_dir", "Specify sub-folder for the build", ".", PathVariable.PathAccept), |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 62 | PathVariable("install_dir", "Specify sub-folder for the install", "", PathVariable.PathAccept), |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 63 | BoolVariable("exceptions", "Enable/disable C++ exception support", True), |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 64 | PathVariable("linker_script", "Use an external linker script", "", PathVariable.PathAccept), |
Anthony Barbier | 149de5b | 2018-12-06 10:27:37 +0000 | [diff] [blame] | 65 | ("toolchain_prefix", "Override the toolchain prefix", ""), |
alered01 | d8872c1 | 2020-02-10 11:29:45 +0000 | [diff] [blame] | 66 | ("compiler_prefix", "Override the compiler prefix", ""), |
Anthony Barbier | 7390e05 | 2018-03-13 09:29:41 +0000 | [diff] [blame] | 67 | ("extra_cxx_flags", "Extra CXX flags to be appended to the build command", ""), |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 68 | ("extra_link_flags", "Extra LD flags to be appended to the build command", ""), |
Anthony Barbier | 7390e05 | 2018-03-13 09:29:41 +0000 | [diff] [blame] | 69 | ("compiler_cache", "Command to prefix to the C and C++ compiler (e.g ccache)", "") |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 70 | ) |
| 71 | |
| 72 | env = Environment(platform="posix", variables=vars, ENV = os.environ) |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 73 | build_path = env['build_dir'] |
| 74 | # If build_dir is a relative path then add a #build/ prefix: |
| 75 | if not env['build_dir'].startswith('/'): |
| 76 | SConsignFile('build/%s/.scons' % build_path) |
| 77 | build_path = "#build/%s" % build_path |
| 78 | else: |
| 79 | SConsignFile('%s/.scons' % build_path) |
| 80 | |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 81 | install_path = env['install_dir'] |
| 82 | #If the install_dir is a relative path then assume it's from inside build_dir |
| 83 | if not env['install_dir'].startswith('/') and install_path != "": |
| 84 | install_path = "%s/%s" % (build_path, install_path) |
| 85 | |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 86 | env.Append(LIBPATH = [build_path]) |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 87 | Export('env') |
| 88 | Export('vars') |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 89 | |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 90 | def install_lib( lib ): |
| 91 | # If there is no install folder, then there is nothing to do: |
| 92 | if install_path == "": |
| 93 | return lib |
| 94 | return env.Install( "%s/lib/" % install_path, lib) |
| 95 | def install_bin( bin ): |
| 96 | # If there is no install folder, then there is nothing to do: |
| 97 | if install_path == "": |
| 98 | return bin |
| 99 | return env.Install( "%s/bin/" % install_path, bin) |
| 100 | def install_include( inc ): |
| 101 | if install_path == "": |
| 102 | return inc |
| 103 | return env.Install( "%s/include/" % install_path, inc) |
| 104 | |
| 105 | Export('install_lib') |
| 106 | Export('install_bin') |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 107 | |
| 108 | Help(vars.GenerateHelpText(env)) |
| 109 | |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 110 | if env['linker_script'] and env['os'] != 'bare_metal': |
| 111 | print("Linker script is only supported for bare_metal builds") |
| 112 | Exit(1) |
| 113 | |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 114 | if env['build'] == "embed_only": |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 115 | SConscript('./SConscript', variant_dir=build_path, duplicate=0) |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 116 | Return() |
| 117 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 118 | if env['neon'] and 'x86' in env['arch']: |
ggardet | 767c9f7 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 119 | print("Cannot compile NEON for x86") |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 120 | Exit(1) |
| 121 | |
| 122 | if env['set_soname'] and not version_at_least(SCons.__version__, "2.4"): |
ggardet | 767c9f7 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 123 | print("Setting the library's SONAME / SHLIBVERSION requires SCons 2.4 or above") |
| 124 | print("Update your version of SCons or use set_soname=0") |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 125 | Exit(1) |
| 126 | |
| 127 | if env['os'] == 'bare_metal': |
| 128 | if env['cppthreads'] or env['openmp']: |
| 129 | print("ERROR: OpenMP and C++11 threads not supported in bare_metal. Use cppthreads=0 openmp=0") |
| 130 | Exit(1) |
| 131 | |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 132 | if not env['exceptions']: |
| 133 | if env['opencl'] or env['gles_compute']: |
| 134 | print("ERROR: OpenCL and GLES are not supported when building without exceptions. Use opencl=0 gles_compute=0") |
| 135 | Exit(1) |
| 136 | |
| 137 | env.Append(CPPDEFINES = ['ARM_COMPUTE_EXCEPTIONS_DISABLED']) |
| 138 | env.Append(CXXFLAGS = ['-fno-exceptions']) |
| 139 | |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 140 | env.Append(CXXFLAGS = ['-Wall','-DARCH_ARM', |
Michalis Spyrou | 7c60c99 | 2019-10-10 14:33:47 +0100 | [diff] [blame] | 141 | '-Wextra','-pedantic','-Wdisabled-optimization','-Wformat=2', |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 142 | '-Winit-self','-Wstrict-overflow=2','-Wswitch-default', |
Michalis Spyrou | 2d22c3f | 2020-02-12 14:50:19 +0000 | [diff] [blame] | 143 | '-std=gnu++11','-Woverloaded-virtual', '-Wformat-security', |
Michalis Spyrou | fae513c | 2019-10-16 17:41:33 +0100 | [diff] [blame] | 144 | '-Wctor-dtor-privacy','-Wsign-promo','-Weffc++','-Wno-overlength-strings']) |
Isabella Gottardi | b28f29d | 2017-11-09 17:05:07 +0000 | [diff] [blame] | 145 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 146 | env.Append(CPPDEFINES = ['_GLIBCXX_USE_NANOSLEEP']) |
| 147 | |
Anthony Barbier | a026e98 | 2018-01-18 10:57:52 +0000 | [diff] [blame] | 148 | default_cpp_compiler = 'g++' if env['os'] != 'android' else 'clang++' |
| 149 | default_c_compiler = 'gcc' if env['os'] != 'android' else 'clang' |
| 150 | cpp_compiler = os.environ.get('CXX', default_cpp_compiler) |
| 151 | c_compiler = os.environ.get('CC', default_c_compiler) |
| 152 | |
Anthony Barbier | dd66937 | 2018-03-01 17:08:54 +0000 | [diff] [blame] | 153 | if env['os'] == 'android' and ( 'clang++' not in cpp_compiler or 'clang' not in c_compiler ): |
ggardet | 767c9f7 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 154 | print( "WARNING: Only clang is officially supported to build the Compute Library for Android") |
Anthony Barbier | a026e98 | 2018-01-18 10:57:52 +0000 | [diff] [blame] | 155 | |
Anthony Barbier | dd66937 | 2018-03-01 17:08:54 +0000 | [diff] [blame] | 156 | if 'clang++' in cpp_compiler: |
Michalis Spyrou | 7c60c99 | 2019-10-10 14:33:47 +0100 | [diff] [blame] | 157 | env.Append(CXXFLAGS = ['-Wno-vla-extension']) |
Georgios Pinitas | e874ef9 | 2019-09-09 17:40:33 +0100 | [diff] [blame] | 158 | elif 'armclang' in cpp_compiler: |
| 159 | pass |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 160 | else: |
Michalis Spyrou | 7c60c99 | 2019-10-10 14:33:47 +0100 | [diff] [blame] | 161 | env.Append(CXXFLAGS = ['-Wlogical-op','-Wnoexcept','-Wstrict-null-sentinel']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 162 | |
| 163 | if env['cppthreads']: |
| 164 | env.Append(CPPDEFINES = [('ARM_COMPUTE_CPP_SCHEDULER', 1)]) |
| 165 | |
| 166 | if env['openmp']: |
Anthony Barbier | dd66937 | 2018-03-01 17:08:54 +0000 | [diff] [blame] | 167 | if 'clang++' in cpp_compiler: |
ggardet | 767c9f7 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 168 | print( "Clang does not support OpenMP. Use scheduler=cpp.") |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 169 | Exit(1) |
| 170 | |
| 171 | env.Append(CPPDEFINES = [('ARM_COMPUTE_OPENMP_SCHEDULER', 1)]) |
| 172 | env.Append(CXXFLAGS = ['-fopenmp']) |
| 173 | env.Append(LINKFLAGS = ['-fopenmp']) |
| 174 | |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 175 | # Validate and define state |
| 176 | if env['estate'] == 'auto': |
| 177 | if 'v7a' in env['arch']: |
| 178 | env['estate'] = '32' |
| 179 | else: |
| 180 | env['estate'] = '64' |
| 181 | |
| 182 | # Map legacy arch |
| 183 | if 'arm64' in env['arch']: |
| 184 | env['estate'] = '64' |
| 185 | |
| 186 | if 'v7a' in env['estate'] and env['estate'] == '64': |
| 187 | print("ERROR: armv7a architecture has only 32-bit execution state") |
| 188 | Exit(1) |
| 189 | |
Georgios Pinitas | e874ef9 | 2019-09-09 17:40:33 +0100 | [diff] [blame] | 190 | # Add architecture specific flags |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 191 | prefix = "" |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 192 | if 'v7a' in env['arch']: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 193 | env.Append(CXXFLAGS = ['-march=armv7-a', '-mthumb', '-mfpu=neon']) |
Inki Dae | 51a9558 | 2020-03-23 08:29:02 +0900 | [diff] [blame] | 194 | if env['os'] == 'android' or env['os'] == 'tizen': |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 195 | env.Append(CXXFLAGS = ['-mfloat-abi=softfp']) |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 196 | else: |
| 197 | env.Append(CXXFLAGS = ['-mfloat-abi=hard']) |
Georgios Pinitas | 94672fb | 2020-01-22 18:36:27 +0000 | [diff] [blame] | 198 | elif 'v8' in env['arch']: |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 199 | if 'sve' in env['arch']: |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 200 | env.Append(CXXFLAGS = ['-march=armv8.2-a+sve+fp16+dotprod']) |
Georgios Pinitas | 94672fb | 2020-01-22 18:36:27 +0000 | [diff] [blame] | 201 | elif 'v8.2-a' in env['arch']: |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 202 | env.Append(CXXFLAGS = ['-march=armv8.2-a+fp16']) # explicitly enable fp16 extension otherwise __ARM_FEATURE_FP16_VECTOR_ARITHMETIC is undefined |
Georgios Pinitas | 94672fb | 2020-01-22 18:36:27 +0000 | [diff] [blame] | 203 | else: |
| 204 | env.Append(CXXFLAGS = ['-march=armv8-a']) |
| 205 | |
| 206 | if 'v8.6-a' in env['arch']: |
Georgios Pinitas | 5aa1a0b | 2020-07-02 20:02:20 +0100 | [diff] [blame] | 207 | env.Append(CPPDEFINES = ['MMLA_INT8', 'MMLA_FP32', 'V8P6', 'V8P6_BF', 'ARM_COMPUTE_FORCE_BF16']) |
Georgios Pinitas | 94672fb | 2020-01-22 18:36:27 +0000 | [diff] [blame] | 208 | |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 209 | elif 'x86' in env['arch']: |
| 210 | if env['estate'] == '32': |
| 211 | env.Append(CCFLAGS = ['-m32']) |
| 212 | env.Append(LINKFLAGS = ['-m32']) |
| 213 | else: |
| 214 | env.Append(CXXFLAGS = ['-fPIC']) |
| 215 | env.Append(CCFLAGS = ['-m64']) |
| 216 | env.Append(LINKFLAGS = ['-m64']) |
| 217 | |
| 218 | # Define toolchain |
| 219 | prefix = "" |
| 220 | if 'x86' not in env['arch']: |
| 221 | if env['estate'] == '32': |
| 222 | if env['os'] == 'linux': |
| 223 | prefix = "arm-linux-gnueabihf-" if 'v7' in env['arch'] else "armv8l-linux-gnueabihf-" |
| 224 | elif env['os'] == 'bare_metal': |
| 225 | prefix = "arm-eabi-" |
| 226 | elif env['os'] == 'android': |
| 227 | prefix = "arm-linux-androideabi-" |
Inki Dae | 51a9558 | 2020-03-23 08:29:02 +0900 | [diff] [blame] | 228 | elif env['os'] == 'tizen': |
| 229 | prefix = "armv7l-tizen-linux-gnueabi-" |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 230 | elif env['estate'] == '64' and 'v8' in env['arch']: |
| 231 | if env['os'] == 'linux': |
| 232 | prefix = "aarch64-linux-gnu-" |
| 233 | elif env['os'] == 'bare_metal': |
| 234 | prefix = "aarch64-elf-" |
| 235 | elif env['os'] == 'android': |
| 236 | prefix = "aarch64-linux-android-" |
Inki Dae | 51a9558 | 2020-03-23 08:29:02 +0900 | [diff] [blame] | 237 | elif env['os'] == 'tizen': |
| 238 | prefix = "aarch64-tizen-linux-gnu-" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 239 | |
| 240 | if env['build'] == 'native': |
| 241 | prefix = "" |
| 242 | |
Anthony Barbier | 149de5b | 2018-12-06 10:27:37 +0000 | [diff] [blame] | 243 | if env["toolchain_prefix"] != "": |
| 244 | prefix = env["toolchain_prefix"] |
| 245 | |
alered01 | d8872c1 | 2020-02-10 11:29:45 +0000 | [diff] [blame] | 246 | compiler_prefix = prefix |
| 247 | if env["compiler_prefix"] != "": |
| 248 | compiler_prefix = env["compiler_prefix"] |
| 249 | |
| 250 | env['CC'] = env['compiler_cache']+ " " + compiler_prefix + c_compiler |
| 251 | env['CXX'] = env['compiler_cache']+ " " + compiler_prefix + cpp_compiler |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 252 | env['LD'] = prefix + "ld" |
| 253 | env['AS'] = prefix + "as" |
| 254 | env['AR'] = prefix + "ar" |
| 255 | env['RANLIB'] = prefix + "ranlib" |
| 256 | |
| 257 | if not GetOption("help"): |
| 258 | try: |
Anthony Barbier | 907dba8 | 2017-08-25 10:11:39 +0100 | [diff] [blame] | 259 | compiler_ver = subprocess.check_output(env['CXX'].split() + ["-dumpversion"]).strip() |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 260 | except OSError: |
| 261 | print("ERROR: Compiler '%s' not found" % env['CXX']) |
| 262 | Exit(1) |
| 263 | |
Georgios Pinitas | e874ef9 | 2019-09-09 17:40:33 +0100 | [diff] [blame] | 264 | if 'armclang' in cpp_compiler: |
| 265 | pass |
| 266 | elif 'clang++' not in cpp_compiler: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 267 | if env['arch'] == 'arm64-v8.2-a' and not version_at_least(compiler_ver, '6.2.1'): |
ggardet | 767c9f7 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 268 | print("GCC 6.2.1 or newer is required to compile armv8.2-a code") |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 269 | Exit(1) |
| 270 | elif env['arch'] == 'arm64-v8a' and not version_at_least(compiler_ver, '4.9'): |
ggardet | 767c9f7 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 271 | print("GCC 4.9 or newer is required to compile NEON code for AArch64") |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 272 | Exit(1) |
| 273 | |
| 274 | if version_at_least(compiler_ver, '6.1'): |
| 275 | env.Append(CXXFLAGS = ['-Wno-ignored-attributes']) |
| 276 | |
| 277 | if compiler_ver == '4.8.3': |
| 278 | env.Append(CXXFLAGS = ['-Wno-array-bounds']) |
| 279 | |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 280 | if env['standalone']: |
| 281 | env.Append(CXXFLAGS = ['-fPIC']) |
Anthony Barbier | 665c89b | 2018-07-16 11:40:09 +0100 | [diff] [blame] | 282 | env.Append(LINKFLAGS = ['-static-libgcc','-static-libstdc++']) |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 283 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 284 | if env['Werror']: |
| 285 | env.Append(CXXFLAGS = ['-Werror']) |
| 286 | |
| 287 | if env['os'] == 'android': |
| 288 | env.Append(CPPDEFINES = ['ANDROID']) |
Michalis Spyrou | 2d22c3f | 2020-02-12 14:50:19 +0000 | [diff] [blame] | 289 | env.Append(LINKFLAGS = ['-pie', '-static-libstdc++', '-ldl']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 290 | elif env['os'] == 'bare_metal': |
| 291 | env.Append(LINKFLAGS = ['-static']) |
Michalis Spyrou | 07781ac | 2017-08-31 15:11:41 +0100 | [diff] [blame] | 292 | env.Append(LINKFLAGS = ['-specs=rdimon.specs']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 293 | env.Append(CXXFLAGS = ['-fPIC']) |
| 294 | env.Append(CPPDEFINES = ['NO_MULTI_THREADING']) |
Michalis Spyrou | 07781ac | 2017-08-31 15:11:41 +0100 | [diff] [blame] | 295 | env.Append(CPPDEFINES = ['BARE_METAL']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 296 | |
| 297 | if env['opencl']: |
Georgios Pinitas | e6032da | 2017-10-26 14:13:35 +0100 | [diff] [blame] | 298 | if env['os'] in ['bare_metal'] or env['standalone']: |
Anthony Barbier | 5f0124d | 2018-04-13 14:05:34 +0100 | [diff] [blame] | 299 | print("Cannot link OpenCL statically, which is required for bare metal / standalone builds") |
| 300 | Exit(1) |
| 301 | |
| 302 | if env['gles_compute']: |
| 303 | if env['os'] in ['bare_metal'] or env['standalone']: |
| 304 | print("Cannot link OpenGLES statically, which is required for bare metal / standalone builds") |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 305 | Exit(1) |
| 306 | |
Anthony Barbier | 9fb0cac | 2018-04-20 15:46:21 +0100 | [diff] [blame] | 307 | if env["os"] not in ["android", "bare_metal"] and (env['opencl'] or env['cppthreads']): |
| 308 | env.Append(LIBS = ['pthread']) |
| 309 | |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 310 | if env['opencl'] or env['gles_compute']: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 311 | if env['embed_kernels']: |
| 312 | env.Append(CPPDEFINES = ['EMBEDDED_KERNELS']) |
| 313 | |
| 314 | if env['debug']: |
| 315 | env['asserts'] = True |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 316 | env['logging'] = True |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 317 | env.Append(CXXFLAGS = ['-O0','-g','-gdwarf-2']) |
| 318 | env.Append(CPPDEFINES = ['ARM_COMPUTE_DEBUG_ENABLED']) |
| 319 | else: |
Ramana Radhakrishnan | d176d54 | 2019-07-04 11:38:45 +0100 | [diff] [blame] | 320 | env.Append(CXXFLAGS = ['-O3']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 321 | |
| 322 | if env['asserts']: |
| 323 | env.Append(CPPDEFINES = ['ARM_COMPUTE_ASSERTS_ENABLED']) |
Moritz Pflanzer | 8b74c78 | 2017-09-14 14:33:20 +0100 | [diff] [blame] | 324 | env.Append(CXXFLAGS = ['-fstack-protector-strong']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 325 | |
Georgios Pinitas | 7d3d1b9 | 2017-10-12 17:34:20 +0100 | [diff] [blame] | 326 | if env['logging']: |
| 327 | env.Append(CPPDEFINES = ['ARM_COMPUTE_LOGGING_ENABLED']) |
| 328 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 329 | env.Append(CPPPATH = ['#/include', "#"]) |
| 330 | env.Append(CXXFLAGS = env['extra_cxx_flags']) |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 331 | env.Append(LINKFLAGS = env['extra_link_flags']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 332 | |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 333 | Default( install_include("arm_compute")) |
Anthony Barbier | 1056595 | 2018-11-15 09:50:06 +0000 | [diff] [blame] | 334 | Default( install_include("support")) |
Michele Di Giorgio | 6afea90 | 2019-04-03 11:40:20 +0100 | [diff] [blame] | 335 | Default( install_include("utils")) |
| 336 | for dirname in os.listdir("./include"): |
| 337 | Default( install_include("include/%s" % dirname)) |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 338 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 339 | Export('version_at_least') |
| 340 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 341 | |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 342 | if env['gles_compute'] and env['os'] != 'android': |
Anthony Barbier | 14c86a9 | 2017-12-14 16:27:41 +0000 | [diff] [blame] | 343 | env.Append(CPPPATH = ['#/include/linux']) |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 344 | |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 345 | SConscript('./SConscript', variant_dir=build_path, duplicate=0) |
Anthony Barbier | 6c0348f | 2017-11-10 18:32:38 +0000 | [diff] [blame] | 346 | |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 347 | if env['examples'] and env['exceptions']: |
| 348 | if env['os'] == 'bare_metal' and env['arch'] == 'armv7a': |
Michalis Spyrou | 35f35a6 | 2019-12-23 11:29:52 +0000 | [diff] [blame] | 349 | print("WARNING: Building examples for bare metal and armv7a is not supported. Use examples=0") |
| 350 | Return() |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 351 | SConscript('./examples/SConscript', variant_dir='%s/examples' % build_path, duplicate=0) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 352 | |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 353 | if env['exceptions']: |
| 354 | if env['os'] == 'bare_metal' and env['arch'] == 'armv7a': |
| 355 | print("WARNING: Building tests for bare metal and armv7a is not supported") |
| 356 | Return() |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 357 | SConscript('./tests/SConscript', variant_dir='%s/tests' % build_path, duplicate=0) |