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