blob: 8ee688e76db5b7cec836531ea1aa86a9ae43cb53 [file] [log] [blame]
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01001# Copyright (c) 2017 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002#
3# SPDX-License-Identifier: MIT
4#
5# Permission is hereby granted, free of charge, to any person obtaining a copy
6# of this software and associated documentation files (the "Software"), to
7# deal in the Software without restriction, including without limitation the
8# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9# sell copies of the Software, and to permit persons to whom the Software is
10# furnished to do so, subject to the following conditions:
11#
12# The above copyright notice and this permission notice shall be included in all
13# copies or substantial portions of the Software.
14#
15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21# SOFTWARE.
22import SCons
23import os.path
24
25Import('env')
Anthony Barbier01bbd5f2018-11-01 15:10:51 +000026Import('install_bin')
Anthony Barbier6ff3b192017-09-04 18:44:23 +010027
Anthony Barbier6ff3b192017-09-04 18:44:23 +010028examples_env = env.Clone()
29
30examples_env.Append(CPPPATH = ["#"])
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031
32# Build examples
33utils = examples_env.Object("../utils/Utils.cpp")
34
Georgios Pinitas45514032020-12-30 00:03:09 +000035if env['os'] in ['android', 'macos', 'bare_metal'] or env['standalone']:
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010036 Import('arm_compute_graph_a')
Pablo Telloc6cb35a2017-06-21 15:39:47 +010037 Import('arm_compute_a')
Anthony Barbierb2881fc2017-09-29 17:12:12 +010038 Import('arm_compute_core_a')
39 arm_compute_libs = [ arm_compute_a, arm_compute_core_a ]
Anthony Barbier8ddab142018-07-13 11:52:37 +010040 arm_compute_graph_libs = arm_compute_libs # The graph library needs to be linked separately with --whole-archive
Anthony Barbier6ff3b192017-09-04 18:44:23 +010041 arm_compute_dependency = arm_compute_a
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010042 graph_dependency = [arm_compute_graph_a]
Anthony Barbier6ff3b192017-09-04 18:44:23 +010043else:
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010044 Import('arm_compute_graph_so')
Pablo Telloc6cb35a2017-06-21 15:39:47 +010045 Import('arm_compute_so')
Anthony Barbier8ddab142018-07-13 11:52:37 +010046 arm_compute_libs = ["arm_compute", "arm_compute_core"]
47 arm_compute_graph_libs = [ "arm_compute_graph" ] + arm_compute_libs
Anthony Barbier6ff3b192017-09-04 18:44:23 +010048 arm_compute_dependency = arm_compute_so
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010049 graph_dependency = [arm_compute_graph_so]
Anthony Barbier6ff3b192017-09-04 18:44:23 +010050
Michalis Spyrou6a9e8012020-02-07 09:45:55 +000051extra_link_flags = []
52if env['os'] != 'bare_metal':
53 extra_link_flags += ['-fstack-protector-strong']
54
Georgios Pinitas45514032020-12-30 00:03:09 +000055load_whole_archive = '-Wl,--whole-archive'
56noload_whole_archive = '-Wl,--no-whole-archive'
57if 'macos' in examples_env['os']:
58 load_whole_archive = '-Wl,-force_load'
59 noload_whole_archive = '-Wl,-noall_load'
60
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010061# Build graph examples
62graph_utils = examples_env.Object("../utils/GraphUtils.cpp")
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010063graph_utils += examples_env.Object("../utils/CommonGraphOptions.cpp")
Anthony Barbier7fb7b612018-05-16 11:58:52 +010064examples_libs = examples_env.get("LIBS",[])
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010065for file in Glob("./graph_*.cpp"):
66 example = os.path.basename(os.path.splitext(str(file))[0])
67 prog = None
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010068
Georgios Pinitas45514032020-12-30 00:03:09 +000069 if env['os'] in ['android', 'macos', 'bare_metal'] or env['standalone']:
70 prog = examples_env.Program(example, ["{}.cpp".format(example), utils, graph_utils], LIBS = examples_libs + arm_compute_graph_libs, LINKFLAGS=examples_env["LINKFLAGS"]+[load_whole_archive, graph_dependency, noload_whole_archive] + extra_link_flags)
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010071 Depends(prog, graph_dependency)
Michalis Spyrou165308c2019-04-10 10:10:21 +010072 prog = install_bin(prog)
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010073 else:
74 #-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies
Anthony Barbier7fb7b612018-05-16 11:58:52 +010075 prog = examples_env.Program(example, ["{}.cpp".format(example), utils, graph_utils], LIBS = examples_libs + arm_compute_graph_libs, LINKFLAGS=examples_env["LINKFLAGS"]+['-Wl,--allow-shlib-undefined'] )
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010076 Depends(prog, graph_dependency)
Michalis Spyrou165308c2019-04-10 10:10:21 +010077 prog = install_bin(prog)
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010078 alias = examples_env.Alias(example, prog)
79 Default(alias)
80
Georgios Pinitas33893c32018-05-18 16:54:54 +010081if env['opencl'] and env['neon']:
Anthony Barbier6ff3b192017-09-04 18:44:23 +010082 for file in Glob("./neoncl_*.cpp"):
83 example = os.path.basename(os.path.splitext(str(file))[0])
Anthony Barbier7fb7b612018-05-16 11:58:52 +010084 prog = examples_env.Program(example, ["{}.cpp".format(example), utils], CPPDEFINES=['ARM_COMPUTE_CL'], LIBS = examples_libs + arm_compute_libs)
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010085 Depends(prog, arm_compute_dependency)
Michalis Spyrou165308c2019-04-10 10:10:21 +010086 prog = install_bin(prog)
Anthony Barbier2a07e182017-08-04 18:20:27 +010087 alias = examples_env.Alias(example, prog)
88 Default(alias)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010089
90if env['opencl']:
91 for file in Glob("./cl_*.cpp"):
92 example = os.path.basename(os.path.splitext(str(file))[0])
Anthony Barbier7fb7b612018-05-16 11:58:52 +010093 prog = examples_env.Program(example, ["{}.cpp".format(example), utils], CPPDEFINES=['ARM_COMPUTE_CL'], LIBS = examples_libs + arm_compute_libs)
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010094 Depends(prog, arm_compute_dependency)
Michalis Spyrou165308c2019-04-10 10:10:21 +010095 prog = install_bin(prog)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010096 alias = examples_env.Alias(example, prog)
97 Default(alias)
98
SiCong Li8b4c7302019-09-19 12:18:15 +010099if env['gemm_tuner'] and env['opencl']:
SiCong Li240b79d2019-09-24 15:50:34 +0100100 gemm_tuner_common_options = examples_env.Object("./gemm_tuner/CommonGemmExampleOptions.cpp")
SiCong Li8b4c7302019-09-19 12:18:15 +0100101 for file in Glob("./gemm_tuner/cl_*.cpp"):
102 example = os.path.basename(os.path.splitext(str(file))[0])
103 example = os.path.join("gemm_tuner", example)
Georgios Pinitas45514032020-12-30 00:03:09 +0000104 if env['os'] in ['android', 'macos', 'bare_metal'] or env['standalone']:
105 prog = examples_env.Program(example, ["{}.cpp".format(example), utils, gemm_tuner_common_options], CPPDEFINES=['ARM_COMPUTE_CL'], LIBS = examples_libs + arm_compute_graph_libs, LINKFLAGS=examples_env["LINKFLAGS"]+[load_whole_archive, graph_dependency, noload_whole_archive, '-fstack-protector-strong'] )
Eren Kopuz350099e2020-06-09 15:37:43 +0100106 Depends(prog, graph_dependency)
107 prog = install_bin(prog)
108 else:
109 #-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies
110 prog = examples_env.Program(example, ["{}.cpp".format(example), utils, gemm_tuner_common_options], CPPDEFINES=['ARM_COMPUTE_CL'], LIBS = examples_libs + arm_compute_graph_libs, LINKFLAGS=examples_env["LINKFLAGS"]+['-Wl,--allow-shlib-undefined'] )
111 Depends(prog, graph_dependency)
112 prog = install_bin(prog)
SiCong Li8b4c7302019-09-19 12:18:15 +0100113 alias = examples_env.Alias(example, prog)
114 Default(alias)
115
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100116if env['neon']:
117 for file in Glob("./neon_*.cpp"):
118 example = os.path.basename(os.path.splitext(str(file))[0])
Michalis Spyrou01833682020-01-09 15:15:13 +0000119
120 prog = None
121 if env['os'] in ['bare_metal']:
Michalis Spyrou6a9e8012020-02-07 09:45:55 +0000122 prog = examples_env.Program(example, ["{}.cpp".format(example), utils], LINKFLAGS=examples_env["LINKFLAGS"], LIBS = examples_libs + arm_compute_libs)
Michalis Spyrou01833682020-01-09 15:15:13 +0000123 else:
124 prog = examples_env.Program(example, ["{}.cpp".format(example), utils], LIBS = examples_libs + arm_compute_libs)
125
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100126 Depends(prog, arm_compute_dependency)
Michalis Spyrou165308c2019-04-10 10:10:21 +0100127 prog = install_bin(prog)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100128 alias = examples_env.Alias(example, prog)
129 Default(alias)
Anthony Barbier7068f992017-10-26 15:23:08 +0100130
Michele Di Giorgio72610dc2020-11-18 15:29:08 +0000131if env['external_tests_dir']:
132 for file in Glob(env['external_tests_dir'] + "/examples/graph_*.cpp"):
133 example = os.path.basename(os.path.splitext(str(file))[0])
134 prog = None
Georgios Pinitas33893c32018-05-18 16:54:54 +0100135
Georgios Pinitas45514032020-12-30 00:03:09 +0000136 if env['os'] in ['android', 'macos', 'bare_metal'] or env['standalone']:
137 prog = examples_env.Program(example, [examples_env.Object(source=file, target=example), utils, graph_utils], LIBS = examples_libs + arm_compute_graph_libs, LINKFLAGS=examples_env["LINKFLAGS"]+[load_whole_archive, graph_dependency, noload_whole_archive] + extra_link_flags)
Michele Di Giorgio72610dc2020-11-18 15:29:08 +0000138 Depends(prog, graph_dependency)
139 prog = install_bin(prog)
140 else:
141 #-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies
142 prog = examples_env.Program(example, [examples_env.Object(source=file, target=example), utils, graph_utils], LIBS = examples_libs + arm_compute_graph_libs, LINKFLAGS=examples_env["LINKFLAGS"]+['-Wl,--allow-shlib-undefined'] )
143 Depends(prog, graph_dependency)
144 prog = install_bin(prog)
145 alias = examples_env.Alias(example, prog)
146 Default(alias)