conanfile.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. from conan import ConanFile
  2. from conan.errors import ConanInvalidConfiguration
  3. from conan.tools.apple import is_apple_os
  4. from conan.tools.build import cross_building
  5. from conan.tools.cmake import CMakeDeps, CMakeToolchain
  6. from conans import tools
  7. required_conan_version = ">=1.51.3"
  8. class VCMI(ConanFile):
  9. settings = "os", "compiler", "build_type", "arch"
  10. _libRequires = [
  11. "boost/[^1.69]",
  12. "minizip/[~1.2.12]",
  13. ]
  14. _clientRequires = [
  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. "onetbb/[^2021.7 <2021.10]", # 2021.10+ breaks mobile builds due to added hwloc dependency
  20. "xz_utils/[>=5.2.5]", # Required for innoextract
  21. ]
  22. requires = _libRequires + _clientRequires
  23. options = {
  24. "default_options_of_requirements": [True, False],
  25. "with_apple_system_libs": [True, False],
  26. "with_ffmpeg": [True, False],
  27. "with_luajit": [True, False],
  28. }
  29. default_options = {
  30. "default_options_of_requirements": False,
  31. "with_apple_system_libs": False,
  32. "with_ffmpeg": True,
  33. "with_luajit": False,
  34. "boost/*:shared": True,
  35. "minizip/*:shared": True,
  36. }
  37. def configure(self):
  38. self.options["ffmpeg"].shared = self.settings.os == "Android" # using shared version results in less total project size on Android
  39. self.options["freetype"].shared = self.settings.os == "Android"
  40. # SDL_image and Qt depend on it, in iOS both are static
  41. # Enable static libpng due to https://github.com/conan-io/conan-center-index/issues/15440,
  42. # which leads to VCMI crashes of MinGW
  43. self.options["libpng"].shared = not (self.settings.os == "Windows" and cross_building(self)) and self.settings.os != "iOS"
  44. # static Qt for iOS is the only viable option at the moment
  45. self.options["qt"].shared = self.settings.os != "iOS"
  46. if self.settings.os == "Android":
  47. self.options["qt"].android_sdk = tools.get_env("ANDROID_HOME", default="")
  48. # TODO: enable for all platforms
  49. if self.settings.os == "Android":
  50. self.options["bzip2"].shared = True
  51. self.options["libiconv"].shared = True
  52. self.options["zlib"].shared = True
  53. if self.options.default_options_of_requirements:
  54. return
  55. # we need only the following Boost parts:
  56. # date_time filesystem iostreams locale program_options system thread
  57. # some other parts are also enabled because they're dependents
  58. # see e.g. conan-center-index/recipes/boost/all/dependencies
  59. self.options["boost"].without_context = True
  60. self.options["boost"].without_contract = True
  61. self.options["boost"].without_coroutine = True
  62. self.options["boost"].without_fiber = True
  63. self.options["boost"].without_graph = True
  64. self.options["boost"].without_graph_parallel = True
  65. self.options["boost"].without_json = True
  66. self.options["boost"].without_log = True
  67. self.options["boost"].without_math = True
  68. self.options["boost"].without_mpi = True
  69. self.options["boost"].without_nowide = True
  70. self.options["boost"].without_python = True
  71. self.options["boost"].without_serialization = True
  72. self.options["boost"].without_stacktrace = True
  73. self.options["boost"].without_test = True
  74. self.options["boost"].without_timer = True
  75. self.options["boost"].without_type_erasure = True
  76. self.options["boost"].without_wave = True
  77. self.options["ffmpeg"].disable_all_bitstream_filters = True
  78. self.options["ffmpeg"].disable_all_decoders = True
  79. self.options["ffmpeg"].disable_all_demuxers = True
  80. self.options["ffmpeg"].disable_all_encoders = True
  81. self.options["ffmpeg"].disable_all_filters = True
  82. self.options["ffmpeg"].disable_all_hardware_accelerators = True
  83. self.options["ffmpeg"].disable_all_muxers = True
  84. self.options["ffmpeg"].disable_all_parsers = True
  85. self.options["ffmpeg"].disable_all_protocols = True
  86. self.options["ffmpeg"].with_asm = False
  87. self.options["ffmpeg"].with_bzip2 = False
  88. self.options["ffmpeg"].with_freetype = False
  89. self.options["ffmpeg"].with_libaom = False
  90. self.options["ffmpeg"].with_libdav1d = False
  91. self.options["ffmpeg"].with_libiconv = False
  92. self.options["ffmpeg"].with_libmp3lame = False
  93. self.options["ffmpeg"].with_libsvtav1 = False
  94. self.options["ffmpeg"].with_libvpx = False
  95. self.options["ffmpeg"].with_libwebp = False
  96. self.options["ffmpeg"].with_libx264 = False
  97. self.options["ffmpeg"].with_libx265 = False
  98. self.options["ffmpeg"].with_lzma = True
  99. self.options["ffmpeg"].with_openh264 = False
  100. self.options["ffmpeg"].with_openjpeg = False
  101. self.options["ffmpeg"].with_opus = False
  102. self.options["ffmpeg"].with_programs = False
  103. self.options["ffmpeg"].with_sdl = False
  104. self.options["ffmpeg"].with_ssl = False
  105. self.options["ffmpeg"].with_vorbis = False
  106. self.options["ffmpeg"].with_zlib = False
  107. if self.settings.os != "Android":
  108. self.options["ffmpeg"].with_libfdk_aac = False
  109. self.options["ffmpeg"].avcodec = True
  110. self.options["ffmpeg"].avdevice = False
  111. self.options["ffmpeg"].avfilter = False
  112. self.options["ffmpeg"].avformat = True
  113. self.options["ffmpeg"].postproc = False
  114. self.options["ffmpeg"].swresample = True # For resampling of audio in 'planar' formats
  115. self.options["ffmpeg"].swscale = True # For video scaling
  116. # We want following options supported:
  117. # H3:SoD - .bik and .smk
  118. # H3:HD - ogg container / theora video / vorbis sound (not supported by vcmi at the moment, but might be supported in future)
  119. # and for mods - webm container / vp8 or vp9 video / opus sound
  120. # TODO: add av1 support for mods (requires enabling libdav1d which currently fails to build via Conan)
  121. self.options["ffmpeg"].enable_protocols = "file"
  122. self.options["ffmpeg"].enable_demuxers = "bink,binka,ogg,smacker,webm_dash_manifest"
  123. self.options["ffmpeg"].enable_parsers = "opus,vorbis,vp8,vp9,webp"
  124. self.options["ffmpeg"].enable_decoders = "bink,binkaudio_dct,binkaudio_rdft,smackaud,smacker,theora,vorbis,vp8,vp9,opus"
  125. #optionally, for testing - enable ffplay/ffprobe binaries in conan package:
  126. #if self.settings.os == "Windows":
  127. # self.options["ffmpeg"].with_programs = True
  128. # self.options["ffmpeg"].avfilter = True
  129. # self.options["ffmpeg"].with_sdl = True
  130. # self.options["ffmpeg"].enable_filters = "aresample,scale"
  131. self.options["sdl"].sdl2main = self.settings.os != "iOS"
  132. self.options["sdl"].vulkan = False
  133. self.options["sdl_image"].lbm = False
  134. self.options["sdl_image"].pnm = False
  135. self.options["sdl_image"].svg = False
  136. self.options["sdl_image"].tga = False
  137. self.options["sdl_image"].with_libjpeg = False
  138. self.options["sdl_image"].with_libtiff = False
  139. self.options["sdl_image"].with_libwebp = False
  140. self.options["sdl_image"].xcf = False
  141. self.options["sdl_image"].xpm = False
  142. self.options["sdl_image"].xv = False
  143. if is_apple_os(self):
  144. self.options["sdl_image"].imageio = True
  145. self.options["sdl_mixer"].flac = False
  146. self.options["sdl_mixer"].mad = False
  147. self.options["sdl_mixer"].mikmod = False
  148. self.options["sdl_mixer"].modplug = False
  149. self.options["sdl_mixer"].nativemidi = False
  150. self.options["sdl_mixer"].opus = False
  151. self.options["sdl_mixer"].wav = False
  152. def _disableQtOptions(disableFlag, options):
  153. return " ".join([f"-{disableFlag}-{tool}" for tool in options])
  154. _qtOptions = [
  155. _disableQtOptions("no", [
  156. "gif",
  157. "ico",
  158. ]),
  159. _disableQtOptions("no-feature", [
  160. # xpm format is required for Drag'n'Drop support
  161. "imageformat_bmp",
  162. "imageformat_jpeg",
  163. "imageformat_ppm",
  164. "imageformat_xbm",
  165. # we need only macdeployqt
  166. # TODO: disabling these doesn't disable generation of CMake targets
  167. # TODO: in Qt 6.3 it's a part of qtbase
  168. # "assistant",
  169. # "designer",
  170. # "distancefieldgenerator",
  171. # "kmap2qmap",
  172. # "linguist",
  173. # "makeqpf",
  174. # "pixeltool",
  175. # "qdbus",
  176. # "qev",
  177. # "qtattributionsscanner",
  178. # "qtdiag",
  179. # "qtpaths",
  180. # "qtplugininfo",
  181. ]),
  182. ]
  183. self.options["qt"].config = " ".join(_qtOptions)
  184. self.options["qt"].qttools = True
  185. self.options["qt"].qtandroidextras = self.settings.os == "Android" # TODO: in Qt 6 it's part of Core
  186. self.options["qt"].with_freetype = self.settings.os == "Android"
  187. self.options["qt"].with_libjpeg = False
  188. self.options["qt"].with_md4c = False
  189. self.options["qt"].with_mysql = False
  190. self.options["qt"].with_odbc = False
  191. self.options["qt"].with_openal = False
  192. self.options["qt"].with_pq = False
  193. self.options["qt"].openssl = not is_apple_os(self)
  194. if self.settings.os == "iOS" or self.settings.os == "Android":
  195. self.options["qt"].opengl = "es2"
  196. if not is_apple_os(self) and self.settings.os != "Android" and cross_building(self):
  197. self.options["qt"].cross_compile = self.env["CONAN_CROSS_COMPILE"]
  198. # TODO: add for all platforms after updating recipe
  199. if self.settings.os == "Android":
  200. self.options["qt"].essential_modules = False
  201. # No Qt OpenGL for cross-compiling for Windows, Conan does not support it
  202. if self.settings.os == "Windows" and cross_building(self):
  203. self.options["qt"].opengl = "no"
  204. # transitive deps
  205. # doesn't link to overridden bzip2 & zlib, the tool isn't needed anyway
  206. self.options["pcre2"].build_pcre2grep = False
  207. # executable not needed
  208. if self.settings.os == "Android":
  209. self.options["sqlite3"].build_executable = False
  210. def requirements(self):
  211. self.requires("freetype/[~2.12.1]", override=True) # sdl_ttf / Qt
  212. self.requires("libpng/[~1.6.39]", override=True) # freetype / qt / sdl_image
  213. # client
  214. if self.options.with_ffmpeg:
  215. self.requires("ffmpeg/[>=4.4]")
  216. # launcher
  217. if self.settings.os == "Android":
  218. self.requires("qt/[~5.15.14]")
  219. else:
  220. self.requires("qt/[~5.15.2]")
  221. # TODO: version range doesn't work in Conan v1
  222. if self.options["qt"].openssl:
  223. self.requires("openssl/1.1.1s")
  224. # use Apple system libraries instead of external ones
  225. if self.options.with_apple_system_libs and is_apple_os(self):
  226. systemLibsOverrides = [
  227. "bzip2/1.0.8",
  228. "libiconv/1.17",
  229. "sqlite3/3.39.2",
  230. "zlib/1.2.12",
  231. ]
  232. for lib in systemLibsOverrides:
  233. self.requires(f"{lib}@vcmi/apple", override=True)
  234. elif self.settings.os == "Android":
  235. self.requires("zlib/1.2.12@vcmi/android", override=True)
  236. else:
  237. self.requires("zlib/[~1.2.13]", override=True) # minizip / Qt
  238. self.requires("libiconv/[~1.17]", override=True) # ffmpeg / sdl
  239. # TODO: the latest official release of LuaJIT (which is quite old) can't be built for arm
  240. if self.options.with_luajit and not str(self.settings.arch).startswith("arm"):
  241. self.requires("luajit/[~2.0.5]")
  242. def validate(self):
  243. if self.options.with_apple_system_libs and not is_apple_os(self):
  244. raise ConanInvalidConfiguration("with_apple_system_libs is only for Apple platforms")
  245. if self.options.with_apple_system_libs and self.options.default_options_of_requirements:
  246. raise ConanInvalidConfiguration("with_apple_system_libs and default_options_of_requirements can't be True at the same time")
  247. def generate(self):
  248. tc = CMakeToolchain(self)
  249. tc.variables["USING_CONAN"] = True
  250. tc.variables["CONAN_INSTALL_FOLDER"] = self.install_folder
  251. if self.settings.os == "Android":
  252. tc.variables["CMAKE_ANDROID_API"] = str(self.settings.os.api_level)
  253. tc.variables["ANDROID_SYSROOT_LIB_SUBDIR"] = {
  254. 'armv7': 'arm-linux-androideabi',
  255. 'armv8': 'aarch64-linux-android',
  256. 'x86': 'i686-linux-android',
  257. 'x86_64': 'x86_64-linux-android',
  258. }.get(str(self.settings.arch))
  259. if cross_building(self) and self.settings.os == "Windows":
  260. tc.variables["CONAN_SYSTEM_LIBRARY_LOCATION"] = self.env["CONAN_SYSTEM_LIBRARY_LOCATION"]
  261. tc.generate()
  262. deps = CMakeDeps(self)
  263. if tools.get_env("GENERATE_ONLY_BUILT_CONFIG", default=False):
  264. deps.generate()
  265. return
  266. # allow using prebuilt deps with all configs
  267. # credits to https://github.com/conan-io/conan/issues/11607#issuecomment-1188500937 for the workaround
  268. configs = [
  269. "Debug",
  270. "MinSizeRel",
  271. "Release",
  272. "RelWithDebInfo",
  273. ]
  274. for config in configs:
  275. print(f"generating CMakeDeps for {config}")
  276. deps.configuration = config
  277. deps.generate()
  278. def imports(self):
  279. if is_apple_os(self):
  280. self.copy("*.dylib", "Frameworks", "lib")
  281. elif self.settings.os == "Windows":
  282. self.copy("*.dll", src="bin/archdatadir/plugins/platforms", dst="platforms")
  283. self.copy("*.dll", src="bin/archdatadir/plugins/styles", dst="styles")
  284. self.copy("*.dll", src="@bindirs", dst="", excludes="archdatadir/*")
  285. elif self.settings.os == "Android":
  286. self.copy("*.so", ".", "lib")