conanfile.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. ]
  20. _nullkillerAIRequires = [
  21. "onetbb/[^2021.3]",
  22. ]
  23. requires = _libRequires + _clientRequires + _nullkillerAIRequires
  24. options = {
  25. "default_options_of_requirements": [True, False],
  26. "with_apple_system_libs": [True, False],
  27. "with_ffmpeg": [True, False],
  28. "with_luajit": [True, False],
  29. }
  30. default_options = {
  31. "default_options_of_requirements": False,
  32. "with_apple_system_libs": False,
  33. "with_ffmpeg": True,
  34. "with_luajit": False,
  35. "boost/*:shared": True,
  36. "minizip/*:shared": True,
  37. "onetbb/*:shared": True,
  38. }
  39. def configure(self):
  40. self.options["ffmpeg"].shared = self.settings.os == "Android" # using shared version results in less total project size on Android
  41. self.options["freetype"].shared = self.settings.os == "Android"
  42. # SDL_image and Qt depend on it, in iOS both are static
  43. # Enable static libpng due to https://github.com/conan-io/conan-center-index/issues/15440,
  44. # which leads to VCMI crashes of MinGW
  45. self.options["libpng"].shared = not (self.settings.os == "Windows" and cross_building(self)) and self.settings.os != "iOS"
  46. # static Qt for iOS is the only viable option at the moment
  47. self.options["qt"].shared = self.settings.os != "iOS"
  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 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_iostreams = 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_random = True
  73. self.options["boost"].without_regex = True
  74. self.options["boost"].without_serialization = True
  75. self.options["boost"].without_stacktrace = True
  76. self.options["boost"].without_test = True
  77. self.options["boost"].without_timer = True
  78. self.options["boost"].without_type_erasure = True
  79. self.options["boost"].without_wave = True
  80. self.options["ffmpeg"].avdevice = False
  81. self.options["ffmpeg"].avfilter = False
  82. self.options["ffmpeg"].postproc = False
  83. self.options["ffmpeg"].swresample = False
  84. self.options["ffmpeg"].with_asm = self.settings.os != "Android"
  85. self.options["ffmpeg"].with_freetype = False
  86. self.options["ffmpeg"].with_libfdk_aac = False
  87. self.options["ffmpeg"].with_libmp3lame = False
  88. self.options["ffmpeg"].with_libvpx = False
  89. self.options["ffmpeg"].with_libwebp = False
  90. self.options["ffmpeg"].with_libx264 = False
  91. self.options["ffmpeg"].with_libx265 = False
  92. self.options["ffmpeg"].with_openh264 = False
  93. self.options["ffmpeg"].with_openjpeg = False
  94. self.options["ffmpeg"].with_opus = False
  95. self.options["ffmpeg"].with_programs = False
  96. self.options["ffmpeg"].with_ssl = False
  97. self.options["ffmpeg"].with_vorbis = False
  98. self.options["sdl"].sdl2main = self.settings.os != "iOS"
  99. self.options["sdl"].vulkan = False
  100. self.options["sdl_image"].lbm = False
  101. self.options["sdl_image"].pnm = False
  102. self.options["sdl_image"].svg = False
  103. self.options["sdl_image"].tga = False
  104. self.options["sdl_image"].with_libjpeg = False
  105. self.options["sdl_image"].with_libtiff = False
  106. self.options["sdl_image"].with_libwebp = False
  107. self.options["sdl_image"].xcf = False
  108. self.options["sdl_image"].xpm = False
  109. self.options["sdl_image"].xv = False
  110. if is_apple_os(self):
  111. self.options["sdl_image"].imageio = True
  112. self.options["sdl_mixer"].flac = False
  113. self.options["sdl_mixer"].mad = False
  114. self.options["sdl_mixer"].mikmod = False
  115. self.options["sdl_mixer"].modplug = False
  116. self.options["sdl_mixer"].nativemidi = False
  117. self.options["sdl_mixer"].opus = False
  118. self.options["sdl_mixer"].wav = False
  119. def _disableQtOptions(disableFlag, options):
  120. return " ".join([f"-{disableFlag}-{tool}" for tool in options])
  121. _qtOptions = [
  122. _disableQtOptions("no", [
  123. "gif",
  124. "ico",
  125. ]),
  126. _disableQtOptions("no-feature", [
  127. # xpm format is required for Drag'n'Drop support
  128. "imageformat_bmp",
  129. "imageformat_jpeg",
  130. "imageformat_ppm",
  131. "imageformat_xbm",
  132. # we need only macdeployqt
  133. # TODO: disabling these doesn't disable generation of CMake targets
  134. # TODO: in Qt 6.3 it's a part of qtbase
  135. # "assistant",
  136. # "designer",
  137. # "distancefieldgenerator",
  138. # "kmap2qmap",
  139. # "linguist",
  140. # "makeqpf",
  141. # "pixeltool",
  142. # "qdbus",
  143. # "qev",
  144. # "qtattributionsscanner",
  145. # "qtdiag",
  146. # "qtpaths",
  147. # "qtplugininfo",
  148. ]),
  149. ]
  150. self.options["qt"].config = " ".join(_qtOptions)
  151. self.options["qt"].qttools = True
  152. self.options["qt"].with_freetype = self.settings.os == "Android"
  153. self.options["qt"].with_libjpeg = False
  154. self.options["qt"].with_md4c = False
  155. self.options["qt"].with_mysql = False
  156. self.options["qt"].with_odbc = False
  157. self.options["qt"].with_openal = False
  158. self.options["qt"].with_pq = False
  159. self.options["qt"].openssl = not is_apple_os(self)
  160. if self.settings.os == "iOS" or self.settings.os == "Android":
  161. self.options["qt"].opengl = "es2"
  162. if not is_apple_os(self) and self.settings.os != "Android" and cross_building(self):
  163. self.options["qt"].cross_compile = self.env["CONAN_CROSS_COMPILE"]
  164. # No Qt OpenGL for cross-compiling for Windows, Conan does not support it
  165. if self.settings.os == "Windows" and cross_building(self):
  166. self.options["qt"].opengl = "no"
  167. # transitive deps
  168. # doesn't link to overridden bzip2 & zlib, the tool isn't needed anyway
  169. self.options["pcre2"].build_pcre2grep = False
  170. def requirements(self):
  171. # TODO: will no longer be needed after merging https://github.com/conan-io/conan-center-index/pull/13399
  172. self.requires("libpng/[~1.6.38]", override=True) # freetype / Qt
  173. if self.options.default_options_of_requirements:
  174. self.requires("libjpeg/9e", override=True) # libtiff / Qt
  175. self.requires("freetype/[~2.12.1]", override=True) # sdl_ttf / Qt
  176. if self.options.with_ffmpeg:
  177. self.requires("libwebp/[~1.2.4]", override=True) # sdl_image / ffmpeg
  178. # client
  179. if self.options.with_ffmpeg:
  180. self.requires("ffmpeg/[^4.4]")
  181. # launcher
  182. if not self.settings.os == "Android":
  183. self.requires("qt/[~5.15.2]")
  184. # use Apple system libraries instead of external ones
  185. if self.options.with_apple_system_libs and is_apple_os(self):
  186. systemLibsOverrides = [
  187. "bzip2/1.0.8",
  188. "libiconv/1.17",
  189. "sqlite3/3.39.2",
  190. "zlib/1.2.12",
  191. ]
  192. for lib in systemLibsOverrides:
  193. self.requires(f"{lib}@vcmi/apple", override=True)
  194. elif self.settings.os == "Android":
  195. self.requires("zlib/1.2.12@vcmi/android", override=True)
  196. else:
  197. self.requires("zlib/[~1.2.13]", override=True) # minizip / Qt
  198. self.requires("libiconv/[~1.17]", override=True) # ffmpeg / sdl
  199. # TODO: the latest official release of LuaJIT (which is quite old) can't be built for arm
  200. if self.options.with_luajit and not str(self.settings.arch).startswith("arm"):
  201. self.requires("luajit/[~2.0.5]")
  202. def validate(self):
  203. if self.options.with_apple_system_libs and not is_apple_os(self):
  204. raise ConanInvalidConfiguration("with_apple_system_libs is only for Apple platforms")
  205. if self.options.with_apple_system_libs and self.options.default_options_of_requirements:
  206. raise ConanInvalidConfiguration("with_apple_system_libs and default_options_of_requirements can't be True at the same time")
  207. def generate(self):
  208. tc = CMakeToolchain(self)
  209. tc.variables["USING_CONAN"] = True
  210. tc.variables["CONAN_INSTALL_FOLDER"] = self.install_folder
  211. if self.settings.os == "Android":
  212. tc.variables["ANDROID_SYSROOT_LIB_SUBDIR"] = {
  213. 'armv7': 'arm-linux-androideabi',
  214. 'armv8': 'aarch64-linux-android',
  215. 'x86': 'i686-linux-android',
  216. 'x86_64': 'x86_64-linux-android',
  217. }.get(str(self.settings.arch))
  218. if cross_building(self) and self.settings.os == "Windows":
  219. tc.variables["CONAN_SYSTEM_LIBRARY_LOCATION"] = self.env["CONAN_SYSTEM_LIBRARY_LOCATION"]
  220. tc.generate()
  221. deps = CMakeDeps(self)
  222. if tools.get_env("GENERATE_ONLY_BUILT_CONFIG", default=False):
  223. deps.generate()
  224. return
  225. # allow using prebuilt deps with all configs
  226. # credits to https://github.com/conan-io/conan/issues/11607#issuecomment-1188500937 for the workaround
  227. configs = [
  228. "Debug",
  229. "MinSizeRel",
  230. "Release",
  231. "RelWithDebInfo",
  232. ]
  233. for config in configs:
  234. print(f"generating CMakeDeps for {config}")
  235. deps.configuration = config
  236. deps.generate()
  237. def imports(self):
  238. if is_apple_os(self):
  239. self.copy("*.dylib", "Frameworks", "lib")
  240. elif self.settings.os == "Windows":
  241. self.copy("*.dll", src="bin/archdatadir/plugins/platforms", dst="platforms")
  242. self.copy("*.dll", src="bin/archdatadir/plugins/styles", dst="styles")
  243. self.copy("*.dll", src="@bindirs", dst="", excludes="archdatadir/*")
  244. elif self.settings.os == "Android":
  245. self.copy("*.so", ".", "lib")