Separates out some "SDK" related setup on Mac land Linux like we do on Windows. I'm trying to make the "compiler" BUILD file just compiler warnings and CPU options, and have system library stuff on the platform directories.

This adds the capability for GN to produce GYP files on Mac that vary according
to the GYP generator as well as target-vs-host. I added a bunch of logic to the
GN iOS build to set up stuff accordingly based on my current knowledge of
what's required.

Sadly, this means we now have an 8-way GN build (all combinations of
debug/release, host/target, and xcode/ninja). I did some refactoring of the GYP
code in GN to make this less unreasonable.

I checked that the GYP files look the way I want, but I didn't actually test
the resulting builds yet. There is still likely to be some conditions wrong or
things not being set properly. I'm going to follow up with a second pass based on actual testing.

I believe, however, that with this new GYP generator code in GN, we can express
in the .gn files what we need to do the iOS build.

Review URL: https://codereview.chromium.org/149163005

git-svn-id: http://src.chromium.org/svn/trunk/src/build@248476 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
This commit is contained in:
brettw@chromium.org 2014-02-03 12:04:33 +00:00
Родитель 9991b0cf19
Коммит f902545676
7 изменённых файлов: 96 добавлений и 31 удалений

Просмотреть файл

@ -80,6 +80,10 @@ declare_args() {
# When running in gyp-generating mode, this is the root of the build tree. # When running in gyp-generating mode, this is the root of the build tree.
gyp_output_dir = "out" gyp_output_dir = "out"
# When running in gyp-generating mode, this flag indicates if the current GYP
# generator is xcode. Can only be true when building for iOS).
is_gyp_xcode_generator = false
} }
# ============================================================================= # =============================================================================
@ -161,9 +165,8 @@ if (os == "win") {
is_nacl = false is_nacl = false
is_posix = true is_posix = true
is_win = false is_win = false
if (!is_clang) { if (!is_gyp_xcode_generator) {
# Always use clang on iOS when using ninja # Always use clang on iOS when using ninja
# (which is always true when using GN).
is_clang = true is_clang = true
} }
} else if (os == "linux") { } else if (os == "linux") {
@ -332,10 +335,13 @@ native_compiler_configs = [
"//build/config/compiler:runtime_library", "//build/config/compiler:runtime_library",
] ]
if (is_win) { if (is_win) {
native_compiler_configs += [ native_compiler_configs += [ "//build/config/win:sdk", ]
"//build/config/win:sdk", } else if (is_mac) {
] native_compiler_configs += [ "//build/config/mac:sdk", ]
} else if (is_clang) { } else if (is_ios) {
native_compiler_configs += [ "//build/config/ios:sdk", ]
}
if (is_clang) {
native_compiler_configs += [ "//build/config/clang:find_bad_constructs" ] native_compiler_configs += [ "//build/config/clang:find_bad_constructs" ]
} }

Просмотреть файл

@ -3,7 +3,6 @@
# found in the LICENSE file. # found in the LICENSE file.
import("//build/config/android/config.gni") import("//build/config/android/config.gni")
import("//build/config/sysroot.gni")
if (cpu_arch == "arm") { if (cpu_arch == "arm") {
import("//build/config/arm.gni") import("//build/config/arm.gni")
} }
@ -63,12 +62,7 @@ config("compiler") {
# ---------------------------------- # ----------------------------------
if (is_mac || is_ios) { if (is_mac || is_ios) {
# These flags are shared between the C compiler and linker. # These flags are shared between the C compiler and linker.
common_mac_flags = [ "-isysroot", sysroot ] common_mac_flags = []
if (is_mac) {
common_mac_flags += [ "-mmacosx-version-min=10.6" ]
} else {
cflags += [ "-mios-simulator-version-min=6.0" ]
}
# CPU architecture. # CPU architecture.
if (cpu_arch == "x64") { if (cpu_arch == "x64") {
@ -175,17 +169,6 @@ config("compiler") {
] ]
} }
if (sysroot != "") {
cflags += [ "--sysroot=" + sysroot ]
ldflags += [ "--sysroot=" + sysroot ]
# Need to get some linker flags out of the sysroot.
ldflags += [ exec_script("../linux/sysroot_ld_path.py",
[rebase_path("../../linux/sysroot_ld_path.sh", ".", root_build_dir),
sysroot],
"value") ]
}
ldflags += [ ldflags += [
"-fPIC", "-fPIC",
"-pthread", "-pthread",

19
config/ios/BUILD.gn Normal file
Просмотреть файл

@ -0,0 +1,19 @@
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/sysroot.gni")
import("//build/config/ios/ios_sdk.gni")
config("sdk") {
common_flags = [ "-isysroot", sysroot ]
cflags = common_flags
ldflags = common_flags
if (use_ios_simulator) {
cflags += [ "-mios-simulator-version-min=$ios_deployment_target" ]
} else {
cflags += [ "-miphoneos-version-min=$ios_deployment_target" ]
}
}

Просмотреть файл

@ -2,9 +2,31 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
# TODO(brettw) support "iphoneos" in addition to the simulator. May also need declare_args() {
# support for common.gypi's "ios_sdk" variable (seems to be a version number) # SDK path to use. When empty this will use the default SDK based on the
# and ios_sdk_path (argument that overrides the one returned below). # value of use_ios_simulator.
ios_sdk_result = ios_sdk_path = ""
exec_script("ios_sdk.py", [ "iphonesimulator" ], "list lines")
ios_sdk_path = ios_sdk_result[0] # Set to true when targeting a simulator build on iOS. False means that the
# target is for running on the device.
use_ios_simulator = true
ios_deployment_target = "6.0"
}
if (!is_gyp_xcode_generator) {
# The Ninja build currently only targets the simulator.
assert(use_ios_simulator, "You can't do an iOS device build using Ninja yet.")
}
if (ios_sdk_path == "") {
# Compute default target.
if (use_ios_simulator) {
_ios_sdk_to_query = "iphonesimulator"
} else {
_ios_sdk_to_query = "iphoneos"
}
_ios_sdk_result =
exec_script("ios_sdk.py", [ _ios_sdk_to_query ], "list lines")
ios_sdk_path = _ios_sdk_result[0]
}

Просмотреть файл

@ -3,6 +3,20 @@
# found in the LICENSE file. # found in the LICENSE file.
import("//build/config/linux/pkg_config.gni") import("//build/config/linux/pkg_config.gni")
import("//build/config/sysroot.gni")
config("sdk") {
if (sysroot != "") {
cflags = [ "--sysroot=" + sysroot ]
ldflags = [ "--sysroot=" + sysroot ]
# Need to get some linker flags out of the sysroot.
ldflags += [ exec_script("sysroot_ld_path.py",
[ rebase_path("//build/linux/sysroot_ld_path.sh", ".", root_build_dir),
sysroot ],
"value") ]
}
}
# Sets up the dynamic library search path to include our "lib" directory. # Sets up the dynamic library search path to include our "lib" directory.
config("executable_ldconfig") { config("executable_ldconfig") {

Просмотреть файл

@ -2,6 +2,18 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import("//build/config/sysroot.gni")
config("sdk") {
common_flags = [
"-isysroot", sysroot,
"-mmacosx-version-min=10.6"
]
cflags = common_flags
ldflags = common_flags
}
# On Mac, this is used for everything except static libraries. # On Mac, this is used for everything except static libraries.
config("mac_dynamic_flags") { config("mac_dynamic_flags") {
ldflags = [ ldflags = [

Просмотреть файл

@ -223,7 +223,8 @@ def GetArgsStringForGN(supplemental_files):
gn_args += ' ' + i[2] gn_args += ' ' + i[2]
# These string arguments get passed directly as GN strings. # These string arguments get passed directly as GN strings.
for v in ['android_src', 'windows_sdk_path', 'arm_float_abi']: for v in ['android_src', 'arm_float_abi', 'ios_deployment_target',
'ios_sdk_path', 'windows_sdk_path']:
if v in vars_dict: if v in vars_dict:
gn_args += ' ' + v + '=' + EscapeStringForGN(vars_dict[v]) gn_args += ' ' + v + '=' + EscapeStringForGN(vars_dict[v])
@ -231,6 +232,14 @@ def GetArgsStringForGN(supplemental_files):
if 'gomadir' in vars_dict: if 'gomadir' in vars_dict:
gn_args += ' goma_dir=%s' % EscapeStringForGN(vars_dict['gomadir']) gn_args += ' goma_dir=%s' % EscapeStringForGN(vars_dict['gomadir'])
# Clear the "use_ios_simulator" flag if the ios_sdk_path is set and is
# not a simulator SDK. This duplicates code done in GYP's xcode emulation.
if 'ios_sdk_path' in vars_dict:
if not os.path.basename(vars_dict['ios_sdk_path']).lower().startswith(
'iphonesimulator'):
gn_args += ' use_ios_simulator=false'
# These arguments get passed directly as integers (avoiding the quoting and # These arguments get passed directly as integers (avoiding the quoting and
# escaping of the string ones above). # escaping of the string ones above).
for v in ['arm_version']: for v in ['arm_version']: