commit c8e815a8cd949c4bb0f51fffc9587e352ace1b6c
parent 129b25211594fe3469b70e8616bc03d222a73a84
Author: Chris Bracken <chris@bracken.jp>
Date: Fri, 5 Oct 2018 12:36:07 -0700
Split out debug, symbols, optimisation configs
Adds is_debug gn argument which controls debug/release mode,
optimisation, and symbolification settings.
Supported build modes are now:
* is_debug=true: cflags = [ "-g2", "-O0" ]
* is_debug=false: cflags = [ "-g0", "-O2" ]
Diffstat:
2 files changed, 114 insertions(+), 0 deletions(-)
diff --git a/build/BUILD.gn b/build/BUILD.gn
@@ -24,3 +24,38 @@ config("compiler_warnings") {
"-Wno-c++98-compat",
]
}
+
+# Debug mode build.
+config("debug") {
+ defines = [ "_DEBUG" ]
+}
+
+# Release mode build.
+config("release") {
+ defines = [ "NDEBUG" ]
+}
+
+# Disable optimisations.
+config("no_optimize") {
+ cflags = [ "-O0" ]
+}
+
+# Enable optimisations.
+config("optimize") {
+ cflags = [ "-O2" ]
+}
+
+# Regular build with symbols.
+config("symbols") {
+ cflags = [ "-g2" ]
+}
+
+# Minimal symbols, typically just enough for backtraces.
+config("min_symbols") {
+ cflags = [ "-g1" ]
+}
+
+# No symbols.
+config("no_symbols") {
+ cflags = [ "-g0" ]
+}
diff --git a/build/BUILDCONFIG.gn b/build/BUILDCONFIG.gn
@@ -1,3 +1,35 @@
+# =============================================================================
+# PLATFORM SELECTION
+# =============================================================================
+#
+# There are two main things to set: "os" and "cpu". The "toolchain" is the name
+# of the GN thing that encodes combinations of these things.
+#
+# Users typically only set the variables "target_os" and "target_cpu" in "gn
+# args", the rest are set up by our build and internal to GN.
+#
+# There are three different types of each of these things: The "host"
+# represents the computer doing the compile and never changes. The "target"
+# represents the main thing we're trying to build. The "current" represents
+# which configuration is currently being defined, which can be either the
+# host, the target, or something completely different (like nacl). GN will
+# run the same build file multiple times for the different required
+# configuration in the same build.
+#
+# This gives the following variables:
+# - host_os, host_cpu, host_toolchain
+# - target_os, target_cpu, default_toolchain
+# - current_os, current_cpu, current_toolchain.
+#
+# Note the default_toolchain isn't symmetrical (you would expect
+# target_toolchain). This is because the "default" toolchain is a GN built-in
+# concept, and "target" is something our build sets up that's symmetrical with
+# its GYP counterpart. Potentially the built-in default_toolchain variable
+# could be renamed in the future.
+#
+# When writing build files, to do something only for the host:
+# if (current_toolchain == host_toolchain) { ...
+
if (target_os == "") {
target_os = host_os
}
@@ -11,6 +43,42 @@ if (current_os == "") {
current_os = target_os
}
+# =============================================================================
+# PLATFORM SELECTION
+# =============================================================================
+#
+# There are two main things to set: "os" and "cpu". The "toolchain" is the name
+# of the GN thing that encodes combinations of these things.
+#
+# Users typically only set the variables "target_os" and "target_cpu" in "gn
+# args", the rest are set up by our build and internal to GN.
+#
+# There are three different types of each of these things: The "host"
+# represents the computer doing the compile and never changes. The "target"
+# represents the main thing we're trying to build. The "current" represents
+# which configuration is currently being defined, which can be either the
+# host, the target, or something completely different (like nacl). GN will
+# run the same build file multiple times for the different required
+# configuration in the same build.
+#
+# This gives the following variables:
+# - host_os, host_cpu, host_toolchain
+# - target_os, target_cpu, default_toolchain
+# - current_os, current_cpu, current_toolchain.
+#
+# Note the default_toolchain isn't symmetrical (you would expect
+# target_toolchain). This is because the "default" toolchain is a GN built-in
+# concept, and "target" is something our build sets up that's symmetrical with
+# its GYP counterpart. Potentially the built-in default_toolchain variable
+# could be renamed in the future.
+#
+# When writing build files, to do something only for the host:
+# if (current_toolchain == host_toolchain) { ...
+
+declare_args() {
+ is_debug = true
+}
+
# Options
use_strip = false
@@ -20,6 +88,17 @@ _shared_binary_target_configs = [
"//build:compiler_warnings",
]
+# Optimisations and debug/release mode.
+if (is_debug) {
+ _shared_binary_target_configs += [ "//build:debug" ]
+ _shared_binary_target_configs += [ "//build:no_optimize" ]
+ _shared_binary_target_configs += [ "//build:symbols" ]
+} else {
+ _shared_binary_target_configs += [ "//build:release" ]
+ _shared_binary_target_configs += [ "//build:optimize" ]
+ _shared_binary_target_configs += [ "//build:no_symbols" ]
+}
+
# Apply that default list to the binary target types.
set_defaults("executable") {
configs = _shared_binary_target_configs