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/rbe.gni") 10import("//build/toolchain/siso.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 common_mac_flags += [ "--target=$clang_arch-apple-macos" ] 29 30 # This is here so that all files get recompiled after an Xcode update. 31 # (defines are passed via the command line, and build system rebuild things 32 # when their commandline changes). Nothing should ever read this define. 33 defines = [ "CR_XCODE_VERSION=$xcode_version" ] 34 35 asmflags = common_mac_flags 36 cflags = common_mac_flags 37 38 ldflags = common_mac_flags 39 40 if (save_unstripped_output) { 41 ldflags += [ "-Wcrl,unstripped," + rebase_path(root_out_dir) ] 42 } 43 44 if (export_libcxxabi_from_executables) { 45 ldflags += [ "-Wl,-undefined,dynamic_lookup" ] 46 } 47} 48 49# This is included by reference in the //build/config/compiler:runtime_library 50# config that is applied to all targets. It is here to separate out the logic 51# that is Mac-only. Please see that target for advice on what should go in 52# :runtime_library vs. :compiler. 53config("runtime_library") { 54 common_flags = [ 55 "-isysroot", 56 rebase_path(sysroot, root_build_dir), 57 "-mmacos-version-min=$mac_deployment_target", 58 ] 59 60 asmflags = common_flags 61 cflags = common_flags 62 ldflags = common_flags 63} 64 65# On Mac, this is used for everything except static libraries. 66config("mac_dynamic_flags") { 67 ldflags = [ "-Wl,-ObjC" ] # Always load Objective-C categories and classes. 68 69 if (is_component_build) { 70 ldflags += [ 71 # Path for loading shared libraries for unbundled binaries. 72 "-Wl,-rpath,@loader_path/.", 73 74 # Path for loading shared libraries for bundled binaries. Get back from 75 # Binary.app/Contents/MacOS. 76 "-Wl,-rpath,@loader_path/../../..", 77 ] 78 79 # Path for loading shared libraries for unbundled binaries for 80 # the host toolchain (see https://crbug.com/1315433). Only used 81 # for when building for iOS. 82 if (target_os == "ios" && current_toolchain == host_toolchain) { 83 ldflags += [ "-Wl,-rpath,@loader_path/" + rebase_path( 84 get_label_info(":mac_dynamic_flags", "root_out_dir"), 85 root_build_dir) ] 86 } 87 } 88} 89 90# When building with RBE, all inputs must be relative to the build directory. 91# If using the system Xcode, which typically resides outside the build root, a 92# symlink to the SDK is created in the build directory, and the path to that 93# link is stored in $mac_sdk_path. If an action references a file in the SDK as 94# an input, GN will complain that no target generates the file because it is 95# below the $root_build_dir. The below action lists as outputs the files in the 96# SDK that are referenced as inputs to actions, so that GN thinks a target has 97# generated them. The list is centralized here, as multiple targets need to 98# reference the same files, and an output can only be generated once. 99# 100# The symbolic link for $mac_sdk_path is set up by 101# //build/config/apple/sdk_info.py in //build/config/mac/mac_sdk.gni. 102if (use_system_xcode && (use_remoteexec || use_siso) && target_os == "mac" && 103 current_toolchain == default_toolchain) { 104 action("sdk_inputs") { 105 script = "//build/noop.py" 106 outputs = [ 107 "$mac_sdk_path/usr/include/mach/exc.defs", 108 "$mac_sdk_path/usr/include/mach/mach_exc.defs", 109 "$mac_sdk_path/usr/include/mach/notify.defs", 110 ] 111 } 112} else { 113 group("sdk_inputs") { 114 if (current_toolchain != default_toolchain) { 115 public_deps = [ ":sdk_inputs($default_toolchain)" ] 116 } 117 } 118} 119