15f9996aaSopenharmony_ci# Copyright 2015 The Chromium Authors. All rights reserved. 25f9996aaSopenharmony_ci# Use of this source code is governed by a BSD-style license that can be 35f9996aaSopenharmony_ci# found in the LICENSE file. 45f9996aaSopenharmony_ci 55f9996aaSopenharmony_ciimport("//build/config/c++/c++.gni") 65f9996aaSopenharmony_ciimport("//build/config/clang/clang.gni") 75f9996aaSopenharmony_ciimport("//build/config/compiler/compiler.gni") 85f9996aaSopenharmony_ciimport("//build/config/deps_revisions.gni") 95f9996aaSopenharmony_ciimport("//build/config/sanitizers/sanitizers.gni") 105f9996aaSopenharmony_ciimport("//build/config/sysroot.gni") 115f9996aaSopenharmony_ciimport("//build/toolchain/toolchain.gni") 125f9996aaSopenharmony_ci 135f9996aaSopenharmony_ciassert(is_posix) 145f9996aaSopenharmony_ci 155f9996aaSopenharmony_cigroup("posix") { 165f9996aaSopenharmony_ci visibility = [ "//:optimize_gn_gen" ] 175f9996aaSopenharmony_ci} 185f9996aaSopenharmony_ci 195f9996aaSopenharmony_ci# This is included by reference in the //build/config/compiler:runtime_library 205f9996aaSopenharmony_ci# config that is applied to all targets. It is here to separate out the logic 215f9996aaSopenharmony_ci# that is Posix-only. Please see that target for advice on what should go in 225f9996aaSopenharmony_ci# :runtime_library vs. :compiler. 235f9996aaSopenharmony_ciconfig("runtime_library") { 245f9996aaSopenharmony_ci asmflags = [] 255f9996aaSopenharmony_ci cflags = [] 265f9996aaSopenharmony_ci cflags_c = [] 275f9996aaSopenharmony_ci cflags_cc = [] 285f9996aaSopenharmony_ci cflags_objc = [] 295f9996aaSopenharmony_ci cflags_objcc = [] 305f9996aaSopenharmony_ci defines = [] 315f9996aaSopenharmony_ci ldflags = [] 325f9996aaSopenharmony_ci lib_dirs = [] 335f9996aaSopenharmony_ci libs = [] 345f9996aaSopenharmony_ci 355f9996aaSopenharmony_ci if (use_custom_libcxx) { 365f9996aaSopenharmony_ci if (!is_component_build) { 375f9996aaSopenharmony_ci # Don't leak any symbols on a static build. 385f9996aaSopenharmony_ci defines += [ "_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS" ] 395f9996aaSopenharmony_ci if (!export_libcxxabi_from_executables) { 405f9996aaSopenharmony_ci defines += [ "_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS" ] 415f9996aaSopenharmony_ci } 425f9996aaSopenharmony_ci } 435f9996aaSopenharmony_ci cflags_cc += [ 445f9996aaSopenharmony_ci "-nostdinc++", 455f9996aaSopenharmony_ci "-isystem" + rebase_path("$libcxx_prefix/include", root_build_dir), 465f9996aaSopenharmony_ci "-isystem" + rebase_path("$libcxxabi_prefix/include", root_build_dir), 475f9996aaSopenharmony_ci ] 485f9996aaSopenharmony_ci defines += [ 495f9996aaSopenharmony_ci "CR_LIBCXX_REVISION=$libcxx_svn_revision", 505f9996aaSopenharmony_ci "CR_LIBCXXABI_REVISION=$libcxxabi_svn_revision", 515f9996aaSopenharmony_ci "_LIBCPP_ENABLE_NODISCARD", 525f9996aaSopenharmony_ci ] 535f9996aaSopenharmony_ci 545f9996aaSopenharmony_ci # Make sure we don't link against libc++ or libstdc++. 555f9996aaSopenharmony_ci if (is_clang) { 565f9996aaSopenharmony_ci # //build/config/ohos:runtime_library adds -nostdlib, which suppresses 575f9996aaSopenharmony_ci # linking against all system libraries. -nostdlib++ would be redundant, 585f9996aaSopenharmony_ci # and would generate an unused warning in this case. 595f9996aaSopenharmony_ci if (!is_ohos) { 605f9996aaSopenharmony_ci ldflags += [ "-nostdlib++" ] 615f9996aaSopenharmony_ci } 625f9996aaSopenharmony_ci } else { 635f9996aaSopenharmony_ci # Gcc has a built-in abs() definition with default visibility. 645f9996aaSopenharmony_ci # If it was not disabled, it would conflict with libc++'s abs() 655f9996aaSopenharmony_ci # with hidden visibility. 665f9996aaSopenharmony_ci cflags += [ "-fno-builtin-abs" ] 675f9996aaSopenharmony_ci 685f9996aaSopenharmony_ci ldflags += [ "-nodefaultlibs" ] 695f9996aaSopenharmony_ci 705f9996aaSopenharmony_ci # Unfortunately, there's no way to disable linking against just libc++ 715f9996aaSopenharmony_ci # (gcc doesn't have -notstdlib++: 725f9996aaSopenharmony_ci # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83931); -nodefaultlibs 735f9996aaSopenharmony_ci # removes all of the default libraries, so add back the ones that we need. 745f9996aaSopenharmony_ci libs += [ 755f9996aaSopenharmony_ci "c", 765f9996aaSopenharmony_ci "gcc_s", 775f9996aaSopenharmony_ci "m", 785f9996aaSopenharmony_ci "rt", 795f9996aaSopenharmony_ci ] 805f9996aaSopenharmony_ci } 815f9996aaSopenharmony_ci } 825f9996aaSopenharmony_ci 835f9996aaSopenharmony_ci if (!is_mac && sysroot != "") { 845f9996aaSopenharmony_ci # Pass the sysroot to all C compiler variants, the assembler, and linker. 855f9996aaSopenharmony_ci sysroot_flags = [ "--sysroot=" + rebase_path(sysroot, root_build_dir) ] 865f9996aaSopenharmony_ci if (is_linux) { 875f9996aaSopenharmony_ci # This is here so that all files get recompiled after a sysroot roll and 885f9996aaSopenharmony_ci # when turning the sysroot on or off. (defines are passed via the command 895f9996aaSopenharmony_ci # line, and build system rebuilds things when their commandline 905f9996aaSopenharmony_ci # changes). Nothing should ever read this define. 915f9996aaSopenharmony_ci sysroot_hash = 925f9996aaSopenharmony_ci exec_script("//build/linux/sysroot_scripts/install-sysroot.py", 935f9996aaSopenharmony_ci [ "--print-hash=$current_cpu" ], 945f9996aaSopenharmony_ci "trim string", 955f9996aaSopenharmony_ci [ "//build/linux/sysroot_scripts/sysroots.json" ]) 965f9996aaSopenharmony_ci defines += [ "CR_SYSROOT_HASH=$sysroot_hash" ] 975f9996aaSopenharmony_ci } 985f9996aaSopenharmony_ci asmflags += sysroot_flags 995f9996aaSopenharmony_ci 1005f9996aaSopenharmony_ci link_sysroot_flags = 1015f9996aaSopenharmony_ci [ "--sysroot=" + rebase_path(link_sysroot, root_build_dir) ] 1025f9996aaSopenharmony_ci ldflags += link_sysroot_flags 1035f9996aaSopenharmony_ci 1045f9996aaSopenharmony_ci # When use_custom_libcxx=true, some -isystem flags get passed to 1055f9996aaSopenharmony_ci # cflags_cc to set up libc++ include paths. We want to make sure 1065f9996aaSopenharmony_ci # the sysroot includes take lower precedence than the libc++ 1075f9996aaSopenharmony_ci # ones, so they must appear later in the command line. However, 1085f9996aaSopenharmony_ci # the gn reference states "These variant-specific versions of 1095f9996aaSopenharmony_ci # cflags* will be appended on the compiler command line after 1105f9996aaSopenharmony_ci # 'cflags'." Because of this, we must set the sysroot flags for 1115f9996aaSopenharmony_ci # all cflags variants instead of using 'cflags' directly. 1125f9996aaSopenharmony_ci cflags_c += sysroot_flags 1135f9996aaSopenharmony_ci cflags_cc += sysroot_flags 1145f9996aaSopenharmony_ci cflags_objc += sysroot_flags 1155f9996aaSopenharmony_ci cflags_objcc += sysroot_flags 1165f9996aaSopenharmony_ci 1175f9996aaSopenharmony_ci # Need to get some linker flags out of the sysroot. 1185f9996aaSopenharmony_ci ld_paths = 1195f9996aaSopenharmony_ci exec_script("sysroot_ld_path.py", 1205f9996aaSopenharmony_ci [ 1215f9996aaSopenharmony_ci rebase_path("//build/misc/linux/sysroot_ld_path.sh", 1225f9996aaSopenharmony_ci root_build_dir), 1235f9996aaSopenharmony_ci rebase_path(link_sysroot), 1245f9996aaSopenharmony_ci ], 1255f9996aaSopenharmony_ci "list lines") 1265f9996aaSopenharmony_ci foreach(ld_path, ld_paths) { 1275f9996aaSopenharmony_ci ld_path = rebase_path(ld_path, root_build_dir) 1285f9996aaSopenharmony_ci ldflags += [ 1295f9996aaSopenharmony_ci "-L" + ld_path, 1305f9996aaSopenharmony_ci "-Wl,-rpath-link=" + ld_path, 1315f9996aaSopenharmony_ci ] 1325f9996aaSopenharmony_ci } 1335f9996aaSopenharmony_ci } 1345f9996aaSopenharmony_ci} 135