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_stream_extend) { 112 defines += [ "ENABLE_STREAM_EXTEND" ] 113 } 114 if (is_debug && is_win) { 115 ldflags += [ "-fstack-protector" ] 116 } 117 if (is_debug && !use_wasm) { 118 cflags += [ "-g" ] 119 if (is_linux) { 120 cflags += [ 121 "-fno-omit-frame-pointer", 122 "-fstandalone-debug", 123 ] 124 ldflags += [ "-fsanitize=address" ] 125 } 126 } 127 128 if (target_os == "windows") { 129 cflags += [ "-D target_cpu_x86_64" ] 130 } else if (is_linux || is_mac) { 131 cflags += [ 132 "-Wa,--noexecstack", 133 "-fcolor-diagnostics", 134 "-fdiagnostics-show-template-tree", 135 "-ftrapv", 136 ] 137 if (!use_wasm) { 138 cflags += [ 139 "-fstack-protector-strong", 140 "-fstack-protector-all", 141 "-D_FORTIFY_SOURCE=2 -O2", 142 "-D target_cpu_x64", 143 "-D target_cpu_x86_64", 144 "-DHAVE_CONFIG_H", 145 "-DCC_IS_CLANG", 146 ] 147 } 148 if (!use_wasm && !is_win && !is_mac && !is_test && !is_mingw) { 149 cflags += [ "-D HAVE_LIBUNWIND" ] 150 } 151 if (use_wasm) { 152 cflags += [ 153 "-D IS_WASM", 154 "-D GOOGLE_PROTOBUF_NO_RDTSC", 155 "-D target_cpu_x64", 156 "-D target_cpu_x86_64", 157 "-DHAVE_CONFIG_H", 158 "-DCC_IS_CLANG", 159 "-D__x86_64__", 160 ] 161 } 162 cflags += [ "-D BINDER_ASYNC" ] 163 libs += [ "pthread" ] 164 if (!is_mac) { 165 libs += [ "rt" ] 166 } 167 if (!is_win) { 168 cflags += [ 169 "-fPIE", 170 "-fPIC", 171 ] 172 } 173 } 174 if (use_wasm) { 175 cflags += [ "-D IS_WASM" ] 176 if (wasm_use_thread) { 177 cflags += [ 178 "-D SUPPORTTHREAD", 179 "-mbulk-memory", 180 "-matomics", 181 ] 182 } 183 } 184 if (!use_wasm) { 185 cflags += [ "-D SUPPORTTHREAD" ] 186 } 187 if (is_win) { 188 cflags += [ "-D is_mingw" ] 189 defines += [ "WIN32_LEAN_AND_MEAN" ] 190 libs += [ "wsock32" ] 191 libs += [ "ws2_32" ] 192 cflags += [ "-Wno-attributes" ] 193 } 194 if (is_linux) { 195 cflags += [ "-D is_linux" ] 196 } 197 if (is_mac) { 198 cflags += [ "-D is_mac" ] 199 } 200} 201 202config("symbols") { 203 cflags = [ "-O3" ] 204 cflags += [ 205 "-fdata-sections", 206 "-ffunction-sections", 207 ] 208 if (is_linux || is_mac) { 209 cflags += [ "-funwind-tables" ] 210 } 211} 212 213config("release") { 214 cflags = [ 215 "-fdata-sections", 216 "-ffunction-sections", 217 ] 218 cflags += [ "-O3" ] 219 ldflags = [ "-fstack-protector" ] 220 if (!is_mac) { 221 ldflags += [ "-Wl,-O3" ] 222 if (!is_win) { 223 ldflags += [ 224 "-fuse-ld=gold", 225 "-Wl,--gc-sections", 226 ] 227 } 228 } 229 230 if (!is_win && !is_mac) { 231 ldflags += [ 232 "-fPIC", 233 "-fpie", 234 "-pie", 235 ] 236 } 237} 238 239config("shared_library") { 240 if (!is_win) { 241 ldflags = [ "-fPIC" ] 242 } 243} 244 245config("executable") { 246 print("use_wasm", use_wasm) 247 ldflags = [] 248 249 if (is_linux || (is_mac && !use_wasm)) { 250 ldflags += [] 251 } 252 if (!is_mac && !use_wasm && !is_win) { 253 ldflags += [ 254 "-Wl,--disable-new-dtags", 255 "-Wl,-z,noexecstack", 256 "-lrt", 257 "-fuse-ld=gold", 258 "-Wl,-z,now", 259 "-Wl,-z,relro", 260 ] 261 } 262 if (!is_mac && !use_wasm) { 263 ldflags += [ "-fpie" ] 264 } 265 if (!is_mac && !use_wasm && !is_win) { 266 ldflags += [ "-pie" ] 267 } 268 if (!is_mac) { 269 ldflags += [ "-Wl,--gc-sections" ] 270 } 271 if (is_mac) { 272 ldflags += [ 273 "-fdata-sections", 274 "-ffunction-sections", 275 ] 276 if (!use_wasm) { 277 ldflags += [ "-Wl,-U,__sanitizer_options_link_helper" ] 278 } 279 } 280 if (!is_debug && !is_mac) { 281 ldflags += [ "-s" ] 282 } else if (!is_debug && is_mac) { 283 ldflags += [ "-dead_strip" ] 284 } 285} 286 287config("ts_config") { 288 ldflags = [] 289 cflags = [ 290 "-D target_cpu_${target_cpu}", 291 "-std=c++17", 292 ] 293 cflags += [ "-D __LITTLE_ENDIAN_BITFIELD" ] 294 295 if (is_mingw) { 296 cflags += [ "-ffunction-sections" ] 297 cflags += [ "-D is_mingw=1" ] 298 cflags += [ "-Wno-inconsistent-dllimport" ] 299 defines = [ "WIN32_LEAN_AND_MEAN" ] 300 ldflags += [ 301 "-Wl,--whole-archive", 302 "-lpthread", 303 "-Wl,--no-whole-archive", 304 ] 305 306 libs = [ "wsock32" ] 307 libs += [ "ws2_32" ] 308 } 309 if (is_linux) { 310 cflags += [ "-D is_linux=1" ] 311 } 312 if (!use_wasm && !is_win && !is_mac && !is_test && !is_mingw) { 313 cflags += [ "-D HAVE_LIBUNWIND" ] 314 } 315 if (enable_ts_utest && !use_wasm) { 316 cflags += [ 317 "-fprofile-arcs", 318 "-ftest-coverage", 319 ] 320 ldflags += [ 321 "-fprofile-arcs", 322 "-ftest-coverage", 323 "--coverage", 324 ] 325 if (is_test) { 326 cflags += [ "-D IS_UT" ] 327 } 328 } 329} 330