arm_compute v17.12
[platform/upstream/armcl.git] / examples / SConscript
1 # Copyright (c) 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 import SCons
23 import os.path
24
25 Import('env')
26
27 if env['opencl']:
28     Import('opencl')
29
30 if env['gles_compute'] and env['os'] != 'android':
31     Import('egl')
32     Import('glesv2')
33
34 examples_env = env.Clone()
35
36 examples_env.Append(CPPPATH = ["#"])
37 examples_env.Append(LIBPATH = ["#build/%s/opencl-1.2-stubs" % env['build_dir']])
38
39 # Build examples
40 utils = examples_env.Object("../utils/Utils.cpp")
41
42 if env['os'] in ['android', 'bare_metal'] or env['standalone']:
43     Import('arm_compute_a')
44     Import('arm_compute_core_a')
45     arm_compute_libs = [ arm_compute_a, arm_compute_core_a ]
46     arm_compute_dependency = arm_compute_a
47 else:
48     Import('arm_compute_so')
49     arm_compute_libs = ["arm_compute", "arm_compute_core"]
50     arm_compute_dependency = arm_compute_so
51
52 if env['opencl'] and env['neon']:
53     for file in Glob("./neoncl_*.cpp"):
54         example = os.path.basename(os.path.splitext(str(file))[0])
55         prog = examples_env.Program(example, ["{}.cpp".format(example), utils], CPPDEFINES=['ARM_COMPUTE_CL'], LIBS = arm_compute_libs +["OpenCL"])
56         Depends(prog, [arm_compute_dependency, opencl])
57         alias = examples_env.Alias(example, prog)
58         Default(alias)
59     if env['os'] == 'android':
60         Import('arm_compute_graph_a')
61         Import('arm_compute_core_a')
62         Import('arm_compute_a')
63         arm_compute_graph_libs = [ arm_compute_a, arm_compute_core_a, "OpenCL"]
64         graph_dependency = arm_compute_graph_a
65     else:
66         Import('arm_compute_graph_so')
67         arm_compute_graph_libs = ["arm_compute_graph", "arm_compute", "arm_compute_core"]
68         graph_dependency = arm_compute_graph_so
69
70     graph_utils = examples_env.Object("../utils/GraphUtils.cpp")
71     for file in Glob("./graph_*.cpp"):
72         example = os.path.basename(os.path.splitext(str(file))[0])
73         prog = None
74         if env['os'] == 'android':
75             prog = examples_env.Program(example, ["{}.cpp".format(example), utils, graph_utils], LIBS = arm_compute_graph_libs + ["OpenCL"], LINKFLAGS=examples_env["LINKFLAGS"]+['-Wl,--whole-archive',graph_dependency,'-Wl,--no-whole-archive'])
76             Depends(prog, [graph_dependency, opencl])
77         else:
78             #-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies
79             prog = examples_env.Program(example, ["{}.cpp".format(example), utils, graph_utils], LIBS = arm_compute_graph_libs, LINKFLAGS=examples_env["LINKFLAGS"]+['-Wl,--allow-shlib-undefined'] )
80             Depends(prog, graph_dependency)
81         alias = examples_env.Alias(example, prog)
82         Default(alias)
83
84 if env['opencl']:
85     for file in Glob("./cl_*.cpp"):
86         example = os.path.basename(os.path.splitext(str(file))[0])
87         prog = examples_env.Program(example, ["{}.cpp".format(example), utils], CPPDEFINES=['ARM_COMPUTE_CL'], LIBS = arm_compute_libs +["OpenCL"])
88         Depends(prog, [arm_compute_dependency, opencl])
89         alias = examples_env.Alias(example, prog)
90         Default(alias)
91
92 if env['neon']:
93     for file in Glob("./neon_*.cpp"):
94         example = os.path.basename(os.path.splitext(str(file))[0])
95         prog = examples_env.Program(example, ["{}.cpp".format(example), utils], LIBS = arm_compute_libs)
96         Depends(prog, arm_compute_dependency)
97         alias = examples_env.Alias(example, prog)
98         Default(alias)
99
100 if env['gles_compute']:
101     for file in Glob("./gc_*.cpp"):
102         example = os.path.basename(os.path.splitext(str(file))[0])
103         if env['os'] != 'android':
104             prog = examples_env.Program(example, ["{}.cpp".format(example), utils], CPPDEFINES=['ARM_COMPUTE_GC'], LIBS = [arm_compute_libs, "EGL", "GLESv2"])
105             Depends(prog, [arm_compute_dependency, egl, glesv2])
106         else:
107             if env['arch'] != 'armv7a':
108                 prog = examples_env.Program(example, ["{}.cpp".format(example), utils], CPPDEFINES=['ARM_COMPUTE_GC'], LIBS = [arm_compute_libs, "EGL", "GLESv3"])
109             else:
110                 prog = examples_env.Program(example, ["{}.cpp".format(example), utils], CPPDEFINES=['ARM_COMPUTE_GC'], LIBS = [arm_compute_libs, "EGL", "GLESv2"])
111             Depends(prog, [arm_compute_dependency])
112         alias = examples_env.Alias(example, prog)
113         Default(alias)