| # 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 | |
| } | |
| c_root = string_replace(string_replace(library_name, ".", "/"), "_", "-") | |
| banjo_root_gen_dir = | |
| get_label_info(":$target_name($banjo_toolchain)", "root_gen_dir") | |
| c_header = "$banjo_root_gen_dir/$c_root/c/banjo.h" | |
| cpp_header = "$banjo_root_gen_dir/$c_root/cpp/banjo.h" | |
| cpp_internal_header = "$banjo_root_gen_dir/$c_root/cpp/banjo-internal.h" | |
| cpp_mock_header = "$banjo_root_gen_dir/$c_root/cpp/banjo-mock.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 = [ | |
| c_header, | |
| cpp_header, | |
| cpp_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/fuchsia.hardware.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 = [ cpp_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" ] | |
| } | |
| } |