# Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import("../build/ts.gni") print("target_os", target_os) group("default_deps") { public_configs = [ ":default_config" ] public_deps = [] } config("default_config") { include_dirs = [ "..", "../include", ] } config("trace_cfg") { cflags_cc = [ "-std=c++17", "-fvisibility=hidden", "-Wno-unused-variable", ] if (!is_test) { cflags_cc += [ "-fno-rtti", "-fno-exceptions", ] } } config("hiperf_trace_cfg") { cflags_cc = [ "-std=c++17", "-fvisibility=hidden", "-Wno-unused-variable", ] } config("visibility_hidden") { cflags = [ "-fvisibility=hidden" ] } config("default") { cflags_c = [] cflags_cc = [] defines = [] libs = [] ldflags = [] cflags = [ "-fstrict-aliasing", "-Wformat", "-Wno-unused-variable", ] if (enable_hiperf) { defines += [ "ENABLE_HIPERF" ] } if (enable_ebpf) { defines += [ "ENABLE_EBPF" ] } if (enable_native_hook) { defines += [ "ENABLE_NATIVE_HOOK" ] } if (enable_hilog) { defines += [ "ENABLE_HILOG" ] } if (enable_hisysevent) { defines += [ "ENABLE_HISYSEVENT" ] } if (enable_arkts) { defines += [ "ENABLE_ARKTS" ] } if (enable_bytrace) { defines += [ "ENABLE_BYTRACE" ] } if (enable_rawtrace) { defines += [ "ENABLE_RAWTRACE" ] } if (enable_ffrt) { defines += [ "ENABLE_FFRT" ] enable_htrace = true } if (enable_htrace) { defines += [ "ENABLE_HTRACE" ] } if (enable_memory) { defines += [ "ENABLE_MEMORY" ] } if (enable_hidump) { defines += [ "ENABLE_HTDUMP" ] } if (enable_cpudata) { defines += [ "ENABLE_CPUDATA" ] } if (enable_network) { defines += [ "ENABLE_NETWORK" ] } if (enable_diskio) { defines += [ "ENABLE_DISKIO" ] } if (enable_process) { defines += [ "ENABLE_PROCESS" ] } if (enable_stream_extend) { defines += [ "ENABLE_STREAM_EXTEND" ] } if (is_debug && is_win) { ldflags += [ "-fstack-protector" ] } if (is_debug && !use_wasm) { cflags += [ "-g" ] if (is_linux) { cflags += [ "-fno-omit-frame-pointer", "-fstandalone-debug", ] ldflags += [ "-fsanitize=address" ] } } if (target_os == "windows") { cflags += [ "-D target_cpu_x86_64" ] } else if (is_linux || is_mac) { cflags += [ "-Wa,--noexecstack", "-fcolor-diagnostics", "-fdiagnostics-show-template-tree", "-ftrapv", ] if (!use_wasm) { cflags += [ "-fstack-protector-strong", "-fstack-protector-all", "-D_FORTIFY_SOURCE=2 -O2", "-D target_cpu_x64", "-D target_cpu_x86_64", "-DHAVE_CONFIG_H", "-DCC_IS_CLANG", ] } if (!use_wasm && !is_win && !is_mac && !is_test && !is_mingw) { cflags += [ "-D HAVE_LIBUNWIND" ] } if (use_wasm) { cflags += [ "-D IS_WASM", "-D GOOGLE_PROTOBUF_NO_RDTSC", "-D target_cpu_x64", "-D target_cpu_x86_64", "-DHAVE_CONFIG_H", "-DCC_IS_CLANG", "-D__x86_64__", ] } cflags += [ "-D BINDER_ASYNC" ] libs += [ "pthread" ] if (!is_mac) { libs += [ "rt" ] } if (!is_win) { cflags += [ "-fPIE", "-fPIC", ] } } if (use_wasm) { cflags += [ "-D IS_WASM" ] if (wasm_use_thread) { cflags += [ "-D SUPPORTTHREAD", "-mbulk-memory", "-matomics", ] } } if (!use_wasm) { cflags += [ "-D SUPPORTTHREAD" ] } if (is_win) { cflags += [ "-D is_mingw" ] defines += [ "WIN32_LEAN_AND_MEAN" ] libs += [ "wsock32" ] libs += [ "ws2_32" ] cflags += [ "-Wno-attributes" ] } if (is_linux) { cflags += [ "-D is_linux" ] } if (is_mac) { cflags += [ "-D is_mac" ] } } config("symbols") { cflags = [ "-O3" ] cflags += [ "-fdata-sections", "-ffunction-sections", ] if (is_linux || is_mac) { cflags += [ "-funwind-tables" ] } } config("release") { cflags = [ "-fdata-sections", "-ffunction-sections", ] cflags += [ "-O3" ] ldflags = [ "-fstack-protector" ] if (!is_mac) { ldflags += [ "-Wl,-O3" ] if (!is_win) { ldflags += [ "-fuse-ld=gold", "-Wl,--gc-sections", ] } } if (!is_win && !is_mac) { ldflags += [ "-fPIC", "-fpie", "-pie", ] } } config("shared_library") { if (!is_win) { ldflags = [ "-fPIC" ] } } config("executable") { print("use_wasm", use_wasm) ldflags = [] if (is_linux || (is_mac && !use_wasm)) { ldflags += [] } if (!is_mac && !use_wasm && !is_win) { ldflags += [ "-Wl,--disable-new-dtags", "-Wl,-z,noexecstack", "-lrt", "-fuse-ld=gold", "-Wl,-z,now", "-Wl,-z,relro", ] } if (!is_mac && !use_wasm) { ldflags += [ "-fpie" ] } if (!is_mac && !use_wasm && !is_win) { ldflags += [ "-pie" ] } if (!is_mac) { ldflags += [ "-Wl,--gc-sections" ] } if (is_mac) { ldflags += [ "-fdata-sections", "-ffunction-sections", ] if (!use_wasm) { ldflags += [ "-Wl,-U,__sanitizer_options_link_helper" ] } } if (!is_debug && !is_mac) { ldflags += [ "-s" ] } else if (!is_debug && is_mac) { ldflags += [ "-dead_strip" ] } } config("ts_config") { ldflags = [] cflags = [ "-D target_cpu_${target_cpu}", "-std=c++17", ] cflags += [ "-D __LITTLE_ENDIAN_BITFIELD" ] if (is_mingw) { cflags += [ "-ffunction-sections" ] cflags += [ "-D is_mingw=1" ] cflags += [ "-Wno-inconsistent-dllimport" ] defines = [ "WIN32_LEAN_AND_MEAN" ] ldflags += [ "-Wl,--whole-archive", "-lpthread", "-Wl,--no-whole-archive", ] libs = [ "wsock32" ] libs += [ "ws2_32" ] } if (is_linux) { cflags += [ "-D is_linux=1" ] } if (!use_wasm && !is_win && !is_mac && !is_test && !is_mingw) { cflags += [ "-D HAVE_LIBUNWIND" ] } if (enable_ts_utest && !use_wasm) { cflags += [ "-fprofile-arcs", "-ftest-coverage", ] ldflags += [ "-fprofile-arcs", "-ftest-coverage", "--coverage", ] if (is_test) { cflags += [ "-D IS_UT" ] } } }