• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (C) 2021 Huawei Device Co., Ltd.
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.
13import("../build/ts.gni")
14print("target_os", target_os)
15print("target_name", target)
16group("default_deps") {
17  public_configs = [ ":default_config" ]
18  public_deps = []
19}
20config("default_config") {
21  include_dirs = [
22    "..",
23    "../include",
24  ]
25}
26config("trace_cfg") {
27  cflags_cc = [
28    "-std=c++17",
29    "-fvisibility=hidden",
30    "-Wno-unused-variable",
31  ]
32  if (!is_test) {
33    cflags_cc += [
34      "-fno-rtti",
35      "-fno-exceptions",
36    ]
37  }
38}
39
40config("hiperf_trace_cfg") {
41  cflags_cc = [
42    "-std=c++17",
43    "-fvisibility=hidden",
44    "-Wno-unused-variable",
45  ]
46}
47
48config("visibility_hidden") {
49  cflags = [ "-fvisibility=hidden" ]
50}
51
52config("default") {
53  cflags_c = []
54  cflags_cc = []
55  libs = []
56
57  cflags = [
58    "-fstrict-aliasing",
59    "-g",
60    "-Wformat",
61    "-Wno-unused-variable",
62  ]
63  if (is_debug && is_win) {
64    ldflags = [ "-fstack-protector" ]
65  }
66  if (target_os == "windows") {
67    cflags += [ "-D target_cpu_x86_64" ]
68    libs += [ "z" ]
69  } else if (is_linux || is_macx) {
70    cflags += [
71      "-Wa,--noexecstack",
72      "-fcolor-diagnostics",
73      "-fdiagnostics-show-template-tree",
74      "-ftrapv",
75    ]
76    if (!use_wasm) {
77      cflags += [
78        "-fstack-protector-strong",
79        "-fstack-protector-all",
80        "-D_FORTIFY_SOURCE=2 -O2",
81
82        # "-D SUPPORTTHREAD",  # if support thread
83
84        # "-D HAVE_ELF_H",
85        "-D target_cpu_x64",
86        "-D target_cpu_x86_64",
87
88        # "-D HAVE_LINK_H",
89        # "-D_GNU_SOURCE",
90        "-DHAVE_CONFIG_H",
91        "-DCC_IS_CLANG",
92      ]
93      libs += [ "z" ]
94
95      # with_libunwind = true
96    }
97    if (!use_wasm && !is_win && !is_macx && !is_test) {
98      cflags += [ "-D HAVE_LIBUNWIND" ]
99    }
100
101    cflags += [ "-D USE_VTABLE" ]
102    if (use_wasm) {
103      cflags += [
104        "-D IS_WASM",
105        "-D GOOGLE_PROTOBUF_NO_RDTSC",
106
107        #  "-D HAVE_LIBUNWIND",
108        "-D target_cpu_x64",
109        "-D target_cpu_x86_64",
110        "-DHAVE_CONFIG_H",
111        "-DNDEBUG",
112        "-DCC_IS_CLANG",
113        "-D__x86_64__",
114      ]
115    }
116    cflags += [ "-D BINDER_ASYNC" ]
117    libs += [ "pthread" ]
118    if (!is_macx) {
119      libs += [ "rt" ]
120    }
121    if (!is_win) {
122      cflags += [
123        "-fPIE",
124        "-fPIC",
125      ]
126    }
127  }
128  if (use_wasm) {
129    cflags += [ "-D IS_WASM" ]
130  }
131  if (is_win) {
132    cflags += [ "-D is_mingw" ]
133    defines = [ "WIN32_LEAN_AND_MEAN" ]
134    libs += [ "wsock32" ]
135    libs += [ "Ws2_32" ]
136    cflags += [
137      "-D SECUREC_IS_DLL_LIBRARY",
138      "-D __KERNEL__",
139    ]
140  }
141  if (with_perf) {
142    cflags += [ "-D WITH_PERF" ]
143  }
144  if (with_ebpf_help_table) {
145    cflags += [ "-D WITH_EBPF_HELP" ]
146  }
147}
148
149config("symbols") {
150  cflags = [ "-O0" ]
151  if (is_linux || is_macx) {
152    cflags += [ "-funwind-tables" ]
153  }
154}
155
156config("release") {
157  cflags = [
158    "-fdata-sections",
159    "-ffunction-sections",
160  ]
161
162  cflags += [ "-O3" ]
163  ldflags = [ "-fstack-protector" ]
164  if (!is_macx) {
165    ldflags += [ "-Wl,-O1" ]
166    if (!is_win) {
167      ldflags += [
168        "-fuse-ld=gold",
169        "-Wl,--gc-sections",
170      ]
171    }
172  }
173
174  if (!is_win && !is_macx) {
175    ldflags += [
176      "-fPIC",
177      "-fpie",
178      "-pie",
179    ]
180  }
181  defines = [ "NDEBUG" ]
182}
183
184config("shared_library") {
185  if (!is_win) {
186    ldflags = [ "-fPIC" ]
187  }
188}
189
190config("executable") {
191  print("use_wasm", use_wasm)
192  ldflags = []
193
194  if (is_linux || (is_macx && !use_wasm)) {
195    ldflags += []
196  }
197  if (!is_macx && !use_wasm && !is_win) {
198    ldflags = [
199      "-Wl,--disable-new-dtags",
200      "-Wl,-z,noexecstack",
201      "-lrt",
202      "-fuse-ld=gold",
203      "-Wl,-z,now",
204      "-Wl,-z,relro",
205    ]
206  }
207  if (!is_macx && !use_wasm) {
208    ldflags += [ "-fpie" ]
209  }
210  if (!is_macx && !use_wasm && !is_win) {
211    ldflags += [ "-pie" ]
212  }
213  if (!is_macx) {
214    ldflags += [ "-Wl,--gc-sections" ]
215  }
216  if (is_macx) {
217    ldflags += [
218      "-fdata-sections",
219      "-ffunction-sections",
220    ]
221    if (!use_wasm) {
222      ldflags += [ "-Wl,-U,__sanitizer_options_link_helper" ]
223    }
224  }
225  if (!is_debug && !is_macx) {
226    ldflags += [ "-s" ]
227  } else if (!is_debug && is_macx) {
228    ldflags += [ "-dead_strip" ]
229  }
230}
231