blob: d922f0b844ac4956245129122a28d296a8246e08 [file] [log] [blame]
Armando Montanez256fb502021-06-28 10:47:49 -07001# Copyright 2021 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7# https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15import("//build_overrides/pigweed.gni")
16
17import("$dir_pw_build/cc_library.gni")
18
19# Note: In general, prefer to import target_types.gni rather than this file.
20# cc_executable.gni and cc_library.gni are both provided by target_types.gni.
21#
22# cc_library.gni is split out from cc_executable.gni because pw_executable
23# templates may need to create pw_source_set targets internally, and can't
24# import target_types.gni because it creates a circular import path.
25
26declare_args() {
27 # The name of the GN target type used to build Pigweed executables.
28 #
29 # If this is a custom template, the .gni file containing the template must
30 # be imported at the top of the target configuration file to make it globally
31 # available.
32 pw_build_EXECUTABLE_TARGET_TYPE = "executable"
33
34 # The path to the .gni file that defines pw_build_EXECUTABLE_TARGET_TYPE.
35 #
36 # If pw_build_EXECUTABLE_TARGET_TYPE is not the default of `executable`, this
37 # .gni file is imported to provide the template definition.
38 pw_build_EXECUTABLE_TARGET_TYPE_FILE = ""
39}
40
41if (pw_build_EXECUTABLE_TARGET_TYPE != "executable" &&
42 pw_build_EXECUTABLE_TARGET_TYPE_FILE != "") {
43 import(pw_build_EXECUTABLE_TARGET_TYPE_FILE)
44}
45
46_supported_toolchain_defaults = [
47 "configs",
48 "public_deps",
49]
50
51# Wrapper for Pigweed executable build targets which uses a globally-defined,
52# configurable target type.
53template("pw_executable") {
54 _executable_output_dir = "${target_out_dir}/bin"
55 if (defined(invoker.output_dir)) {
56 _executable_output_dir = invoker.output_dir
57 }
58
59 target(pw_build_EXECUTABLE_TARGET_TYPE, target_name) {
60 import("$dir_pw_build/defaults.gni")
61
62 forward_variables_from(invoker, "*", _supported_toolchain_defaults)
63
64 if (!defined(configs)) {
65 configs = []
66 }
67 if (defined(pw_build_defaults.configs)) {
68 configs += pw_build_defaults.configs
69 }
70 if (defined(remove_configs)) {
71 if (remove_configs != [] && remove_configs[0] == "*") {
72 configs = []
73 } else {
74 configs += remove_configs # Add configs in case they aren't already
75 configs -= remove_configs # present, then remove them.
76 }
77 }
78 if (defined(invoker.configs)) {
79 configs += invoker.configs
80 }
81
82 public_deps = [ "$dir_pw_build:link_deps" ]
83 if (defined(pw_build_defaults.public_deps)) {
84 public_deps += pw_build_defaults.public_deps
85 }
86 if (defined(remove_public_deps)) {
87 if (remove_public_deps != [] && remove_public_deps[0] == "*") {
88 public_deps = []
89 } else {
90 public_deps += remove_public_deps
91 public_deps -= remove_public_deps
92 }
93 }
94 if (defined(invoker.public_deps)) {
95 public_deps += invoker.public_deps
96 }
97
98 output_dir = _executable_output_dir
99 }
100}