dir_targets.jinja 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. {%- macro MacrosesWithMergeArgs(target_name, list_of_dict, macro_suffix, macro_field, args_field) -%}
  2. {%- set macros = list_of_dict|map(attribute=macro_field)|unique -%}
  3. {%- for macro in macros -%}
  4. {%- set args = list_of_dict|selectattr(macro_field, 'eq', macro)|map(attribute=args_field)|sum -%}
  5. {%- if args|length %}
  6. {{ macro }}({{ target_name }}{{ macro_suffix }}
  7. {%- for arg in args %}
  8. {{ arg }}
  9. {%- endfor %}
  10. )
  11. {% endif %}
  12. {%- endfor -%}
  13. {%- endmacro -%}
  14. {%- macro Macroses(target_name, list_of_dict, macro_field, args_field, excludes) -%}
  15. {%- set macros = list_of_dict|map(attribute=macro_field)|unique -%}
  16. {%- for macro in macros -%}
  17. {%- if (excludes|length == 0) or not (macro in excludes) -%}
  18. {%- set merge_args = list_of_dict|selectattr(macro_field, 'eq', macro)|selectattr('merge_args') -%}
  19. {%- if merge_args|length %}
  20. {{ MacrosesWithMergeArgs(target_name, list_of_dict|selectattr(macro_field, 'eq', macro), '', macro_field, args_field) }}
  21. {%- else -%}
  22. {%- set macroses = list_of_dict|selectattr(macro_field, 'eq', macro) -%}
  23. {%- for macros in macroses %}
  24. {{ macros.macro }}({{ target_name }}{{ macro_suffix }}
  25. {%- if macros.args|length %}
  26. {%- for arg in macros.args %}
  27. {{ arg }}
  28. {%- endfor %}
  29. {% endif -%}
  30. )
  31. {% endfor -%}
  32. {%- endif -%}
  33. {%- endif -%}
  34. {%- endfor -%}
  35. {%- endmacro -%}
  36. {%- macro RenderTargetOptions(target_name, prefix, options, only_option, exclude_options) -%}
  37. {%- if only_option != "" -%}
  38. {%- set selected_options = options|selectattr('option', 'eq', only_option) -%}
  39. {%- elif exclude_options|length -%}
  40. {%- set selected_options = options|rejectattr('option', 'in', exclude_options) -%}
  41. {%- else -%}
  42. {%- set selected_options = options -%}
  43. {%- endif -%}
  44. {%- if selected_options|length -%}
  45. {{ MacrosesWithMergeArgs(target_name, selected_options, prefix, 'option', 'args') }}
  46. {%- endif -%}
  47. {%- endmacro -%}
  48. {%- macro TargetOptions(target_name, is_really_fake_module, target_options, only_option, exclude_options) -%}
  49. {%- if (target_options.interfaces is defined) -%}
  50. {{ RenderTargetOptions(target_name, ' INTERFACE', target_options.interfaces, only_option, exclude_options) }}
  51. {%- endif -%}
  52. {%- if (target_options.publics is defined) -%}
  53. {%- if is_really_fake_module -%}
  54. {%- set prefix = ' INTERFACE' -%}
  55. {%- else -%}
  56. {%- set prefix = ' PUBLIC' -%}
  57. {%- endif -%}
  58. {{ RenderTargetOptions(target_name, prefix, target_options.publics, only_option, exclude_options) }}
  59. {%- endif -%}
  60. {%- if (target_options.privates is defined) -%}
  61. {%- if is_really_fake_module -%}
  62. {%- set prefix = ' INTERFACE' -%}
  63. {%- else -%}
  64. {%- set prefix = ' PRIVATE' -%}
  65. {%- endif -%}
  66. {{ RenderTargetOptions(target_name, prefix, target_options.privates, only_option, exclude_options) }}
  67. {%- endif -%}
  68. {%- endmacro -%}
  69. {%- if target is defined -%}
  70. {%- set current_target = target -%}
  71. {%- include '[generator]/target_cmake_lists.jinja' -%}
  72. {%- endif -%}
  73. {%- if extra_targets|length -%}
  74. {%- for current_target in extra_targets -%}
  75. {%- include '[generator]/target_cmake_lists.jinja' -%}
  76. {%- endfor -%}
  77. {%- endif -%}