conanfile.py.jinja 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. from conan import ConanFile
  2. {%- if use_conan2 %}
  3. from conan.tools.files import copy
  4. from conan.tools.cmake import CMakeToolchain, CMakeDeps, cmake_layout
  5. {%- endif %}
  6. class App(ConanFile):
  7. settings = "os", "compiler", "build_type", "arch"
  8. options = {
  9. {%- for conan_option in conan.options -%}
  10. {%- set option_and_value = rsplit(conan_option, "=", 2) %}"{{ option_and_value[0] }}": "{{ option_and_value[1] }}"
  11. {%- if not loop.last -%}, {% endif -%}
  12. {%- endfor -%}
  13. }
  14. {%- set has_conan_os_depends_requires = conan.os_depends|selectattr('requires')|map(attribute='requires')|sum|length -%}
  15. {%- if (conan.requires|length) or (has_conan_os_depends_requires) %}
  16. def requirements(self):
  17. {%- if (conan.requires|length) %}
  18. {%- for conan_require in conan.requires %}
  19. self.requires("{{ conan_require }}")
  20. {%- endfor -%}
  21. {%- endif -%}
  22. {%- if (has_conan_os_depends_requires) -%}
  23. {%- for conan_os_depend in conan.os_depends|selectattr('requires') %}
  24. {%- if (conan_os_depend.requires|length) %}
  25. if self.settings.os == "{{ conan_os_depend.os }}":
  26. {%- for conan_require in conan_os_depend.requires %}
  27. self.requires("{{ conan_require }}")
  28. {%- endfor -%}
  29. {%- endif -%}
  30. {%- endfor -%}
  31. {%- endif -%}
  32. {%- endif -%}
  33. {%- set has_conan_os_depends_tool_requires = conan.os_depends|selectattr('tool_requires')|map(attribute='tool_requires')|sum|length -%}
  34. {%- if (conan.tool_requires|length) or (has_conan_os_depends_tool_requires) %}
  35. def build_requirements(self):
  36. {%- if (conan.tool_requires|length) %}
  37. {%- for conan_tool_require in conan.tool_requires %}
  38. self.tool_requires("{{ conan_tool_require }}")
  39. {%- endfor -%}
  40. {%- endif -%}
  41. {%- if (has_conan_os_depends_tool_requires) -%}
  42. {%- for conan_os_depend in conan.os_depends|selectattr('tool_requires') %}
  43. {%- if (conan_os_depend.tool_requires|length) %}
  44. if self.settings.os == "{{ conan_os_depend.os }}":
  45. {%- for conan_tool_require in conan_os_depend.tool_requires %}
  46. self.tool_requires("{{ conan_tool_require }}")
  47. {%- endfor -%}
  48. {%- endif -%}
  49. {%- endfor -%}
  50. {%- endif -%}
  51. {%- endif -%}
  52. {%- set has_conan_os_depends_imports = conan.os_depends|selectattr('imports')|map(attribute='imports')|sum|length -%}
  53. {%- if use_conan2 %}
  54. def generate(self):
  55. CMakeDeps(self).generate()
  56. CMakeToolchain(self).generate()
  57. {%- for conan_generator in conan.generators %}
  58. {{ conan_generator }}(self).generate()
  59. {%- endfor %}
  60. for dep in self.dependencies.values():
  61. {%- if conan.imports|length -%}
  62. {%- set conan_imports = conan.imports -%}
  63. {%- set shift = "" -%}
  64. {%- include "[generator]/conan_imports.jinja" -%}
  65. {%- endif -%}
  66. {%- if (has_conan_os_depends_imports) -%}
  67. {%- for conan_os_depend in conan.os_depends|selectattr('imports') %}
  68. {%- if (conan_os_depend.imports|length) %}
  69. if self.settings.os == "{{ conan_os_depend.os }}":
  70. {%- set conan_imports = conan_os_depend.imports -%}
  71. {%- set shift = " " -%}
  72. {%- include "[generator]/conan_imports.jinja" -%}
  73. {%- endif -%}
  74. {%- endfor -%}
  75. {%- endif %}
  76. def layout(self):
  77. cmake_layout(self)
  78. {%- else %}
  79. generators = "cmake_find_package", "cmake_paths"
  80. def imports(self):
  81. {%- if conan.imports|length -%}
  82. {%- set conan_imports = conan.imports -%}
  83. {%- set shift = "" -%}
  84. {%- include "[generator]/conan_imports.jinja" -%}
  85. {%- endif -%}
  86. {%- if (has_conan_os_depends_imports) -%}
  87. {%- for conan_os_depend in conan.os_depends|selectattr('imports') %}
  88. {%- if (conan_os_depend.imports|length) %}
  89. if self.settings.os == "{{ conan_os_depend.os }}":
  90. {%- set conan_imports = conan_os_depend.imports -%}
  91. {%- set shift = " " -%}
  92. {%- include "[generator]/conan_imports.jinja" -%}
  93. {%- endif -%}
  94. {%- endfor -%}
  95. {%- endif -%}
  96. {%- endif -%}
  97. {%- include "[generator]/debug_conan.jinja" ignore missing %}