# Copyright (C) 2021 Huawei Device Co., Ltd. # 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) print("target_name", target) 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 = [] libs = [] ldflags = [] cflags = [ "-fstrict-aliasing", "-g", "-Wformat", "-Wno-unused-variable", ] if (is_debug && is_win) { ldflags += [ "-fstack-protector" ] } if (is_debug && is_linux && !use_wasm) { cflags += [ "-fsanitize=address", "-fno-omit-frame-pointer", ] ldflags += [ "-fsanitize=address" ] } if (target_os == "windows") { cflags += [ "-D target_cpu_x86_64" ] libs += [ "z" ] } else if (is_linux || is_macx) { 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 SUPPORTTHREAD", # if support thread # "-D HAVE_ELF_H", "-D target_cpu_x64", "-D target_cpu_x86_64", # "-D HAVE_LINK_H", # "-D_GNU_SOURCE", "-DHAVE_CONFIG_H", "-DCC_IS_CLANG", ] libs += [ "z" ] # with_libunwind = true } if (!use_wasm && !is_win && !is_macx && !is_test && !is_mingw) { cflags += [ "-D HAVE_LIBUNWIND" ] } cflags += [ "-D USE_VTABLE" ] if (use_wasm) { cflags += [ "-D IS_WASM", "-D GOOGLE_PROTOBUF_NO_RDTSC", # "-D HAVE_LIBUNWIND", "-D target_cpu_x64", "-D target_cpu_x86_64", "-DHAVE_CONFIG_H", "-DNDEBUG", "-DCC_IS_CLANG", "-D__x86_64__", ] } cflags += [ "-D BINDER_ASYNC" ] libs += [ "pthread" ] if (!is_macx) { libs += [ "rt" ] } if (!is_win) { cflags += [ "-fPIE", "-fPIC", ] } } if (use_wasm) { cflags += [ "-D IS_WASM" ] } if (is_win) { cflags += [ "-D is_mingw" ] defines = [ "WIN32_LEAN_AND_MEAN" ] libs += [ "wsock32" ] libs += [ "ws2_32" ] cflags += [ "-Wno-attributes" ] } if (with_ebpf_help_table) { cflags += [ "-D WITH_EBPF_HELP" ] } } config("symbols") { cflags = [ "-O0" ] if (is_linux || is_macx) { cflags += [ "-funwind-tables" ] } } config("release") { cflags = [ "-fdata-sections", "-ffunction-sections", ] cflags += [ "-O3" ] ldflags = [ "-fstack-protector" ] if (!is_macx) { ldflags += [ "-Wl,-O1" ] if (!is_win) { ldflags += [ "-fuse-ld=gold", "-Wl,--gc-sections", ] } } if (!is_win && !is_macx) { ldflags += [ "-fPIC", "-fpie", "-pie", ] } defines = [ "NDEBUG" ] } config("shared_library") { if (!is_win) { ldflags = [ "-fPIC" ] } } config("executable") { print("use_wasm", use_wasm) ldflags = [] if (is_linux || (is_macx && !use_wasm)) { ldflags += [] } if (!is_macx && !use_wasm && !is_win) { ldflags += [ "-Wl,--disable-new-dtags", "-Wl,-z,noexecstack", "-lrt", "-fuse-ld=gold", "-Wl,-z,now", "-Wl,-z,relro", ] } if (!is_macx && !use_wasm) { ldflags += [ "-fpie" ] } if (!is_macx && !use_wasm && !is_win) { ldflags += [ "-pie" ] } if (!is_macx) { ldflags += [ "-Wl,--gc-sections" ] } if (is_macx) { ldflags += [ "-fdata-sections", "-ffunction-sections", ] if (!use_wasm) { ldflags += [ "-Wl,-U,__sanitizer_options_link_helper" ] } } if (!is_debug && !is_macx) { ldflags += [ "-s" ] } else if (!is_debug && is_macx) { 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 (!use_wasm && !is_win && !is_macx && !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" ] } } }