1# Copyright 2013 The Chromium Authors 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import("//build/config/apple/symbols.gni") 6import("//build/config/c++/c++.gni") 7import("//build/config/mac/mac_sdk.gni") 8import("//build/config/sysroot.gni") 9import("//build/toolchain/goma.gni") 10import("//build/toolchain/rbe.gni") 11 12# This is included by reference in the //build/config/compiler config that 13# is applied to all targets. It is here to separate out the logic. 14config("compiler") { 15 # These flags are shared between the C compiler and linker. 16 common_mac_flags = [] 17 18 # CPU architecture. 19 if (current_cpu == "x64") { 20 clang_arch = "x86_64" 21 } else if (current_cpu == "x86") { 22 clang_arch = "i386" 23 } else if (current_cpu == "arm64") { 24 clang_arch = current_cpu 25 } else { 26 assert(false, "unknown current_cpu $current_cpu") 27 } 28 if (host_os == "mac") { 29 common_mac_flags += [ 30 "-arch", 31 clang_arch, 32 ] 33 } else { 34 common_mac_flags += [ "--target=$clang_arch-apple-macos" ] 35 } 36 37 # This is here so that all files get recompiled after an Xcode update. 38 # (defines are passed via the command line, and build system rebuild things 39 # when their commandline changes). Nothing should ever read this define. 40 defines = [ "CR_XCODE_VERSION=$xcode_version" ] 41 42 asmflags = common_mac_flags 43 cflags = common_mac_flags 44 45 # Without this, the constructors and destructors of a C++ object inside 46 # an Objective C struct won't be called, which is very bad. 47 cflags_objcc = [ "-fobjc-call-cxx-cdtors" ] 48 49 ldflags = common_mac_flags 50 51 if (save_unstripped_output) { 52 ldflags += [ "-Wcrl,unstripped," + rebase_path(root_out_dir) ] 53 } 54 55 if (export_libcxxabi_from_executables) { 56 ldflags += [ "-Wl,-undefined,dynamic_lookup" ] 57 } 58} 59 60# This is included by reference in the //build/config/compiler:runtime_library 61# config that is applied to all targets. It is here to separate out the logic 62# that is Mac-only. Please see that target for advice on what should go in 63# :runtime_library vs. :compiler. 64config("runtime_library") { 65 common_flags = [ 66 "-isysroot", 67 rebase_path(sysroot, root_build_dir), 68 "-mmacos-version-min=$mac_deployment_target", 69 ] 70 71 asmflags = common_flags 72 cflags = common_flags 73 ldflags = common_flags 74} 75 76# On Mac, this is used for everything except static libraries. 77config("mac_dynamic_flags") { 78 ldflags = [ "-Wl,-ObjC" ] # Always load Objective-C categories and classes. 79 80 if (is_component_build) { 81 ldflags += [ 82 # Path for loading shared libraries for unbundled binaries. 83 "-Wl,-rpath,@loader_path/.", 84 85 # Path for loading shared libraries for bundled binaries. Get back from 86 # Binary.app/Contents/MacOS. 87 "-Wl,-rpath,@loader_path/../../..", 88 ] 89 90 # Path for loading shared libraries for unbundled binaries for 91 # the host toolchain (see https://crbug.com/1315433). Only used 92 # for when building for iOS. 93 if (target_os == "ios" && current_toolchain == host_toolchain) { 94 ldflags += [ "-Wl,-rpath,@loader_path/" + rebase_path( 95 get_label_info(":mac_dynamic_flags", "root_out_dir"), 96 root_build_dir) ] 97 } 98 } 99} 100 101# When building with Goma, all inputs must be relative to the build directory. 102# If using the system Xcode, which typically resides outside the build root, a 103# symlink to the SDK is created in the build directory, and the path to that 104# link is stored in $mac_sdk_path. If an action references a file in the SDK as 105# an input, GN will complain that no target generates the file because it is 106# below the $root_build_dir. The below action lists as outputs the files in the 107# SDK that are referenced as inputs to actions, so that GN thinks a target has 108# generated them. The list is centralized here, as multiple targets need to 109# reference the same files, and an output can only be generated once. 110# 111# The symbolic link for $mac_sdk_path is set up by 112# //build/config/apple/sdk_info.py in //build/config/mac/mac_sdk.gni. 113if (use_system_xcode && (use_goma || use_remoteexec) && target_os == "mac" && 114 current_toolchain == default_toolchain) { 115 action("sdk_inputs") { 116 script = "//build/noop.py" 117 outputs = [ 118 "$mac_sdk_path/usr/include/mach/exc.defs", 119 "$mac_sdk_path/usr/include/mach/mach_exc.defs", 120 "$mac_sdk_path/usr/include/mach/notify.defs", 121 ] 122 } 123} else { 124 group("sdk_inputs") { 125 if (current_toolchain != default_toolchain) { 126 public_deps = [ ":sdk_inputs($default_toolchain)" ] 127 } 128 } 129} 130