1# Copyright (c) 2021-2022 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14import("ohos-var.gni") 15 16template("ohos_executable") { 17 not_needed(invoker, 18 [ 19 "install_images", 20 "part_name", 21 ]) 22 23 if (defined(invoker.external_deps) && invoker.external_deps != []) { 24 if (!defined(invoker.deps)) { 25 invoker.deps = [] 26 } 27 foreach(dep, invoker.external_deps) { 28 if (label_matches(dep, [ "//third_party/*" ])) { 29 invoker.deps += [ dep ] 30 } 31 } 32 } 33 34 executable("${target_name}") { 35 forward_variables_from(invoker, 36 "*", 37 [ 38 "configs", 39 "remove_configs", 40 "public_configs", 41 "relative_install_dir", 42 "subsystem_name", 43 "install_enable", 44 ]) 45 if (defined(invoker.configs)) { 46 configs += invoker.configs 47 } 48 49 if (defined(invoker.public_configs)) { 50 configs += invoker.public_configs 51 } 52 if (defined(invoker.remove_configs)) { 53 configs -= invoker.remove_configs 54 } 55 56 assert(!defined(invoker.output_dir), 57 "output_dir is not allowed to be defined.") 58 output_dir = "${root_out_dir}/bin" 59 } 60} 61 62template("ohos_shared_library") { 63 not_needed(invoker, 64 [ 65 "install_images", 66 "part_name", 67 ]) 68 69 if (defined(invoker.external_deps) && invoker.external_deps != []) { 70 if (!defined(invoker.deps)) { 71 invoker.deps = [] 72 } 73 foreach(dep, invoker.external_deps) { 74 if (label_matches(dep, [ "//third_party/*" ])) { 75 invoker.deps += [ dep ] 76 } 77 } 78 } 79 80 shared_library("${target_name}") { 81 forward_variables_from(invoker, 82 "*", 83 [ 84 "configs", 85 "remove_configs", 86 "public_configs", 87 "relative_install_dir", 88 "subsystem_name", 89 "install_enable", 90 "part_name", 91 ]) 92 93 if (defined(invoker.configs)) { 94 configs += invoker.configs 95 } 96 if (defined(invoker.public_configs)) { 97 configs += invoker.public_configs 98 } 99 100 if (defined(invoker.remove_configs)) { 101 configs -= invoker.remove_configs 102 } 103 104 assert(!defined(invoker.output_dir), 105 "output_dir is not allowed to be defined.") 106 output_dir = "${root_out_dir}/lib" 107 } 108} 109 110template("ohos_static_library") { 111 not_needed(invoker, [ "part_name" ]) 112 113 if (defined(invoker.external_deps) && invoker.external_deps != []) { 114 if (!defined(invoker.deps)) { 115 invoker.deps = [] 116 } 117 foreach(dep, invoker.external_deps) { 118 if (label_matches(dep, [ "//third_party/*" ])) { 119 invoker.deps += [ dep ] 120 } 121 } 122 } 123 124 static_library("${target_name}") { 125 forward_variables_from(invoker, 126 "*", 127 [ 128 "configs", 129 "remove_configs", 130 "public_configs", 131 "relative_install_dir", 132 "subsystem_name", 133 "install_enable", 134 ]) 135 136 if (defined(invoker.configs)) { 137 configs += invoker.configs 138 } 139 140 if (defined(invoker.public_configs)) { 141 configs += invoker.public_configs 142 } 143 144 if (defined(invoker.remove_configs)) { 145 configs -= invoker.remove_configs 146 } 147 } 148} 149 150template("ohos_prebuilt_etc") { 151 copy("${target_name}") { 152 forward_variables_from(invoker, 153 "*", 154 [ 155 "subsystem_name", 156 "install_enable", 157 "source", 158 "module_install_dir", 159 "part_name", 160 ]) 161 sources = [ invoker.source ] 162 outputs = [ "${target_out_dir}/${invoker.source}" ] 163 } 164} 165 166template("ohos_source_set") { 167 not_needed(invoker, 168 [ 169 "public_external_deps", 170 "part_name", 171 "subsystem_name", 172 ]) 173 174 if (defined(invoker.external_deps) && invoker.external_deps != []) { 175 if (!defined(invoker.deps)) { 176 invoker.deps = [] 177 } 178 foreach(dep, invoker.external_deps) { 179 if (label_matches(dep, [ "//third_party/*" ])) { 180 invoker.deps += [ dep ] 181 } 182 } 183 } 184 185 source_set(target_name) { 186 forward_variables_from(invoker, 187 "*", 188 [ 189 "configs", 190 "public_configs", 191 "remove_configs", 192 ]) 193 if (defined(invoker.configs)) { 194 configs += invoker.configs 195 } 196 if (defined(invoker.public_configs)) { 197 configs += invoker.public_configs 198 } 199 if (defined(invoker.remove_configs)) { 200 configs -= invoker.remove_configs 201 } 202 } 203} 204