| # Copyright 2018 The Fuchsia 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/banjo/toolchain.gni") |
| import("//build/compiled_action.gni") |
| |
| # C/C++ bindings for a Banjo protocol. |
| # |
| # The parameters for this template are defined in //build/banjo/banjo.gni. The |
| # relevant parameters in this template are: |
| # name: string, name of the Banjo protocol |
| |
| template("banjo_c_target") { |
| assert(is_fuchsia, "This template can only be used in $target_toolchain.") |
| |
| not_needed(invoker, [ "sources" ]) |
| |
| main_target_name = target_name |
| |
| library_name = target_name |
| if (defined(invoker.name)) { |
| library_name = invoker.name |
| } |
| |
| ddk_root = string_replace(string_replace(library_name, ".", "/"), "_", "-") |
| ddktl_root = string_replace(ddk_root, "ddk", "ddktl") |
| banjo_root_gen_dir = |
| get_label_info(":$target_name($banjo_toolchain)", "root_gen_dir") |
| ddk_header = "$banjo_root_gen_dir/$ddk_root.h" |
| ddktl_header = "$banjo_root_gen_dir/$ddktl_root.h" |
| ddktl_internal_header = "$banjo_root_gen_dir/$ddktl_root-internal.h" |
| ddktl_mock_header = "$banjo_root_gen_dir/mock/$ddktl_root.h" |
| |
| # The C/C++ headers are generated by the frontend, so we just need to |
| # produce a target with the generated file name and configuration information. |
| source_set(main_target_name) { |
| forward_variables_from(invoker, |
| [ |
| "deps", |
| "needs_composite", |
| "testonly", |
| "visibility", |
| ]) |
| |
| public = [ |
| ddk_header, |
| ddktl_header, |
| ddktl_internal_header, |
| ] |
| |
| # The generated headers #include <ddk/*.h> and #include <ddktl/*.h> |
| # files from the libraries (that aren't generated). |
| public_deps = [ |
| "//src/lib/ddk", |
| "//src/lib/ddktl", |
| ] |
| if (!defined(needs_composite) || needs_composite) { |
| public_deps += [ "//sdk/banjo/ddk.protocol.composite" ] |
| } |
| |
| # Let dependencies use `#include "$file_stem.h"`. |
| public_configs = [ "//build/c:banjo_gen_config" ] |
| |
| if (!defined(deps)) { |
| deps = [] |
| } |
| deps += [ |
| ":${main_target_name}_c_compile($banjo_toolchain)", |
| ":${main_target_name}_cpp_compile($banjo_toolchain)", |
| ":${main_target_name}_cpp_i_compile($banjo_toolchain)", |
| "//src/zircon/lib/zircon", |
| ] |
| } |
| |
| # Define a separate target for mocks to avoid requiring all Banjo users to |
| # link to the C++ standard library. |
| source_set("${main_target_name}_mock") { |
| testonly = true |
| |
| forward_variables_from(invoker, |
| [ |
| "deps", |
| "visibility", |
| ]) |
| |
| public = [ ddktl_mock_header ] |
| |
| if (!defined(deps)) { |
| deps = [] |
| } |
| deps += [ |
| ":${main_target_name}", |
| ":${main_target_name}_cpp_mock($banjo_toolchain)", |
| ] |
| |
| public_deps = [ |
| "//zircon/public/lib/fbl", |
| "//zircon/public/lib/mock-function", |
| "//zircon/public/lib/zxtest", |
| ] |
| } |
| } |
| |
| template("banjo_dummy_c_target") { |
| assert(is_fuchsia, "This template can only be used in $target_toolchain.") |
| |
| not_needed(invoker, |
| [ |
| "sources", |
| "name", |
| ]) |
| |
| main_target_name = target_name |
| |
| # The headers referenced by a dummy target all exist in the sysroot. |
| source_set(main_target_name) { |
| forward_variables_from(invoker, |
| [ |
| "deps", |
| "testonly", |
| "visibility", |
| ]) |
| |
| public_deps = [ "//zircon/public/sysroot:headers" ] |
| deps = [ "//src/zircon/lib/zircon" ] |
| } |
| } |