conanfile.py 14 KB

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