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 ldflags = [] 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 (is_debug && is_linux && !use_wasm) { 67 cflags += [ 68 "-fsanitize=address", 69 "-fno-omit-frame-pointer", 70 ] 71 ldflags += [ "-fsanitize=address" ] 72 } 73 if (target_os == "windows") { 74 cflags += [ "-D target_cpu_x86_64" ] 75 libs += [ "z" ] 76 } else if (is_linux || is_macx) { 77 cflags += [ 78 "-Wa,--noexecstack", 79 "-fcolor-diagnostics", 80 "-fdiagnostics-show-template-tree", 81 "-ftrapv", 82 ] 83 if (!use_wasm) { 84 cflags += [ 85 "-fstack-protector-strong", 86 "-fstack-protector-all", 87 "-D_FORTIFY_SOURCE=2 -O2", 88 89 # "-D SUPPORTTHREAD", # if support thread 90 91 # "-D HAVE_ELF_H", 92 "-D target_cpu_x64", 93 "-D target_cpu_x86_64", 94 95 # "-D HAVE_LINK_H", 96 # "-D_GNU_SOURCE", 97 "-DHAVE_CONFIG_H", 98 "-DCC_IS_CLANG", 99 ] 100 libs += [ "z" ] 101 102 # with_libunwind = true 103 } 104 if (!use_wasm && !is_win && !is_macx && !is_test && !is_mingw) { 105 cflags += [ "-D HAVE_LIBUNWIND" ] 106 } 107 108 cflags += [ "-D USE_VTABLE" ] 109 if (use_wasm) { 110 cflags += [ 111 "-D IS_WASM", 112 "-D GOOGLE_PROTOBUF_NO_RDTSC", 113 114 # "-D HAVE_LIBUNWIND", 115 "-D target_cpu_x64", 116 "-D target_cpu_x86_64", 117 "-DHAVE_CONFIG_H", 118 "-DNDEBUG", 119 "-DCC_IS_CLANG", 120 "-D__x86_64__", 121 ] 122 } 123 cflags += [ "-D BINDER_ASYNC" ] 124 libs += [ "pthread" ] 125 if (!is_macx) { 126 libs += [ "rt" ] 127 } 128 if (!is_win) { 129 cflags += [ 130 "-fPIE", 131 "-fPIC", 132 ] 133 } 134 } 135 if (use_wasm) { 136 cflags += [ "-D IS_WASM" ] 137 } 138 if (is_win) { 139 cflags += [ "-D is_mingw" ] 140 defines = [ "WIN32_LEAN_AND_MEAN" ] 141 libs += [ "wsock32" ] 142 libs += [ "ws2_32" ] 143 cflags += [ "-Wno-attributes" ] 144 } 145 if (with_ebpf_help_table) { 146 cflags += [ "-D WITH_EBPF_HELP" ] 147 } 148} 149 150config("symbols") { 151 cflags = [ "-O0" ] 152 if (is_linux || is_macx) { 153 cflags += [ "-funwind-tables" ] 154 } 155} 156 157config("release") { 158 cflags = [ 159 "-fdata-sections", 160 "-ffunction-sections", 161 ] 162 163 cflags += [ "-O3" ] 164 ldflags = [ "-fstack-protector" ] 165 if (!is_macx) { 166 ldflags += [ "-Wl,-O1" ] 167 if (!is_win) { 168 ldflags += [ 169 "-fuse-ld=gold", 170 "-Wl,--gc-sections", 171 ] 172 } 173 } 174 175 if (!is_win && !is_macx) { 176 ldflags += [ 177 "-fPIC", 178 "-fpie", 179 "-pie", 180 ] 181 } 182 defines = [ "NDEBUG" ] 183} 184 185config("shared_library") { 186 if (!is_win) { 187 ldflags = [ "-fPIC" ] 188 } 189} 190 191config("executable") { 192 print("use_wasm", use_wasm) 193 ldflags = [] 194 195 if (is_linux || (is_macx && !use_wasm)) { 196 ldflags += [] 197 } 198 if (!is_macx && !use_wasm && !is_win) { 199 ldflags += [ 200 "-Wl,--disable-new-dtags", 201 "-Wl,-z,noexecstack", 202 "-lrt", 203 "-fuse-ld=gold", 204 "-Wl,-z,now", 205 "-Wl,-z,relro", 206 ] 207 } 208 if (!is_macx && !use_wasm) { 209 ldflags += [ "-fpie" ] 210 } 211 if (!is_macx && !use_wasm && !is_win) { 212 ldflags += [ "-pie" ] 213 } 214 if (!is_macx) { 215 ldflags += [ "-Wl,--gc-sections" ] 216 } 217 if (is_macx) { 218 ldflags += [ 219 "-fdata-sections", 220 "-ffunction-sections", 221 ] 222 if (!use_wasm) { 223 ldflags += [ "-Wl,-U,__sanitizer_options_link_helper" ] 224 } 225 } 226 if (!is_debug && !is_macx) { 227 ldflags += [ "-s" ] 228 } else if (!is_debug && is_macx) { 229 ldflags += [ "-dead_strip" ] 230 } 231} 232 233config("ts_config") { 234 ldflags = [] 235 cflags = [ 236 "-D target_cpu_${target_cpu}", 237 "-std=c++17", 238 ] 239 cflags += [ "-D __LITTLE_ENDIAN_BITFIELD" ] 240 241 if (is_mingw) { 242 cflags += [ "-ffunction-sections" ] 243 cflags += [ "-D is_mingw=1" ] 244 cflags += [ "-Wno-inconsistent-dllimport" ] 245 defines = [ "WIN32_LEAN_AND_MEAN" ] 246 ldflags += [ 247 "-Wl,--whole-archive", 248 "-lpthread", 249 "-Wl,--no-whole-archive", 250 ] 251 252 libs = [ "wsock32" ] 253 libs += [ "ws2_32" ] 254 } 255 if (!use_wasm && !is_win && !is_macx && !is_test && !is_mingw) { 256 cflags += [ "-D HAVE_LIBUNWIND" ] 257 } 258 if (enable_ts_utest && !use_wasm) { 259 cflags += [ 260 "-fprofile-arcs", 261 "-ftest-coverage", 262 ] 263 ldflags += [ 264 "-fprofile-arcs", 265 "-ftest-coverage", 266 "--coverage", 267 ] 268 if (is_test) { 269 cflags += [ "-D IS_UT" ] 270 } 271 } 272} 273