conanfile.py 8.7 KB

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