conanfile.py 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. from conan import ConanFile
  2. from conan.errors import ConanInvalidConfiguration
  3. from conan.tools.apple import is_apple_os
  4. from conan.tools.cmake import CMakeDeps, CMakeToolchain
  5. from conans import tools
  6. required_conan_version = ">=1.51.3"
  7. class VCMI(ConanFile):
  8. settings = "os", "compiler", "build_type", "arch"
  9. requires = [
  10. "boost/[^1.69]",
  11. "minizip/[~1.2.12]",
  12. "onetbb/[^2021.3]", # Nullkiller AI
  13. "qt/[~5.15.2]", # launcher
  14. "sdl/[~2.26.1 || >=2.0.20 <=2.22.0]", # versions in between have broken sound
  15. "sdl_image/[~2.0.5]",
  16. "sdl_mixer/[~2.0.4]",
  17. "sdl_ttf/[~2.0.18]",
  18. ]
  19. options = {
  20. "default_options_of_requirements": [True, False],
  21. "with_apple_system_libs": [True, False],
  22. "with_ffmpeg": [True, False],
  23. "with_luajit": [True, False],
  24. }
  25. default_options = {
  26. "default_options_of_requirements": False,
  27. "with_apple_system_libs": False,
  28. "with_ffmpeg": True,
  29. "with_luajit": False,
  30. "boost/*:shared": True,
  31. "minizip/*:shared": True,
  32. "onetbb/*:shared": True,
  33. }
  34. def configure(self):
  35. # SDL_image and Qt depend on it, in iOS both are static
  36. self.options["libpng"].shared = self.settings.os != "iOS"
  37. # static Qt for iOS is the only viable option at the moment
  38. self.options["qt"].shared = self.settings.os != "iOS"
  39. if self.options.default_options_of_requirements:
  40. return
  41. # we need only the following Boost parts:
  42. # date_time filesystem locale program_options system thread
  43. # some other parts are also enabled because they're dependents
  44. # see e.g. conan-center-index/recipes/boost/all/dependencies
  45. self.options["boost"].without_context = True
  46. self.options["boost"].without_contract = True
  47. self.options["boost"].without_coroutine = True
  48. self.options["boost"].without_fiber = True
  49. self.options["boost"].without_graph = True
  50. self.options["boost"].without_graph_parallel = True
  51. self.options["boost"].without_iostreams = True
  52. self.options["boost"].without_json = True
  53. self.options["boost"].without_log = True
  54. self.options["boost"].without_math = True
  55. self.options["boost"].without_mpi = True
  56. self.options["boost"].without_nowide = True
  57. self.options["boost"].without_python = True
  58. self.options["boost"].without_random = True
  59. self.options["boost"].without_regex = True
  60. self.options["boost"].without_serialization = True
  61. self.options["boost"].without_stacktrace = True
  62. self.options["boost"].without_test = True
  63. self.options["boost"].without_timer = True
  64. self.options["boost"].without_type_erasure = True
  65. self.options["boost"].without_wave = True
  66. self.options["ffmpeg"].avdevice = False
  67. self.options["ffmpeg"].avfilter = False
  68. self.options["ffmpeg"].postproc = False
  69. self.options["ffmpeg"].swresample = False
  70. self.options["ffmpeg"].with_freetype = False
  71. self.options["ffmpeg"].with_libfdk_aac = False
  72. self.options["ffmpeg"].with_libmp3lame = False
  73. self.options["ffmpeg"].with_libvpx = False
  74. self.options["ffmpeg"].with_libwebp = False
  75. self.options["ffmpeg"].with_libx264 = False
  76. self.options["ffmpeg"].with_libx265 = False
  77. self.options["ffmpeg"].with_openh264 = False
  78. self.options["ffmpeg"].with_openjpeg = False
  79. self.options["ffmpeg"].with_opus = False
  80. self.options["ffmpeg"].with_programs = False
  81. self.options["ffmpeg"].with_ssl = False
  82. self.options["ffmpeg"].with_vorbis = False
  83. self.options["sdl"].sdl2main = self.settings.os != "iOS"
  84. self.options["sdl"].vulkan = False
  85. self.options["sdl_image"].lbm = False
  86. self.options["sdl_image"].pnm = False
  87. self.options["sdl_image"].svg = False
  88. self.options["sdl_image"].tga = False
  89. self.options["sdl_image"].with_libjpeg = False
  90. self.options["sdl_image"].with_libtiff = False
  91. self.options["sdl_image"].with_libwebp = False
  92. self.options["sdl_image"].xcf = False
  93. self.options["sdl_image"].xpm = False
  94. self.options["sdl_image"].xv = False
  95. if is_apple_os(self):
  96. self.options["sdl_image"].imageio = True
  97. self.options["sdl_mixer"].flac = False
  98. self.options["sdl_mixer"].mad = False
  99. self.options["sdl_mixer"].mikmod = False
  100. self.options["sdl_mixer"].modplug = False
  101. self.options["sdl_mixer"].nativemidi = False
  102. self.options["sdl_mixer"].opus = False
  103. self.options["sdl_mixer"].wav = False
  104. def _disableQtOptions(disableFlag, options):
  105. return " ".join([f"-{disableFlag}-{tool}" for tool in options])
  106. _qtOptions = [
  107. _disableQtOptions("no", [
  108. "gif",
  109. "ico",
  110. ]),
  111. _disableQtOptions("no-feature", [
  112. # xpm format is required for Drag'n'Drop support
  113. "imageformat_bmp",
  114. "imageformat_jpeg",
  115. "imageformat_ppm",
  116. "imageformat_xbm",
  117. # we need only macdeployqt
  118. # TODO: disabling these doesn't disable generation of CMake targets
  119. # TODO: in Qt 6.3 it's a part of qtbase
  120. # "assistant",
  121. # "designer",
  122. # "distancefieldgenerator",
  123. # "kmap2qmap",
  124. # "linguist",
  125. # "makeqpf",
  126. # "pixeltool",
  127. # "qdbus",
  128. # "qev",
  129. # "qtattributionsscanner",
  130. # "qtdiag",
  131. # "qtpaths",
  132. # "qtplugininfo",
  133. ]),
  134. ]
  135. self.options["qt"].config = " ".join(_qtOptions)
  136. self.options["qt"].qttools = True
  137. self.options["qt"].with_freetype = False
  138. self.options["qt"].with_libjpeg = False
  139. self.options["qt"].with_md4c = False
  140. self.options["qt"].with_mysql = False
  141. self.options["qt"].with_odbc = False
  142. self.options["qt"].with_openal = False
  143. self.options["qt"].with_pq = False
  144. self.options["qt"].openssl = not is_apple_os(self)
  145. if self.settings.os == "iOS":
  146. self.options["qt"].opengl = "es2"
  147. # transitive deps
  148. # doesn't link to overridden bzip2 & zlib, the tool isn't needed anyway
  149. self.options["pcre2"].build_pcre2grep = False
  150. def requirements(self):
  151. # TODO: will no longer be needed after merging https://github.com/conan-io/conan-center-index/pull/13399
  152. self.requires("libpng/[~1.6.38]", override=True) # freetype / Qt
  153. if self.options.default_options_of_requirements:
  154. self.requires("libjpeg/9e", override=True) # libtiff / Qt
  155. self.requires("freetype/[~2.12.1]", override=True) # sdl_ttf / Qt
  156. if self.options.with_ffmpeg:
  157. self.requires("libwebp/[~1.2.4]", override=True) # sdl_image / ffmpeg
  158. if self.options.with_ffmpeg:
  159. self.requires("ffmpeg/[^4.4]")
  160. # use Apple system libraries instead of external ones
  161. if self.options.with_apple_system_libs and not self.options.default_options_of_requirements and is_apple_os(self):
  162. systemLibsOverrides = [
  163. "bzip2/1.0.8",
  164. "libiconv/1.17",
  165. "sqlite3/3.39.2",
  166. "zlib/1.2.12",
  167. ]
  168. for lib in systemLibsOverrides:
  169. self.requires(f"{lib}@vcmi/apple", override=True)
  170. # TODO: the latest official release of LuaJIT (which is quite old) can't be built for arm
  171. if self.options.with_luajit and not str(self.settings.arch).startswith("arm"):
  172. self.requires("luajit/[~2.0.5]")
  173. def generate(self):
  174. tc = CMakeToolchain(self)
  175. tc.variables["USING_CONAN"] = True
  176. tc.variables["CONAN_INSTALL_FOLDER"] = self.install_folder
  177. tc.generate()
  178. deps = CMakeDeps(self)
  179. if tools.get_env("GENERATE_ONLY_BUILT_CONFIG", default=False):
  180. deps.generate()
  181. return
  182. # allow using prebuilt deps with all configs
  183. # credits to https://github.com/conan-io/conan/issues/11607#issuecomment-1188500937 for the workaround
  184. configs = [
  185. "Debug",
  186. "MinSizeRel",
  187. "Release",
  188. "RelWithDebInfo",
  189. ]
  190. for config in configs:
  191. print(f"generating CMakeDeps for {config}")
  192. deps.configuration = config
  193. deps.generate()
  194. def imports(self):
  195. self.copy("*.dylib", "Frameworks", "lib")