blob: cc96a5102dc32995b24808c7198a99b47f65db97 [file] [log] [blame]
# Copyright 2017 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# The delegated_config template defines a family of configs which delegate to
# real implementations elsewhere. The most notable use of this template is to
# define toolchain-independent compiler configs, such as
# //starboard/build/config:rtti (and its sisters :no_rtti and :default_rtti).
#
# The simplest way to use delegated_config is to specify only a path:
#
# delegated_config("rtti") {
# path = "//$starboard_path"
# }
#
# The sample code above will expand to:
#
# config("rtti") {
# configs = [ "//$starboard_path:rtti" ]
# }
#
# config("no_rtti") {
# configs = [ "//$starboard_path:no_rtti" ]
# }
#
# config("default_rtti") {
# configs = [ "//$starboard_path:default_rtti" ]
# }
#
# The BUILD.gn file is then expected to define each of those three configs (or
# further delegate them to e.g. a toolchain's implementation).
#
# To use a different list of prefixes, set the prefixes option:
#
# delegated_config("optimizations") {
# path = "//$starboard_path"
# prefixes = [ "no", "debuggable", "full" ]
# }
#
# This will expand to:
#
# config("no_optimizations") {
# configs = [ "//$starboard_path:no_optimizations" ]
# }
#
# config("debuggable_optimizations") {
# configs = [ "//$starboard_path:debuggable_optimizations" ]
# }
#
# config("full_optimizations") {
# configs = [ "//$starboard_path:full_optimizations" ]
# }
#
# config("default_optimizations") {
# configs = [ "//$starboard_path:default_optimizations" ]
# }
#
# Note that the default_optimizations config is generated, even though it is
# not in the list of prefixes. If you don't want the default_optimizations
# config to be generated, set generate_default = false:
#
# delegated_config("optimizations") {
# path = "//$starboard_path"
# prefixes = [ "no", "debuggable", "full" ]
# generate_default = false
# }
#
# Now only the no_, debuggable_, and full_ configs will be generated.
template("delegated_config") {
assert(defined(invoker.path),
"You need to specify a path to the implementation")
if (defined(invoker.prefixes)) {
prefixes = invoker.prefixes
} else {
prefixes = [ "", "no" ]
}
foreach(prefix, prefixes) {
assert(prefix != "default",
"You shouldn't include \"default\" in the list of prefixes " +
"because it's separately generated.")
if (prefix == "") {
prefix_ = prefix
} else {
prefix_ = "${prefix}_"
}
config("$prefix_$target_name") {
configs = [ "${invoker.path}:$prefix_$target_name" ]
}
}
if (!(defined(invoker.generate_default) && !invoker.generate_default)) {
config("default_$target_name") {
configs = [ "${invoker.path}:default_$target_name" ]
}
}
}