wayland_protocol.gni 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Copyright 2018 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. # Template to generate wayland protocol code with wayland-scanner.
  5. #
  6. # Example:
  7. # wayland_protocol("foo") {
  8. # sources = [ "foo.xml" ]
  9. # }
  10. import("//third_party/wayland/features.gni")
  11. template("wayland_protocol") {
  12. assert(defined(invoker.sources), "Need sources for wayland protocol")
  13. # Calculate the output paths.
  14. protocol_outputs = []
  15. output_dirs = []
  16. foreach(protocol, invoker.sources) {
  17. dir = "$root_gen_dir/" + rebase_path(get_path_info(protocol, "dir"), "//")
  18. name = get_path_info(protocol, "name")
  19. protocol_outputs += [
  20. "${dir}/${name}-protocol.c",
  21. "${dir}/${name}-client-protocol.h",
  22. "${dir}/${name}-server-protocol.h",
  23. ]
  24. output_dirs += [ dir ]
  25. }
  26. action_name = "${target_name}_gen"
  27. config_name = "${target_name}_config"
  28. source_set_name = "${target_name}"
  29. # Action which runs wayland-scanner to generate the code.
  30. action(action_name) {
  31. visibility = [ ":$source_set_name" ]
  32. script = "//third_party/wayland/wayland_scanner_wrapper.py"
  33. sources = invoker.sources
  34. outputs = protocol_outputs
  35. # Paths in invoker.sources are relative to the invoker.
  36. # Make it relative to the src root.
  37. args = rebase_path(invoker.sources, "//")
  38. args += [
  39. "--src-root",
  40. rebase_path("//", root_build_dir),
  41. ]
  42. args += [
  43. "--root-gen-dir",
  44. rebase_path(root_gen_dir, root_build_dir),
  45. ]
  46. if (use_system_wayland_scanner) {
  47. args += [
  48. "--cmd",
  49. system_wayland_scanner_path,
  50. ]
  51. } else {
  52. wayland_scanner_label =
  53. "//third_party/wayland:wayland_scanner($host_toolchain)"
  54. deps = [ wayland_scanner_label ]
  55. wayland_scanner_path = get_label_info(wayland_scanner_label,
  56. "root_out_dir") + "/wayland_scanner"
  57. cmd = "./" + rebase_path(wayland_scanner_path, root_build_dir)
  58. args += [
  59. "--cmd",
  60. cmd,
  61. ]
  62. }
  63. }
  64. # Config to include the generated headers only with the file names.
  65. # e.g. #include <foo-client-protocol.h>
  66. config(config_name) {
  67. include_dirs = output_dirs
  68. }
  69. # Source set which consists of the generated code.
  70. source_set(source_set_name) {
  71. sources = get_target_outputs(":$action_name")
  72. deps = [
  73. ":$action_name",
  74. "//third_party/wayland:wayland_util",
  75. ]
  76. configs -= [ "//build/config/compiler:chromium_code" ]
  77. configs += [ "//build/config/compiler:no_chromium_code" ]
  78. public_configs = [ ":$config_name" ]
  79. }
  80. }