message_compiler.gni 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # Copyright 2015 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. assert(is_win, "This only runs on Windows.")
  5. # Runs mc.exe over a list of sources. The outputs (a header and rc file) are
  6. # placed in the target gen dir, and compiled.
  7. #
  8. # sources
  9. # List of message files to process.
  10. #
  11. # user_mode_logging (optional bool)
  12. # Generates user-mode logging code. Defaults to false (no logging code).
  13. #
  14. # compile_generated_code (optional, deafults = true)
  15. # If unset or true, the generated code will be compiled and linked into
  16. # targets that depend on it. If set to false, the .h and .rc files will only
  17. # be generated.
  18. #
  19. # deps, public_deps, visibility
  20. # Normal meaning.
  21. template("message_compiler") {
  22. if (defined(invoker.compile_generated_code) &&
  23. !invoker.compile_generated_code) {
  24. compile_generated_code = false
  25. action_name = target_name
  26. } else {
  27. compile_generated_code = true
  28. action_name = "${target_name}_mc"
  29. source_set_name = target_name
  30. }
  31. action_foreach(action_name) {
  32. if (compile_generated_code) {
  33. visibility = [ ":$source_set_name" ]
  34. } else {
  35. forward_variables_from(invoker, [ "visibility" ])
  36. }
  37. script = "//build/win/message_compiler.py"
  38. outputs = [
  39. "$target_gen_dir/{{source_name_part}}.h",
  40. "$target_gen_dir/{{source_name_part}}.rc",
  41. ]
  42. args = [
  43. # The first argument is the environment file saved to the build
  44. # directory. This is required because the Windows toolchain setup saves
  45. # the VC paths and such so that running "mc.exe" will work with the
  46. # configured toolchain. This file is in the root build dir.
  47. "environment.$current_cpu",
  48. # Where to put the header.
  49. "-h",
  50. rebase_path(target_gen_dir, root_build_dir),
  51. # Where to put the .rc file.
  52. "-r",
  53. rebase_path(target_gen_dir, root_build_dir),
  54. # Input is Unicode.
  55. "-u",
  56. ]
  57. if (defined(invoker.user_mode_logging) && invoker.user_mode_logging) {
  58. args += [ "-um" ]
  59. }
  60. args += [ "{{source}}" ]
  61. forward_variables_from(invoker,
  62. [
  63. "deps",
  64. "public_deps",
  65. "sources",
  66. ])
  67. }
  68. if (compile_generated_code) {
  69. # Compile the generated rc file.
  70. source_set(source_set_name) {
  71. forward_variables_from(invoker, [ "visibility" ])
  72. sources = get_target_outputs(":$action_name")
  73. deps = [ ":$action_name" ]
  74. }
  75. }
  76. }