dir_targets.jinja 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 not(is_really_fake_module) and (target_options.privates is defined) -%}
  61. {{ RenderTargetOptions(target_name, ' PRIVATE', target_options.privates, only_option, exclude_options) }}
  62. {%- endif -%}
  63. {%- endmacro -%}
  64. {%- if target is defined -%}
  65. {%- set current_target = target -%}
  66. {%- include '[generator]/target_cmake_lists.jinja' -%}
  67. {%- endif -%}
  68. {%- if extra_targets is defined -%}
  69. {%- for current_target in extra_targets -%}
  70. {%- include '[generator]/target_cmake_lists.jinja' -%}
  71. {%- endfor -%}
  72. {%- endif -%}