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