Michele Di Giorgio | 33f41fa | 2021-03-09 14:09:08 +0000 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | |
Pablo Marquez Tello | 6bcdc57 | 2023-01-11 09:54:00 +0000 | [diff] [blame] | 3 | # Copyright (c) 2016-2023 Arm Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 4 | # |
| 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 | |
| 25 | import SCons |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 26 | import json |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 27 | import os |
Giorgio Arena | b83e672 | 2022-03-24 14:23:07 +0000 | [diff] [blame] | 28 | from subprocess import check_output |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 29 | |
| 30 | def version_at_least(version, required): |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 31 | |
Michalis Spyrou | cfac305 | 2020-10-14 12:06:28 +0100 | [diff] [blame] | 32 | 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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 37 | return False |
Michalis Spyrou | cfac305 | 2020-10-14 12:06:28 +0100 | [diff] [blame] | 38 | elif int(version_list[i]) > int(required_list[i]): |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 39 | return True |
| 40 | |
| 41 | return True |
| 42 | |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 43 | def 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 | |
| 63 | def update_data_type_layout_flags(env, data_types, data_layouts): |
| 64 | # Manage data-types |
| 65 | if any(i in data_types for i in ['all', 'fp16']): |
| 66 | env.Append(CXXFLAGS = ['-DENABLE_FP16_KERNELS']) |
| 67 | if any(i in data_types for i in ['all', 'fp32']): |
| 68 | env.Append(CXXFLAGS = ['-DENABLE_FP32_KERNELS']) |
| 69 | if any(i in data_types for i in ['all', 'qasymm8']): |
| 70 | env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_KERNELS']) |
| 71 | if any(i in data_types for i in ['all', 'qasymm8_signed']): |
| 72 | env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_SIGNED_KERNELS']) |
| 73 | if any(i in data_types for i in ['all', 'qsymm16']): |
| 74 | env.Append(CXXFLAGS = ['-DENABLE_QSYMM16_KERNELS']) |
| 75 | if any(i in data_types for i in ['all', 'integer']): |
| 76 | env.Append(CXXFLAGS = ['-DENABLE_INTEGER_KERNELS']) |
| 77 | |
| 78 | # Manage data-layouts |
| 79 | if any(i in data_layouts for i in ['all', 'nhwc']): |
| 80 | env.Append(CXXFLAGS = ['-DENABLE_NHWC_KERNELS']) |
| 81 | if any(i in data_layouts for i in ['all', 'nchw']): |
| 82 | env.Append(CXXFLAGS = ['-DENABLE_NCHW_KERNELS']) |
| 83 | |
| 84 | return env |
| 85 | |
| 86 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 87 | vars = Variables("scons") |
| 88 | vars.AddVariables( |
| 89 | BoolVariable("debug", "Debug", False), |
| 90 | BoolVariable("asserts", "Enable asserts (this flag is forced to 1 for debug=1)", False), |
ramelg01 | 93d6cf0 | 2021-09-23 13:59:22 +0100 | [diff] [blame] | 91 | BoolVariable("logging", "Enable Logging", False), |
Michalis Spyrou | a3f7cd2 | 2022-07-04 15:32:02 +0100 | [diff] [blame] | 92 | EnumVariable("arch", "Target Architecture. The x86_32 and x86_64 targets can only be used with neon=0 and opencl=1.", "armv7a", |
Slava Barinov | db0e2c8 | 2021-04-07 11:23:27 +0300 | [diff] [blame] | 93 | 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 Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 94 | "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 Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 95 | EnumVariable("estate", "Execution State", "auto", allowed_values=("auto", "32", "64")), |
Michalis Spyrou | a3f7cd2 | 2022-07-04 15:32:02 +0100 | [diff] [blame] | 96 | 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")), |
| 97 | 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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 98 | BoolVariable("examples", "Build example programs", True), |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 99 | BoolVariable("gemm_tuner", "Build gemm_tuner programs", True), |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 100 | BoolVariable("Werror", "Enable/disable the -Werror compilation flag", True), |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 101 | BoolVariable("multi_isa", "Build Multi ISA binary version of library. Note works only for armv8.2-a", False), |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 102 | 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] | 103 | BoolVariable("opencl", "Enable OpenCL support", True), |
Michele Di Giorgio | 33f41fa | 2021-03-09 14:09:08 +0000 | [diff] [blame] | 104 | BoolVariable("neon", "Enable Arm® Neon™ support", False), |
Michalis Spyrou | a3f7cd2 | 2022-07-04 15:32:02 +0100 | [diff] [blame] | 105 | 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), |
| 106 | BoolVariable("compress_kernels", "Compress embedded OpenCL kernels in library binary using zlib. Useful for reducing the binary size. embed_kernels should be enabled", False), |
| 107 | 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), |
| 108 | BoolVariable("openmp", "Enable OpenMP backend. Only works when building with g++ and not clang++", False), |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 109 | BoolVariable("cppthreads", "Enable C++11 threads backend", True), |
| 110 | PathVariable("build_dir", "Specify sub-folder for the build", ".", PathVariable.PathAccept), |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 111 | PathVariable("install_dir", "Specify sub-folder for the install", "", PathVariable.PathAccept), |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 112 | BoolVariable("exceptions", "Enable/disable C++ exception support", True), |
Michalis Spyrou | 62c2ad6 | 2021-06-21 17:40:09 +0100 | [diff] [blame] | 113 | BoolVariable("high_priority", "Generate a library containing only the high priority operators", False), |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 114 | PathVariable("linker_script", "Use an external linker script", "", PathVariable.PathAccept), |
Michalis Spyrou | a3f7cd2 | 2022-07-04 15:32:02 +0100 | [diff] [blame] | 115 | 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: |
| 116 | EXTERNAL_TESTS_DIR: |
| 117 | └── tests |
| 118 | ├── benchmark |
| 119 | │ ├── CL |
| 120 | │ ├── datasets |
| 121 | │ ├── fixtures |
| 122 | │ └── Neon |
| 123 | └── validation |
| 124 | ├── CL |
| 125 | ├── datasets |
| 126 | ├── fixtures |
| 127 | └── Neon\n""", "", PathVariable.PathAccept), |
Giorgio Arena | 232c452 | 2022-03-03 10:09:01 +0000 | [diff] [blame] | 128 | BoolVariable("experimental_dynamic_fusion", "Build the experimental dynamic fusion files", False), |
Francesco.Petrogalli@arm.com | 5fcf22d | 2022-04-05 10:31:08 +0000 | [diff] [blame] | 129 | BoolVariable("experimental_fixed_format_kernels", "Enable fixed format kernels for GEMM", False), |
Pablo Marquez Tello | 299d3a1 | 2022-10-12 14:58:24 +0100 | [diff] [blame] | 130 | BoolVariable("mapfile", "Generate a map file", False), |
Georgios Pinitas | 49c6ced | 2020-09-21 17:16:09 +0100 | [diff] [blame] | 131 | ListVariable("custom_options", "Custom options that can be used to turn on/off features", "none", ["disable_mmla_fp"]), |
Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 132 | ListVariable("data_type_support", "Enable a list of data types to support", "all", ["qasymm8", "qasymm8_signed", "qsymm16", "fp16", "fp32", "integer"]), |
Sheri Zhang | 79144a6 | 2021-02-08 17:43:04 +0000 | [diff] [blame] | 133 | ListVariable("data_layout_support", "Enable a list of data layout to support", "all", ["nhwc", "nchw"]), |
SiCong Li | fe1b1f6 | 2022-05-19 18:58:31 +0100 | [diff] [blame] | 134 | ("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"), |
| 135 | ("compiler_prefix", "Override the compiler prefix; used by just compilers (CC,CXX); further overrides toolchain_prefix for compilers; this is for when the compiler prefixes are different from that of the linkers, archivers etc. If unspecified, this is the same as toolchain_prefix; if passed an empty string '' prefixes would be disabled", "auto"), |
Anthony Barbier | 7390e05 | 2018-03-13 09:29:41 +0000 | [diff] [blame] | 136 | ("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] | 137 | ("extra_link_flags", "Extra LD flags to be appended to the build command", ""), |
Manuel Bottini | e5a9ad8 | 2020-11-18 16:22:16 +0000 | [diff] [blame] | 138 | ("compiler_cache", "Command to prefix to the C and C++ compiler (e.g ccache)", ""), |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 139 | ("specs_file", "Specs file to use (e.g. rdimon.specs)", ""), |
| 140 | ("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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 141 | ) |
| 142 | |
Viet-Hoa Do | 36dc77d | 2023-03-03 10:44:58 +0000 | [diff] [blame] | 143 | if version_at_least(SCons.__version__, "4.0"): |
| 144 | vars.Add(BoolVariable("export_compile_commands", "Export compile_commands.json file.", False)) |
| 145 | |
Motti Gondabi | f76a502 | 2021-12-21 13:19:29 +0200 | [diff] [blame] | 146 | |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 147 | env = Environment(variables=vars, ENV = os.environ) |
| 148 | |
| 149 | |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 150 | build_path = env['build_dir'] |
| 151 | # If build_dir is a relative path then add a #build/ prefix: |
| 152 | if not env['build_dir'].startswith('/'): |
| 153 | SConsignFile('build/%s/.scons' % build_path) |
| 154 | build_path = "#build/%s" % build_path |
| 155 | else: |
| 156 | SConsignFile('%s/.scons' % build_path) |
| 157 | |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 158 | install_path = env['install_dir'] |
| 159 | #If the install_dir is a relative path then assume it's from inside build_dir |
| 160 | if not env['install_dir'].startswith('/') and install_path != "": |
| 161 | install_path = "%s/%s" % (build_path, install_path) |
| 162 | |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 163 | env.Append(LIBPATH = [build_path]) |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 164 | Export('env') |
| 165 | Export('vars') |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 166 | |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 167 | def install_lib( lib ): |
| 168 | # If there is no install folder, then there is nothing to do: |
| 169 | if install_path == "": |
| 170 | return lib |
| 171 | return env.Install( "%s/lib/" % install_path, lib) |
| 172 | def install_bin( bin ): |
| 173 | # If there is no install folder, then there is nothing to do: |
| 174 | if install_path == "": |
| 175 | return bin |
| 176 | return env.Install( "%s/bin/" % install_path, bin) |
| 177 | def install_include( inc ): |
| 178 | if install_path == "": |
| 179 | return inc |
| 180 | return env.Install( "%s/include/" % install_path, inc) |
| 181 | |
| 182 | Export('install_lib') |
| 183 | Export('install_bin') |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 184 | |
| 185 | Help(vars.GenerateHelpText(env)) |
| 186 | |
Viet-Hoa Do | 36dc77d | 2023-03-03 10:44:58 +0000 | [diff] [blame] | 187 | # Export compile_commands.json file |
| 188 | if env.get("export_compile_commands", False): |
| 189 | env.Tool("compilation_db") |
| 190 | env.CompilationDatabase("%s/compile_commands.json" % build_path) |
| 191 | |
Michalis Spyrou | 14ce094 | 2022-06-13 15:40:35 +0100 | [diff] [blame] | 192 | if 'armv7a' in env['arch'] and env['os'] == 'android': |
SiCong Li | 13f96d0 | 2022-06-21 10:06:51 +0100 | [diff] [blame] | 193 | print("WARNING: armv7a on Android is no longer maintained") |
Michalis Spyrou | 14ce094 | 2022-06-13 15:40:35 +0100 | [diff] [blame] | 194 | |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 195 | if env['linker_script'] and env['os'] != 'bare_metal': |
| 196 | print("Linker script is only supported for bare_metal builds") |
| 197 | Exit(1) |
| 198 | |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 199 | if env['build'] == "embed_only": |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 200 | SConscript('./SConscript', variant_dir=build_path, duplicate=0) |
Anthony Barbier | 6a3daf1 | 2018-02-19 17:24:27 +0000 | [diff] [blame] | 201 | Return() |
| 202 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 203 | if env['neon'] and 'x86' in env['arch']: |
Michele Di Giorgio | 33f41fa | 2021-03-09 14:09:08 +0000 | [diff] [blame] | 204 | print("Cannot compile Arm® Neon™ for x86") |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 205 | Exit(1) |
| 206 | |
| 207 | if env['set_soname'] and not version_at_least(SCons.__version__, "2.4"): |
ggardet | 767c9f7 | 2018-06-29 17:01:01 +0200 | [diff] [blame] | 208 | print("Setting the library's SONAME / SHLIBVERSION requires SCons 2.4 or above") |
| 209 | print("Update your version of SCons or use set_soname=0") |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 210 | Exit(1) |
| 211 | |
| 212 | if env['os'] == 'bare_metal': |
| 213 | if env['cppthreads'] or env['openmp']: |
| 214 | print("ERROR: OpenMP and C++11 threads not supported in bare_metal. Use cppthreads=0 openmp=0") |
| 215 | Exit(1) |
| 216 | |
Georgios Pinitas | ea85727 | 2021-01-22 05:47:37 +0000 | [diff] [blame] | 217 | if env['opencl'] and env['embed_kernels'] and env['compress_kernels'] and env['os'] not in ['android']: |
| 218 | print("Compressed kernels are supported only for android builds") |
| 219 | Exit(1) |
| 220 | |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 221 | if not env['exceptions']: |
Manuel Bottini | ceaa0bf | 2021-02-16 15:15:19 +0000 | [diff] [blame] | 222 | if env['opencl']: |
| 223 | print("ERROR: OpenCL is not supported when building without exceptions. Use opencl=0") |
Michalis Spyrou | 323ce0f | 2018-11-30 16:30:43 +0000 | [diff] [blame] | 224 | Exit(1) |
| 225 | |
| 226 | env.Append(CPPDEFINES = ['ARM_COMPUTE_EXCEPTIONS_DISABLED']) |
| 227 | env.Append(CXXFLAGS = ['-fno-exceptions']) |
| 228 | |
Pablo Tello | 29cab36 | 2022-03-10 17:05:34 +0000 | [diff] [blame] | 229 | env.Append(CXXFLAGS = ['-DARCH_ARM', |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 230 | '-Wextra','-Wdisabled-optimization','-Wformat=2', |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 231 | '-Winit-self','-Wstrict-overflow=2','-Wswitch-default', |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 232 | '-Woverloaded-virtual', '-Wformat-security', |
Michalis Spyrou | fae513c | 2019-10-16 17:41:33 +0100 | [diff] [blame] | 233 | '-Wctor-dtor-privacy','-Wsign-promo','-Weffc++','-Wno-overlength-strings']) |
Isabella Gottardi | b28f29d | 2017-11-09 17:05:07 +0000 | [diff] [blame] | 234 | |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 235 | if not 'windows' in env['os']: |
Pablo Tello | 29cab36 | 2022-03-10 17:05:34 +0000 | [diff] [blame] | 236 | env.Append(CXXFLAGS = ['-Wall','-std=c++14', '-pedantic' ]) |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 237 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 238 | env.Append(CPPDEFINES = ['_GLIBCXX_USE_NANOSLEEP']) |
| 239 | |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 240 | cpp_tool = {'linux': 'g++', 'android' : 'clang++', |
| 241 | 'tizen': 'g++', 'macos':'clang++', |
| 242 | 'bare_metal':'g++', 'openbsd':'g++','windows':'clang-cl'} |
| 243 | |
| 244 | c_tool = {'linux':'gcc', 'android': 'clang', 'tizen':'gcc', |
| 245 | 'macos':'clang','bare_metal':'gcc', |
| 246 | 'openbsd':'gcc','windows':'clang-cl'} |
| 247 | |
| 248 | default_cpp_compiler = cpp_tool[env['os']] |
| 249 | default_c_compiler = c_tool[env['os']] |
Anthony Barbier | a026e98 | 2018-01-18 10:57:52 +0000 | [diff] [blame] | 250 | cpp_compiler = os.environ.get('CXX', default_cpp_compiler) |
| 251 | c_compiler = os.environ.get('CC', default_c_compiler) |
| 252 | |
Anthony Barbier | dd66937 | 2018-03-01 17:08:54 +0000 | [diff] [blame] | 253 | 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] | 254 | 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] | 255 | |
Anthony Barbier | dd66937 | 2018-03-01 17:08:54 +0000 | [diff] [blame] | 256 | if 'clang++' in cpp_compiler: |
Michalis Spyrou | 7c60c99 | 2019-10-10 14:33:47 +0100 | [diff] [blame] | 257 | env.Append(CXXFLAGS = ['-Wno-vla-extension']) |
Georgios Pinitas | e874ef9 | 2019-09-09 17:40:33 +0100 | [diff] [blame] | 258 | elif 'armclang' in cpp_compiler: |
| 259 | pass |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 260 | elif not 'windows' in env['os']: |
Giorgio Arena | b83e672 | 2022-03-24 14:23:07 +0000 | [diff] [blame] | 261 | env.Append(CXXFLAGS = ['-Wlogical-op','-Wnoexcept','-Wstrict-null-sentinel','-Wno-misleading-indentation']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 262 | |
SiCongLi | 410e21e | 2020-12-11 15:07:53 +0000 | [diff] [blame] | 263 | if cpp_compiler == 'g++': |
| 264 | # Don't strip comments that could include markers |
| 265 | env.Append(CXXFLAGS = ['-C']) |
| 266 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 267 | if env['cppthreads']: |
| 268 | env.Append(CPPDEFINES = [('ARM_COMPUTE_CPP_SCHEDULER', 1)]) |
| 269 | |
| 270 | if env['openmp']: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 271 | env.Append(CPPDEFINES = [('ARM_COMPUTE_OPENMP_SCHEDULER', 1)]) |
| 272 | env.Append(CXXFLAGS = ['-fopenmp']) |
| 273 | env.Append(LINKFLAGS = ['-fopenmp']) |
| 274 | |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 275 | # Validate and define state |
| 276 | if env['estate'] == 'auto': |
| 277 | if 'v7a' in env['arch']: |
| 278 | env['estate'] = '32' |
| 279 | else: |
| 280 | env['estate'] = '64' |
| 281 | |
| 282 | # Map legacy arch |
| 283 | if 'arm64' in env['arch']: |
| 284 | env['estate'] = '64' |
| 285 | |
| 286 | if 'v7a' in env['estate'] and env['estate'] == '64': |
| 287 | print("ERROR: armv7a architecture has only 32-bit execution state") |
| 288 | Exit(1) |
| 289 | |
Motti Gondabi | 9d9ad33 | 2022-01-23 12:42:24 +0200 | [diff] [blame] | 290 | env.Append(CPPDEFINES = ['ENABLE_NEON', 'ARM_COMPUTE_ENABLE_NEON']) |
| 291 | |
Motti Gondabi | f76a502 | 2021-12-21 13:19:29 +0200 | [diff] [blame] | 292 | if 'sve' in env['arch']: |
| 293 | env.Append(CPPDEFINES = ['ENABLE_SVE', 'ARM_COMPUTE_ENABLE_SVE']) |
| 294 | if 'sve2' in env['arch']: |
| 295 | env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVE2']) |
Motti Gondabi | f76a502 | 2021-12-21 13:19:29 +0200 | [diff] [blame] | 296 | |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 297 | if 'sme' in env['arch']: |
| 298 | env.Append(CPPDEFINES = ['ENABLE_SME', 'ARM_COMPUTE_ENABLE_SME']) |
| 299 | if 'sme2' in env['arch']: |
| 300 | env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SME2']) |
| 301 | |
Georgios Pinitas | e874ef9 | 2019-09-09 17:40:33 +0100 | [diff] [blame] | 302 | # Add architecture specific flags |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 303 | if env['multi_isa']: |
| 304 | # assert arch version is v8 |
| 305 | if 'v8' not in env['arch']: |
| 306 | print("Currently Multi ISA binary is only supported for arm v8 family") |
| 307 | Exit(1) |
Georgios Pinitas | 94672fb | 2020-01-22 18:36:27 +0000 | [diff] [blame] | 308 | |
Georgios Pinitas | 8e2f64f | 2021-07-28 13:18:46 +0100 | [diff] [blame] | 309 | if 'v8.6-a' in env['arch']: |
Georgios Pinitas | 49c6ced | 2020-09-21 17:16:09 +0100 | [diff] [blame] | 310 | if "disable_mmla_fp" not in env['custom_options']: |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 311 | env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVEF32MM']) |
Georgios Pinitas | 8e2f64f | 2021-07-28 13:18:46 +0100 | [diff] [blame] | 312 | |
Pablo Marquez Tello | 6bcdc57 | 2023-01-11 09:54:00 +0000 | [diff] [blame] | 313 | env.Append(CXXFLAGS = ['-march=armv8.2-a+fp16']) # explicitly enable fp16 extension otherwise __ARM_FEATURE_FP16_VECTOR_ARITHMETIC is undefined |
Giorgio Arena | 73fa0a7 | 2022-02-10 15:06:51 +0000 | [diff] [blame] | 314 | |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 315 | else: # NONE "multi_isa" builds |
| 316 | |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 317 | if 'v7a' in env['arch']: |
| 318 | env.Append(CXXFLAGS = ['-march=armv7-a', '-mthumb', '-mfpu=neon']) |
| 319 | if (env['os'] == 'android' or env['os'] == 'tizen') and not 'hf' in env['arch']: |
| 320 | env.Append(CXXFLAGS = ['-mfloat-abi=softfp']) |
| 321 | else: |
| 322 | env.Append(CXXFLAGS = ['-mfloat-abi=hard']) |
Pablo Marquez Tello | d208f4f | 2022-07-19 12:19:46 +0100 | [diff] [blame] | 323 | elif 'v8.6-a' in env['arch']: |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 324 | if 'armv8.6-a-sve2' in env['arch']: |
Pablo Marquez Tello | d208f4f | 2022-07-19 12:19:46 +0100 | [diff] [blame] | 325 | env.Append(CXXFLAGS = ['-march=armv8.6-a+sve2']) |
| 326 | elif 'armv8.6-a-sve' == env['arch']: |
| 327 | env.Append(CXXFLAGS = ['-march=armv8.6-a+sve']) |
| 328 | elif 'armv8.6-a' == env['arch']: |
Pablo Marquez Tello | cf07d11 | 2022-09-28 21:37:37 +0100 | [diff] [blame] | 329 | env.Append(CXXFLAGS = ['-march=armv8.6-a+fp16']) |
Pablo Marquez Tello | d208f4f | 2022-07-19 12:19:46 +0100 | [diff] [blame] | 330 | |
| 331 | env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_I8MM', 'ARM_COMPUTE_ENABLE_BF16','ARM_COMPUTE_ENABLE_FP16']) |
| 332 | if "disable_mmla_fp" not in env['custom_options']: |
| 333 | env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVEF32MM']) |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 334 | elif 'v8' in env['arch']: |
| 335 | # Preserve the V8 archs for non-multi-ISA variants |
| 336 | if 'sve2' in env['arch']: |
| 337 | env.Append(CXXFLAGS = ['-march=armv8.2-a+sve2+fp16+dotprod']) |
| 338 | elif 'sve' in env['arch']: |
| 339 | env.Append(CXXFLAGS = ['-march=armv8.2-a+sve+fp16+dotprod']) |
| 340 | elif 'armv8r64' in env['arch']: |
| 341 | env.Append(CXXFLAGS = ['-march=armv8.4-a']) |
| 342 | elif 'v8.' in env['arch']: |
| 343 | env.Append(CXXFLAGS = ['-march=armv8.2-a+fp16']) # explicitly enable fp16 extension otherwise __ARM_FEATURE_FP16_VECTOR_ARITHMETIC is undefined |
| 344 | else: |
| 345 | env.Append(CXXFLAGS = ['-march=armv8-a']) |
| 346 | |
Motti Gondabi | 6f3a9f5 | 2021-11-09 15:47:17 +0200 | [diff] [blame] | 347 | if 'v8.' in env['arch']: |
| 348 | env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_FP16']) |
| 349 | |
| 350 | elif 'x86' in env['arch']: |
| 351 | if env['estate'] == '32': |
| 352 | env.Append(CCFLAGS = ['-m32']) |
| 353 | env.Append(LINKFLAGS = ['-m32']) |
| 354 | else: |
| 355 | env.Append(CXXFLAGS = ['-fPIC']) |
| 356 | env.Append(CCFLAGS = ['-m64']) |
| 357 | env.Append(LINKFLAGS = ['-m64']) |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 358 | |
| 359 | # Define toolchain |
SiCongLi | fecdb8f | 2022-01-04 18:33:17 +0000 | [diff] [blame] | 360 | # The reason why we distinguish toolchain_prefix from compiler_prefix is for cases where the linkers/archivers use a |
| 361 | # different prefix than the compilers. An example is the NDK r20 toolchain |
SiCong Li | fe1b1f6 | 2022-05-19 18:58:31 +0100 | [diff] [blame] | 362 | auto_toolchain_prefix = "" |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 363 | if 'x86' not in env['arch']: |
| 364 | if env['estate'] == '32': |
| 365 | if env['os'] == 'linux': |
SiCong Li | fe1b1f6 | 2022-05-19 18:58:31 +0100 | [diff] [blame] | 366 | auto_toolchain_prefix = "arm-linux-gnueabihf-" if 'v7' in env['arch'] else "armv8l-linux-gnueabihf-" |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 367 | elif env['os'] == 'bare_metal': |
SiCong Li | fe1b1f6 | 2022-05-19 18:58:31 +0100 | [diff] [blame] | 368 | auto_toolchain_prefix = "arm-eabi-" |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 369 | elif env['os'] == 'android': |
SiCong Li | fe1b1f6 | 2022-05-19 18:58:31 +0100 | [diff] [blame] | 370 | auto_toolchain_prefix = "arm-linux-androideabi-" |
Inki Dae | 51a9558 | 2020-03-23 08:29:02 +0900 | [diff] [blame] | 371 | elif env['os'] == 'tizen': |
SiCong Li | fe1b1f6 | 2022-05-19 18:58:31 +0100 | [diff] [blame] | 372 | auto_toolchain_prefix = "armv7l-tizen-linux-gnueabi-" |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 373 | elif env['estate'] == '64' and 'v8' in env['arch']: |
| 374 | if env['os'] == 'linux': |
SiCong Li | fe1b1f6 | 2022-05-19 18:58:31 +0100 | [diff] [blame] | 375 | auto_toolchain_prefix = "aarch64-linux-gnu-" |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 376 | elif env['os'] == 'bare_metal': |
SiCong Li | fe1b1f6 | 2022-05-19 18:58:31 +0100 | [diff] [blame] | 377 | auto_toolchain_prefix = "aarch64-elf-" |
Georgios Pinitas | f2cdce3 | 2019-12-09 18:35:57 +0000 | [diff] [blame] | 378 | elif env['os'] == 'android': |
SiCong Li | fe1b1f6 | 2022-05-19 18:58:31 +0100 | [diff] [blame] | 379 | auto_toolchain_prefix = "aarch64-linux-android-" |
Inki Dae | 51a9558 | 2020-03-23 08:29:02 +0900 | [diff] [blame] | 380 | elif env['os'] == 'tizen': |
SiCong Li | fe1b1f6 | 2022-05-19 18:58:31 +0100 | [diff] [blame] | 381 | auto_toolchain_prefix = "aarch64-tizen-linux-gnu-" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 382 | |
Pablo Marquez Tello | ddf2f6c | 2022-06-28 12:56:27 +0100 | [diff] [blame] | 383 | if env['build'] == 'native' or env["toolchain_prefix"] == "": |
SiCong Li | fe1b1f6 | 2022-05-19 18:58:31 +0100 | [diff] [blame] | 384 | toolchain_prefix = "" |
| 385 | elif env["toolchain_prefix"] == "auto": |
| 386 | toolchain_prefix = auto_toolchain_prefix |
| 387 | else: |
SiCongLi | fecdb8f | 2022-01-04 18:33:17 +0000 | [diff] [blame] | 388 | toolchain_prefix = env["toolchain_prefix"] |
Anthony Barbier | 149de5b | 2018-12-06 10:27:37 +0000 | [diff] [blame] | 389 | |
Pablo Marquez Tello | ddf2f6c | 2022-06-28 12:56:27 +0100 | [diff] [blame] | 390 | if env['build'] == 'native' or env["compiler_prefix"] == "": |
SiCong Li | fe1b1f6 | 2022-05-19 18:58:31 +0100 | [diff] [blame] | 391 | compiler_prefix = "" |
| 392 | elif env["compiler_prefix"] == "auto": |
| 393 | compiler_prefix = toolchain_prefix |
| 394 | else: |
alered01 | d8872c1 | 2020-02-10 11:29:45 +0000 | [diff] [blame] | 395 | compiler_prefix = env["compiler_prefix"] |
| 396 | |
| 397 | env['CC'] = env['compiler_cache']+ " " + compiler_prefix + c_compiler |
| 398 | env['CXX'] = env['compiler_cache']+ " " + compiler_prefix + cpp_compiler |
SiCongLi | fecdb8f | 2022-01-04 18:33:17 +0000 | [diff] [blame] | 399 | env['LD'] = toolchain_prefix + "ld" |
| 400 | env['AS'] = toolchain_prefix + "as" |
Pablo Tello | 29cab36 | 2022-03-10 17:05:34 +0000 | [diff] [blame] | 401 | |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 402 | if env['os'] == 'windows': |
Pablo Tello | 29cab36 | 2022-03-10 17:05:34 +0000 | [diff] [blame] | 403 | env['AR'] = "llvm-lib" |
| 404 | env['RANLIB'] = "llvm-ranlib" |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 405 | else: |
SiCongLi | fecdb8f | 2022-01-04 18:33:17 +0000 | [diff] [blame] | 406 | env['AR'] = toolchain_prefix + "ar" |
Pablo Tello | 29cab36 | 2022-03-10 17:05:34 +0000 | [diff] [blame] | 407 | |
SiCongLi | fecdb8f | 2022-01-04 18:33:17 +0000 | [diff] [blame] | 408 | env['RANLIB'] = toolchain_prefix + "ranlib" |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 409 | |
SiCong Li | fe1b1f6 | 2022-05-19 18:58:31 +0100 | [diff] [blame] | 410 | print("Using compilers:") |
| 411 | print("CC", env['CC']) |
| 412 | print("CXX", env['CXX']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 413 | |
| 414 | if not GetOption("help"): |
| 415 | try: |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 416 | if env['os'] == 'windows': |
Giorgio Arena | b83e672 | 2022-03-24 14:23:07 +0000 | [diff] [blame] | 417 | compiler_ver = check_output("clang++ -dumpversion").decode().strip() |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 418 | else: |
Giorgio Arena | b83e672 | 2022-03-24 14:23:07 +0000 | [diff] [blame] | 419 | compiler_ver = check_output(env['CXX'].split() + ["-dumpversion"]).decode().strip() |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 420 | except OSError: |
| 421 | print("ERROR: Compiler '%s' not found" % env['CXX']) |
| 422 | Exit(1) |
| 423 | |
Georgios Pinitas | e874ef9 | 2019-09-09 17:40:33 +0100 | [diff] [blame] | 424 | if 'armclang' in cpp_compiler: |
| 425 | pass |
| 426 | elif 'clang++' not in cpp_compiler: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 427 | 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] | 428 | 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] | 429 | Exit(1) |
| 430 | elif env['arch'] == 'arm64-v8a' and not version_at_least(compiler_ver, '4.9'): |
Michele Di Giorgio | 33f41fa | 2021-03-09 14:09:08 +0000 | [diff] [blame] | 431 | print("GCC 4.9 or newer is required to compile Arm® Neon™ code for AArch64") |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 432 | Exit(1) |
| 433 | |
| 434 | if version_at_least(compiler_ver, '6.1'): |
| 435 | env.Append(CXXFLAGS = ['-Wno-ignored-attributes']) |
| 436 | |
| 437 | if compiler_ver == '4.8.3': |
| 438 | env.Append(CXXFLAGS = ['-Wno-array-bounds']) |
| 439 | |
Michalis Spyrou | cfac305 | 2020-10-14 12:06:28 +0100 | [diff] [blame] | 440 | if not version_at_least(compiler_ver, '7.0.0') and env['os'] == 'bare_metal': |
| 441 | env.Append(LINKFLAGS = ['-fstack-protector-strong']) |
| 442 | |
SiCong Li | bf5274d | 2022-07-20 17:45:36 +0100 | [diff] [blame] | 443 | # Add Android NDK toolchain specific flags |
| 444 | if 'clang++' in cpp_compiler and env['os'] == 'android': |
| 445 | # For NDK >= r21, clang 9 or above is used |
| 446 | if version_at_least(compiler_ver, '9.0.0'): |
| 447 | env['ndk_above_r21'] = True |
Giorgio Arena | b83e672 | 2022-03-24 14:23:07 +0000 | [diff] [blame] | 448 | |
SiCong Li | bf5274d | 2022-07-20 17:45:36 +0100 | [diff] [blame] | 449 | if env['openmp']: |
| 450 | env.Append(LINKFLAGS = ['-static-openmp']) |
| 451 | |
| 452 | # For NDK >= r23, clang 12 or above is used. This condition detects NDK < r23 |
| 453 | if not version_at_least(compiler_ver, '12.0.0'): |
| 454 | # System assembler is deprecated and integrated assembler is preferred since r23. |
| 455 | # However integrated assembler has always been suppressed for NDK < r23. |
| 456 | # Thus for backward compatibility, we include this flag only for NDK < r23 |
| 457 | env.Append(CXXFLAGS = ['-no-integrated-as']) |
Giorgio Arena | b83e672 | 2022-03-24 14:23:07 +0000 | [diff] [blame] | 458 | |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 459 | if env['high_priority'] and env['build_config']: |
SiCongLi | dc85d78 | 2021-12-17 13:22:55 +0000 | [diff] [blame] | 460 | print("The high priority library cannot be built in conjunction with a user-specified build configuration") |
Georgios Pinitas | b6af482 | 2021-09-14 12:33:34 +0100 | [diff] [blame] | 461 | Exit(1) |
| 462 | |
| 463 | if not env['high_priority'] and not env['build_config']: |
| 464 | env.Append(CPPDEFINES = ['ARM_COMPUTE_GRAPH_ENABLED']) |
| 465 | |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 466 | data_types = [] |
| 467 | data_layouts = [] |
Georgios Pinitas | ff4fca0 | 2020-10-02 21:00:00 +0100 | [diff] [blame] | 468 | |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 469 | # Set correct data types / layouts to build |
| 470 | if env['high_priority']: |
| 471 | data_types = ['all'] |
| 472 | data_layouts = ['all'] |
| 473 | elif env['build_config']: |
| 474 | data_types, data_layouts = read_build_config_json(env['build_config']) |
| 475 | else: |
| 476 | data_types = env['data_type_support'] |
| 477 | data_layouts = env['data_layout_support'] |
| 478 | |
| 479 | env = update_data_type_layout_flags(env, data_types, data_layouts) |
Sheri Zhang | 79144a6 | 2021-02-08 17:43:04 +0000 | [diff] [blame] | 480 | |
Pablo Tello | c6cb35a | 2017-06-21 15:39:47 +0100 | [diff] [blame] | 481 | if env['standalone']: |
Pablo Tello | 29cab36 | 2022-03-10 17:05:34 +0000 | [diff] [blame] | 482 | if not 'windows' in env['os']: |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 483 | env.Append(CXXFLAGS = ['-fPIC']) |
Pablo Tello | 29cab36 | 2022-03-10 17:05:34 +0000 | [diff] [blame] | 484 | env.Append(LINKFLAGS = ['-static-libgcc','-static-libstdc++']) |
| 485 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 486 | if env['Werror']: |
| 487 | env.Append(CXXFLAGS = ['-Werror']) |
| 488 | |
| 489 | if env['os'] == 'android': |
| 490 | env.Append(CPPDEFINES = ['ANDROID']) |
Michalis Spyrou | 2d22c3f | 2020-02-12 14:50:19 +0000 | [diff] [blame] | 491 | env.Append(LINKFLAGS = ['-pie', '-static-libstdc++', '-ldl']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 492 | elif env['os'] == 'bare_metal': |
| 493 | env.Append(LINKFLAGS = ['-static']) |
| 494 | env.Append(CXXFLAGS = ['-fPIC']) |
Manuel Bottini | e5a9ad8 | 2020-11-18 16:22:16 +0000 | [diff] [blame] | 495 | if env['specs_file'] == "": |
| 496 | env.Append(LINKFLAGS = ['-specs=rdimon.specs']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 497 | env.Append(CPPDEFINES = ['NO_MULTI_THREADING']) |
Michalis Spyrou | 07781ac | 2017-08-31 15:11:41 +0100 | [diff] [blame] | 498 | env.Append(CPPDEFINES = ['BARE_METAL']) |
Manuel Bottini | 827817e | 2020-11-19 12:12:06 +0000 | [diff] [blame] | 499 | if env['os'] == 'linux' and env['arch'] == 'armv7a': |
| 500 | env.Append(CXXFLAGS = [ '-Wno-psabi' ]) |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 501 | if env['os'] == 'windows': |
| 502 | env.Append(CXXFLAGS = [ '/std:c++14','/EHa']) |
| 503 | env.Append(CXXFLAGS = [ '-Wno-c++98-compat', '-Wno-covered-switch-default','-Wno-c++98-compat-pedantic']) |
| 504 | env.Append(CXXFLAGS = [ '-Wno-shorten-64-to-32', '-Wno-sign-conversion','-Wno-documentation']) |
| 505 | env.Append(CXXFLAGS = [ '-Wno-extra-semi-stmt', '-Wno-float-equal','-Wno-implicit-int-conversion']) |
| 506 | env.Append(CXXFLAGS = [ '-Wno-documentation-pedantic', '-Wno-extra-semi','-Wno-shadow-field-in-constructor']) |
| 507 | env.Append(CXXFLAGS = [ '-Wno-float-conversion', '-Wno-switch-enum','-Wno-comma']) |
| 508 | env.Append(CXXFLAGS = [ '-Wno-implicit-float-conversion', '-Wno-deprecated-declarations','-Wno-old-style-cast']) |
| 509 | env.Append(CXXFLAGS = [ '-Wno-zero-as-null-pointer-constant', '-Wno-inconsistent-missing-destructor-override']) |
Pablo Tello | fbbfa53 | 2023-01-26 16:24:04 +0000 | [diff] [blame] | 510 | env.Append(CXXFLAGS = [ '-Wno-asm-operand-widths']) |
| 511 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 512 | |
Manuel Bottini | e5a9ad8 | 2020-11-18 16:22:16 +0000 | [diff] [blame] | 513 | if env['specs_file'] != "": |
| 514 | env.Append(LINKFLAGS = ['-specs='+env['specs_file']]) |
| 515 | |
Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 516 | if env['neon']: |
| 517 | env.Append(CPPDEFINES = ['ARM_COMPUTE_CPU_ENABLED']) |
| 518 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 519 | if env['opencl']: |
Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 520 | env.Append(CPPDEFINES = ['ARM_COMPUTE_OPENCL_ENABLED']) |
Georgios Pinitas | e6032da | 2017-10-26 14:13:35 +0100 | [diff] [blame] | 521 | if env['os'] in ['bare_metal'] or env['standalone']: |
Anthony Barbier | 5f0124d | 2018-04-13 14:05:34 +0100 | [diff] [blame] | 522 | print("Cannot link OpenCL statically, which is required for bare metal / standalone builds") |
| 523 | Exit(1) |
| 524 | |
Pablo Tello | 29cab36 | 2022-03-10 17:05:34 +0000 | [diff] [blame] | 525 | if env["os"] not in ["windows","android", "bare_metal"] and (env['opencl'] or env['cppthreads']): |
Anthony Barbier | 9fb0cac | 2018-04-20 15:46:21 +0100 | [diff] [blame] | 526 | env.Append(LIBS = ['pthread']) |
| 527 | |
Kevin Lo | 7195f71 | 2022-01-07 15:46:02 +0800 | [diff] [blame] | 528 | if env['os'] == 'openbsd': |
| 529 | env.Append(LIBS = ['c']) |
| 530 | env.Append(CXXFLAGS = ['-fPIC']) |
| 531 | |
Manuel Bottini | ceaa0bf | 2021-02-16 15:15:19 +0000 | [diff] [blame] | 532 | if env['opencl']: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 533 | if env['embed_kernels']: |
| 534 | env.Append(CPPDEFINES = ['EMBEDDED_KERNELS']) |
Georgios Pinitas | ea85727 | 2021-01-22 05:47:37 +0000 | [diff] [blame] | 535 | if env['compress_kernels']: |
| 536 | env.Append(CPPDEFINES = ['ARM_COMPUTE_COMPRESSED_KERNELS']) |
| 537 | env.Append(LIBS = ['z']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 538 | |
| 539 | if env['debug']: |
| 540 | env['asserts'] = True |
Pablo Tello | 29cab36 | 2022-03-10 17:05:34 +0000 | [diff] [blame] | 541 | if not 'windows' in env['os']: |
| 542 | env.Append(CXXFLAGS = ['-O0','-g','-gdwarf-2']) |
| 543 | else: |
| 544 | env.Append(CXXFLAGS = ['-Z7','-MTd','-fms-compatibility','-fdelayed-template-parsing']) |
| 545 | env.Append(LINKFLAGS = ['-DEBUG']) |
| 546 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 547 | env.Append(CPPDEFINES = ['ARM_COMPUTE_DEBUG_ENABLED']) |
| 548 | else: |
Pablo Tello | 4e66d70 | 2022-03-07 18:20:12 +0000 | [diff] [blame] | 549 | if not 'windows' in env['os']: |
| 550 | env.Append(CXXFLAGS = ['-O3']) |
| 551 | else: |
| 552 | # on windows we use clang-cl which does not support the option -O3 |
| 553 | env.Append(CXXFLAGS = ['-O2']) |
Pablo Tello | 29cab36 | 2022-03-10 17:05:34 +0000 | [diff] [blame] | 554 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 555 | if env['asserts']: |
| 556 | env.Append(CPPDEFINES = ['ARM_COMPUTE_ASSERTS_ENABLED']) |
Pablo Tello | 29cab36 | 2022-03-10 17:05:34 +0000 | [diff] [blame] | 557 | if not 'windows' in env['os']: |
| 558 | env.Append(CXXFLAGS = ['-fstack-protector-strong']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 559 | |
Georgios Pinitas | 7d3d1b9 | 2017-10-12 17:34:20 +0100 | [diff] [blame] | 560 | if env['logging']: |
| 561 | env.Append(CPPDEFINES = ['ARM_COMPUTE_LOGGING_ENABLED']) |
| 562 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 563 | env.Append(CPPPATH = ['#/include', "#"]) |
| 564 | env.Append(CXXFLAGS = env['extra_cxx_flags']) |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 565 | env.Append(LINKFLAGS = env['extra_link_flags']) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 566 | |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 567 | Default( install_include("arm_compute")) |
Anthony Barbier | 1056595 | 2018-11-15 09:50:06 +0000 | [diff] [blame] | 568 | Default( install_include("support")) |
Michele Di Giorgio | 6afea90 | 2019-04-03 11:40:20 +0100 | [diff] [blame] | 569 | Default( install_include("utils")) |
| 570 | for dirname in os.listdir("./include"): |
| 571 | Default( install_include("include/%s" % dirname)) |
Anthony Barbier | 01bbd5f | 2018-11-01 15:10:51 +0000 | [diff] [blame] | 572 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 573 | Export('version_at_least') |
| 574 | |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 575 | SConscript('./SConscript', variant_dir=build_path, duplicate=0) |
Anthony Barbier | 6c0348f | 2017-11-10 18:32:38 +0000 | [diff] [blame] | 576 | |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 577 | if env['examples'] and (env['build_config'] or env['high_priority']): |
| 578 | print("WARNING: Building examples for selected operators not supported. Use examples=0") |
| 579 | Return() |
| 580 | |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 581 | if env['examples'] and env['exceptions']: |
| 582 | if env['os'] == 'bare_metal' and env['arch'] == 'armv7a': |
Michalis Spyrou | 35f35a6 | 2019-12-23 11:29:52 +0000 | [diff] [blame] | 583 | print("WARNING: Building examples for bare metal and armv7a is not supported. Use examples=0") |
| 584 | Return() |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 585 | SConscript('./examples/SConscript', variant_dir='%s/examples' % build_path, duplicate=0) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 586 | |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 587 | if env['exceptions']: |
Freddie Liardet | 487d390 | 2021-09-21 12:36:43 +0100 | [diff] [blame] | 588 | if env['build_config'] or env['high_priority']: |
| 589 | print("WARNING: Building tests for selected operators not supported") |
| 590 | Return() |
Michalis Spyrou | 748a7c8 | 2019-10-07 13:00:44 +0100 | [diff] [blame] | 591 | if env['os'] == 'bare_metal' and env['arch'] == 'armv7a': |
| 592 | print("WARNING: Building tests for bare metal and armv7a is not supported") |
| 593 | Return() |
Anthony Barbier | e8a55df | 2018-10-26 09:05:01 +0100 | [diff] [blame] | 594 | SConscript('./tests/SConscript', variant_dir='%s/tests' % build_path, duplicate=0) |
Motti Gondabi | f76a502 | 2021-12-21 13:19:29 +0200 | [diff] [blame] | 595 | |
| 596 | # Unknown variables are not allowed |
| 597 | # Note: we must delay the call of UnknownVariables until after |
| 598 | # we have applied the Variables object to the construction environment |
| 599 | unknown = vars.UnknownVariables() |
| 600 | if unknown: |
| 601 | print("Unknown variables: %s" % " ".join(unknown.keys())) |
Ramy Elgammal | 451c309 | 2022-02-01 23:01:27 +0000 | [diff] [blame] | 602 | Exit(1) |