1# Copyright (c) Huawei Technologies Co., Ltd. 2023. 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. 13import("../build/ts.gni") 14print("target_os", target_os) 15group("default_deps") { 16 public_configs = [ ":default_config" ] 17 public_deps = [] 18} 19config("default_config") { 20 include_dirs = [ 21 "..", 22 "../include", 23 ] 24} 25config("trace_cfg") { 26 cflags_cc = [ 27 "-std=c++17", 28 "-fvisibility=hidden", 29 "-Wno-unused-variable", 30 ] 31 if (!is_test) { 32 cflags_cc += [ 33 "-fno-rtti", 34 "-fno-exceptions", 35 ] 36 } 37} 38 39config("hiperf_trace_cfg") { 40 cflags_cc = [ 41 "-std=c++17", 42 "-fvisibility=hidden", 43 "-Wno-unused-variable", 44 ] 45} 46 47config("visibility_hidden") { 48 cflags = [ "-fvisibility=hidden" ] 49} 50 51config("default") { 52 cflags_c = [] 53 cflags_cc = [] 54 defines = [] 55 libs = [] 56 ldflags = [] 57 cflags = [ 58 "-fstrict-aliasing", 59 "-Wformat", 60 "-Wno-unused-variable", 61 ] 62 if (enable_hiperf) { 63 defines += [ "ENABLE_HIPERF" ] 64 } 65 if (enable_ebpf) { 66 defines += [ "ENABLE_EBPF" ] 67 } 68 if (enable_native_hook) { 69 defines += [ "ENABLE_NATIVE_HOOK" ] 70 } 71 if (enable_hilog) { 72 defines += [ "ENABLE_HILOG" ] 73 } 74 if (enable_hisysevent) { 75 defines += [ "ENABLE_HISYSEVENT" ] 76 } 77 if (enable_arkts) { 78 defines += [ "ENABLE_ARKTS" ] 79 } 80 if (enable_bytrace) { 81 defines += [ "ENABLE_BYTRACE" ] 82 } 83 if (enable_rawtrace) { 84 defines += [ "ENABLE_RAWTRACE" ] 85 } 86 if (enable_ffrt) { 87 defines += [ "ENABLE_FFRT" ] 88 enable_htrace = true 89 } 90 if (enable_htrace) { 91 defines += [ "ENABLE_HTRACE" ] 92 } 93 if (enable_memory) { 94 defines += [ "ENABLE_MEMORY" ] 95 } 96 if (enable_hidump) { 97 defines += [ "ENABLE_HTDUMP" ] 98 } 99 if (enable_cpudata) { 100 defines += [ "ENABLE_CPUDATA" ] 101 } 102 if (enable_network) { 103 defines += [ "ENABLE_NETWORK" ] 104 } 105 if (enable_diskio) { 106 defines += [ "ENABLE_DISKIO" ] 107 } 108 if (enable_process) { 109 defines += [ "ENABLE_PROCESS" ] 110 } 111 if (enable_xpower) { 112 defines += [ "ENABLE_XPOWER" ] 113 } 114 if (enable_stream_extend) { 115 defines += [ "ENABLE_STREAM_EXTEND" ] 116 } 117 if (enable_addr2line) { 118 defines += [ "ENABLE_ADDR2LINE" ] 119 } 120 if (is_debug && is_win) { 121 ldflags += [ "-fstack-protector" ] 122 } 123 if (is_debug && !use_wasm) { 124 cflags += [ "-g" ] 125 if (is_linux) { 126 cflags += [ 127 "-fno-omit-frame-pointer", 128 "-fstandalone-debug", 129 ] 130 ldflags += [ "-fsanitize=address" ] 131 } 132 } 133 134 if (target_os == "windows") { 135 cflags += [ "-D target_cpu_x86_64" ] 136 } else if (is_linux || is_mac) { 137 cflags += [ 138 "-Wa,--noexecstack", 139 "-fcolor-diagnostics", 140 "-fdiagnostics-show-template-tree", 141 "-ftrapv", 142 ] 143 if (!use_wasm) { 144 cflags += [ 145 "-fstack-protector-strong", 146 "-fstack-protector-all", 147 "-D_FORTIFY_SOURCE=2 -O2", 148 "-D target_cpu_x64", 149 "-D target_cpu_x86_64", 150 "-DHAVE_CONFIG_H", 151 "-DCC_IS_CLANG", 152 ] 153 } 154 if (!use_wasm && !is_win && !is_mac && !is_test && !is_mingw) { 155 cflags += [ "-D HAVE_LIBUNWIND" ] 156 } 157 if (use_wasm) { 158 cflags += [ 159 "-D IS_WASM", 160 "-D GOOGLE_PROTOBUF_NO_RDTSC", 161 "-D target_cpu_x64", 162 "-D target_cpu_x86_64", 163 "-DHAVE_CONFIG_H", 164 "-DCC_IS_CLANG", 165 "-D__x86_64__", 166 ] 167 } 168 cflags += [ "-D BINDER_ASYNC" ] 169 libs += [ "pthread" ] 170 if (!is_mac) { 171 libs += [ "rt" ] 172 } 173 if (!is_win) { 174 cflags += [ 175 "-fPIE", 176 "-fPIC", 177 ] 178 } 179 } 180 if (use_wasm) { 181 cflags += [ "-D IS_WASM" ] 182 if (wasm_use_thread) { 183 cflags += [ 184 "-D SUPPORTTHREAD", 185 "-mbulk-memory", 186 "-matomics", 187 ] 188 } 189 } 190 if (!use_wasm) { 191 cflags += [ "-D SUPPORTTHREAD" ] 192 } 193 if (is_win) { 194 cflags += [ "-D is_mingw" ] 195 defines += [ "WIN32_LEAN_AND_MEAN" ] 196 libs += [ "wsock32" ] 197 libs += [ "ws2_32" ] 198 cflags += [ "-Wno-attributes" ] 199 } 200 if (is_linux) { 201 cflags += [ "-D is_linux" ] 202 } 203 if (is_mac) { 204 cflags += [ "-D is_mac" ] 205 } 206} 207 208config("symbols") { 209 cflags = [ "-O3" ] 210 cflags += [ 211 "-fdata-sections", 212 "-ffunction-sections", 213 ] 214 if (is_linux || is_mac) { 215 cflags += [ "-funwind-tables" ] 216 } 217} 218 219config("release") { 220 cflags = [ 221 "-fdata-sections", 222 "-ffunction-sections", 223 ] 224 cflags += [ "-O3" ] 225 ldflags = [ "-fstack-protector" ] 226 if (!is_mac) { 227 ldflags += [ "-Wl,-O3" ] 228 if (!is_win) { 229 ldflags += [ 230 "-fuse-ld=gold", 231 "-Wl,--gc-sections", 232 ] 233 } 234 } 235 236 if (!is_win && !is_mac) { 237 ldflags += [ 238 "-fPIC", 239 "-fpie", 240 "-pie", 241 ] 242 } 243} 244 245config("shared_library") { 246 if (!is_win) { 247 ldflags = [ "-fPIC" ] 248 } 249} 250 251config("executable") { 252 print("use_wasm", use_wasm) 253 ldflags = [] 254 255 if (is_linux || (is_mac && !use_wasm)) { 256 ldflags += [] 257 } 258 if (!is_mac && !use_wasm && !is_win) { 259 ldflags += [ 260 "-Wl,--disable-new-dtags", 261 "-Wl,-z,noexecstack", 262 "-lrt", 263 "-fuse-ld=gold", 264 "-Wl,-z,now", 265 "-Wl,-z,relro", 266 ] 267 } 268 if (!is_mac && !use_wasm) { 269 ldflags += [ "-fpie" ] 270 } 271 if (!is_mac && !use_wasm && !is_win) { 272 ldflags += [ "-pie" ] 273 } 274 if (!is_mac) { 275 ldflags += [ "-Wl,--gc-sections" ] 276 } 277 if (is_mac) { 278 ldflags += [ 279 "-fdata-sections", 280 "-ffunction-sections", 281 ] 282 if (!use_wasm) { 283 ldflags += [ "-Wl,-U,__sanitizer_options_link_helper" ] 284 } 285 } 286 if (!is_debug && !is_mac) { 287 ldflags += [ "-s" ] 288 } else if (!is_debug && is_mac) { 289 ldflags += [ "-dead_strip" ] 290 } 291} 292 293config("ts_config") { 294 ldflags = [] 295 cflags = [ 296 "-D target_cpu_${target_cpu}", 297 "-std=c++17", 298 ] 299 cflags += [ "-D __LITTLE_ENDIAN_BITFIELD" ] 300 301 if (is_mingw) { 302 cflags += [ "-ffunction-sections" ] 303 cflags += [ "-D is_mingw=1" ] 304 cflags += [ "-Wno-inconsistent-dllimport" ] 305 defines = [ "WIN32_LEAN_AND_MEAN" ] 306 ldflags += [ 307 "-Wl,--whole-archive", 308 "-lpthread", 309 "-Wl,--no-whole-archive", 310 ] 311 312 libs = [ "wsock32" ] 313 libs += [ "ws2_32" ] 314 } 315 if (is_linux) { 316 cflags += [ "-D is_linux=1" ] 317 } 318 if (!use_wasm && !is_win && !is_mac && !is_test && !is_mingw) { 319 cflags += [ "-D HAVE_LIBUNWIND" ] 320 } 321 if (enable_ts_utest && !use_wasm) { 322 cflags += [ 323 "-fprofile-arcs", 324 "-ftest-coverage", 325 ] 326 ldflags += [ 327 "-fprofile-arcs", 328 "-ftest-coverage", 329 "--coverage", 330 ] 331 if (is_test) { 332 cflags += [ "-D IS_UT" ] 333 } 334 } 335} 336