conanfile.py.jinja 4.2 KB

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