1# Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6#     http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14import("//build/ohos.gni")
15import("../../base/config.gni")
16
17config("hook_config") {
18  defines = [
19    "HAVE_LIBUNWIND=0",
20    "HAVE_LIBUNWINDER=1",
21    "HIPERF_DEBUG",
22    "CONFIG_NO_HILOG",
23  ]
24  defines += [ "target_cpu_${target_cpu}" ]
25  if (!is_asan) {
26    defines += [ "HOOK_ENABLE" ]
27  }
28}
29
30ohos_source_set("native_hook_source") {
31  use_exceptions = true
32  sources = [
33    "../../services/ipc/src/socket_context.cpp",
34    "../../services/ipc/src/unix_socket_client.cpp",
35    "../native_daemon/src/debug_logger.cpp",
36    "../native_daemon/src/get_thread_id.cpp",
37    "../native_daemon/src/register.cpp",
38    "../native_daemon/src/utilities.cpp",
39    "src/hook_client.cpp",
40    "src/hook_socket_client.cpp",
41    "src/runtime_stack_range.cpp",
42    "src/sampling.cpp",
43    "src/stack_writer.cpp",
44  ]
45  include_dirs = [
46    "./include",
47    "../api/include",
48    "../api/src",
49    "../../base/include/",
50    "../native_daemon/include",
51    "${OHOS_PROFILER_DIR}/interfaces/kits",
52    "${OHOS_PROFILER_DIR}/device/services/ipc/include",
53    "${OHOS_PROFILER_DIR}/device/services/shared_memory/include",
54  ]
55  public_configs = [
56    ":hook_config",
57    "${OHOS_PROFILER_DIR}/device/base:hiprofiler_test_config",
58  ]
59  deps = [
60    "${OHOS_PROFILER_DIR}/device/services/shared_memory:shared_memory_lite",
61    "../../base:hiprofiler_base",
62  ]
63  if (hiprofiler_use_libunwind) {
64    public_deps = [ "//third_party/libunwind:unwind_source_${target_cpu}" ]
65  }
66  external_deps = [
67    "bounds_checking_function:libsec_shared",
68    "ffrt:libffrt",
69    "hitrace:libhitracechain",
70    "init:libbegetutil",
71    "zlib:libz",
72  ]
73  if (hiprofiler_use_libunwinder) {
74    external_deps += [ "faultloggerd:libunwinder" ]
75  }
76
77  if (current_toolchain != host_toolchain) {
78    defines = [ "HAVE_HILOG" ]
79    external_deps += [ "hilog:libhilog_base" ]
80  }
81  subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}"
82  part_name = "${OHOS_PROFILER_PART_NAME}"
83  defines += [ "NO_PROTOBUF" ]
84  cflags = [
85    "-Wno-error=inline-asm",
86    "-DPERF_TEST_DATA",
87    "-O3",
88  ]
89}
90
91ohos_shared_library("native_hook") {
92  output_name = "native_hook"
93  deps = [ ":native_hook_source" ]
94  if (current_toolchain != host_toolchain) {
95    defines = [ "HAVE_HILOG" ]
96    external_deps = [ "hilog:libhilog_base" ]
97  }
98  version_script = "libnative_hook.map"
99  install_enable = true
100  subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}"
101  part_name = "${OHOS_PROFILER_PART_NAME}"
102}
103
104ohos_executable("nativetest_c") {
105  output_name = "nativetest_c"
106  sources = [ "test/hook_test.c" ]
107
108  if (current_toolchain != host_toolchain) {
109    defines = [ "HAVE_HILOG" ]
110    if (use_musl && !is_asan) {
111      defines += [ "HOOK_ENABLE" ]
112    }
113    external_deps = [ "hilog:libhilog_base" ]
114  }
115  cflags = [
116    "-Wno-error=inline-asm",
117    "-O3",
118  ]
119  external_deps += [ "bounds_checking_function:libsec_shared" ]
120  ldflags = [ "-rdynamic" ]
121  install_enable = false
122  subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}"
123  part_name = "${OHOS_PROFILER_PART_NAME}"
124}
125
126ohos_executable("nativetest_cpp") {
127  output_name = "nativetest_cpp"
128  sources = [ "test/hook_test.cpp" ]
129
130  if (current_toolchain != host_toolchain) {
131    defines = [ "HAVE_HILOG" ]
132    external_deps = [ "hilog:libhilog_base" ]
133  }
134
135  cflags = [
136    "-Wno-error=inline-asm",
137    "-O3",
138  ]
139  ldflags = [ "-rdynamic" ]
140
141  install_enable = false
142  subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}"
143  part_name = "${OHOS_PROFILER_PART_NAME}"
144}
145
146ohos_shared_library("nativetest_so") {
147  output_name = "nativetest_so"
148  sources = [ "test/hook_so.cpp" ]
149
150  if (current_toolchain != host_toolchain) {
151    defines = [ "HAVE_HILOG" ]
152    external_deps = [ "hilog:libhilog_base" ]
153  }
154
155  cflags = [
156    "-Wno-error=inline-asm",
157    "-O3",
158  ]
159
160  install_enable = false
161  subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}"
162  part_name = "${OHOS_PROFILER_PART_NAME}"
163}
164
165ohos_executable("malloctest_cpp") {
166  output_name = "malloctest_cpp"
167  sources = [ "test/malloc_test.cpp" ]
168
169  if (current_toolchain != host_toolchain) {
170    defines = [ "HAVE_HILOG" ]
171    external_deps = [ "hilog:libhilog_base" ]
172  }
173
174  cflags = [
175    "-Wno-error=inline-asm",
176    "-O3",
177  ]
178  external_deps += [ "bounds_checking_function:libsec_shared" ]
179  ldflags = [ "-rdynamic" ]
180  install_enable = false
181  subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}"
182  part_name = "${OHOS_PROFILER_PART_NAME}"
183}
184
185ohos_executable("perf_test_data") {
186  output_name = "perf_test_data"
187  sources = [ "test/perf_test_data.cpp" ]
188
189  if (current_toolchain != host_toolchain) {
190    defines = [ "HAVE_HILOG" ]
191    external_deps = [ "hilog:libhilog_base" ]
192  }
193
194  cflags = [ "-Wno-error=inline-asm" ]
195  install_enable = false
196  ldflags = [ "-rdynamic" ]
197  subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}"
198  part_name = "${OHOS_PROFILER_PART_NAME}"
199}
200
201ohos_executable("statisticstest_cpp") {
202  output_name = "statisticstest_cpp"
203  sources = [ "test/statistics_test.cpp" ]
204
205  if (current_toolchain != host_toolchain) {
206    defines = [ "HAVE_HILOG" ]
207    external_deps = [ "hilog:libhilog_base" ]
208  }
209
210  cflags = [
211    "-Wno-error=inline-asm",
212    "-O3",
213  ]
214  ldflags = [ "-rdynamic" ]
215  external_deps += [ "bounds_checking_function:libsec_shared" ]
216  install_enable = false
217  subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}"
218  part_name = "${OHOS_PROFILER_PART_NAME}"
219}
220