xmake.lua 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. package("skia")
  2. set_homepage("https://skia.org/")
  3. set_description("A complete 2D graphic library for drawing Text, Geometries, and Images.")
  4. set_license("BSD-3-Clause")
  5. local commits = {
  6. ["88"] = "158dc9d7d4cafb177b99b68c5dc502f8f4282092",
  7. ["89"] = "109bfc9052ce1bde7acf07321d605601d7b7ec24",
  8. ["90"] = "adbb69cd7fe4e1c321e1526420e30265655e809c",
  9. ["132"] = "07f41bcb8ee32fd84ae845095d49055d5122e606",
  10. }
  11. add_urls("https://github.com/google/skia/archive/$(version).zip", {version = function (version) return commits[tostring(version)] end})
  12. add_versions("88", "3334fd7d0705e803fe2dd606a2a7d67cc428422a3e2ba512deff84a4bc5c48fa")
  13. add_versions("89", "b4c8260ad7d1a60e0382422d76ea6174fc35ce781b01030068fcad08364dd334")
  14. add_versions("90", "5201386a026d1dd55e662408acf9df6ff9d8c1df24ef6a5b3d51b006b516ac90")
  15. add_versions("132", "1246975f106a2fc98a167bf5d56053a6e8618e42db0394228c6f152daa298116")
  16. local components = {"gpu", "pdf", "nvpr"}
  17. for _, component in ipairs(components) do
  18. add_configs(component, {description = "Enable " .. component .. " support.", default = true, type = "boolean"})
  19. end
  20. if is_plat("windows") then
  21. add_syslinks("gdi32", "user32", "opengl32")
  22. elseif is_plat("macosx") then
  23. add_frameworks("CoreFoundation", "CoreGraphics", "CoreText", "CoreServices")
  24. elseif is_plat("linux") then
  25. add_syslinks("pthread", "GL", "dl", "rt")
  26. end
  27. add_includedirs("include", "include/..", "include/ports")
  28. add_links("skia")
  29. add_deps("gn", "python", "ninja", {kind = "binary"})
  30. if is_plat("linux") then
  31. add_deps("fontconfig", "freetype >=2.10")
  32. end
  33. if on_check then
  34. on_check(function (package)
  35. if package:is_cross() then
  36. raise("package(skia) unsupported cross-compilation now.")
  37. end
  38. end)
  39. end
  40. on_install("macosx", "linux|!arm64", "windows|!arm64", function (package)
  41. local args = {is_official_build = false,
  42. is_component_build = false,
  43. is_debug = package:is_debug(),
  44. is_shared_library = package:config("shared"),
  45. skia_enable_tools = false,
  46. skia_use_icu = false,
  47. skia_use_sfntly = true,
  48. skia_use_piex = true,
  49. skia_use_freetype = true,
  50. skia_use_system_freetype2 = package:is_plat("linux") and true or false,
  51. skia_use_harfbuzz = true,
  52. skia_use_libheif = true,
  53. skia_use_expat = true,
  54. skia_use_libjpeg_turbo_decode = true,
  55. skia_use_libjpeg_turbo_encode = true,
  56. skia_use_libpng_decode = true,
  57. skia_use_libpng_encode = true,
  58. skia_use_libwebp_decode = true,
  59. skia_use_libwebp_encode = true,
  60. skia_use_zlib = true}
  61. for _, component in ipairs(components) do
  62. args["skia_enable_" .. component] = package:config(component)
  63. end
  64. if package:is_arch("x86") then
  65. args.target_cpu = "x86"
  66. elseif package:is_arch("x64") then
  67. args.target_cpu = "x64"
  68. elseif package:is_arch("arm64") then
  69. args.target_cpu = "arm64"
  70. end
  71. if not package:is_plat("windows") then
  72. args.cc = package:build_getenv("cc")
  73. args.cxx = package:build_getenv("cxx")
  74. else
  75. args.extra_cflags = {
  76. "/" .. package:runtimes()
  77. }
  78. end
  79. if package:is_plat("macosx") then
  80. args.extra_ldflags = {"-lstdc++"}
  81. local xcode = import("core.tool.toolchain").load("xcode", {plat = package:plat(), arch = package:arch()})
  82. args.xcode_sysroot = xcode:config("xcode_sysroot")
  83. end
  84. -- fix symbol lookup error: /lib64/libk5crypto.so.3: undefined symbol: EVP_KDF_ctrl, version OPENSSL_1_1_1b
  85. local LD_LIBRARY_PATH
  86. if package:is_plat("linux") and linuxos.name() == "fedora" then
  87. LD_LIBRARY_PATH = os.getenv("LD_LIBRARY_PATH")
  88. if LD_LIBRARY_PATH then
  89. local libdir = os.arch() == "x86_64" and "/usr/lib64" or "/usr/lib"
  90. LD_LIBRARY_PATH = libdir .. ":" .. LD_LIBRARY_PATH
  91. end
  92. end
  93. -- patches
  94. io.replace("bin/fetch-gn", "import os\n", "import os\nimport ssl\nssl._create_default_https_context = ssl._create_unverified_context\n", {plain = true})
  95. os.vrunv("python", {"tools/git-sync-deps"}, {
  96. envs = {
  97. LD_LIBRARY_PATH = LD_LIBRARY_PATH,
  98. HTTP_PROXY = os.getenv("HTTP_PROXY"),
  99. HTTPS_PROXY = os.getenv("HTTPS_PROXY"),
  100. }})
  101. local skia_gn = "gn/skia/BUILD.gn"
  102. if not os.exists(skia_gn) then
  103. skia_gn = "gn/BUILD.gn"
  104. end
  105. io.replace(skia_gn, "libs += [ \"pthread\" ]", "libs += [ \"pthread\", \"m\", \"stdc++\" ]", {plain = true})
  106. io.replace("gn/toolchain/BUILD.gn", "$shell $win_sdk/bin/SetEnv.cmd /x86 && ", "", {plain = true})
  107. io.replace("third_party/externals/dng_sdk/source/dng_pthread.cpp", "auto_ptr", "unique_ptr", {plain = true})
  108. io.replace("BUILD.gn", 'executable%("skia_c_api_example"%) {.-}', "")
  109. -- set deps flags
  110. local cflags = {}
  111. local ldflags = {}
  112. if package:is_plat("linux") then
  113. for _, depname in ipairs({"fontconfig", "freetype"}) do
  114. local fetchinfo = package:dep(depname):fetch()
  115. if fetchinfo then
  116. for _, includedir in ipairs(fetchinfo.includedirs or fetchinfo.sysincludedirs) do
  117. table.insert(cflags, "-I" .. includedir)
  118. end
  119. for _, linkdir in ipairs(fetchinfo.linkdirs) do
  120. table.insert(ldflags, "-L" .. linkdir)
  121. end
  122. for _, link in ipairs(fetchinfo.links) do
  123. table.insert(ldflags, "-l" .. link)
  124. end
  125. end
  126. end
  127. end
  128. if #cflags > 0 then
  129. io.replace(skia_gn, "cflags = []", 'cflags = ["' .. table.concat(cflags, '", "') .. '"]', {plain = true})
  130. end
  131. if #ldflags > 0 then
  132. io.replace(skia_gn, "ldflags = []", 'ldflags = ["' .. table.concat(ldflags, '", "') .. '"]', {plain = true})
  133. end
  134. -- installation
  135. import("package.tools.gn").build(package, args, {buildir = "out"})
  136. os.mv("include", package:installdir())
  137. os.cd("out")
  138. os.rm("obj")
  139. os.rm("*.ninja")
  140. os.rm("*.ninja*")
  141. os.rm("*.gn")
  142. if package:is_plat("windows") then
  143. os.mv("*.lib", package:installdir("lib"))
  144. os.trymv("*.dll", package:installdir("bin"))
  145. os.mv("*.exe", package:installdir("bin"))
  146. else
  147. os.mv("*.a", package:installdir("lib"))
  148. os.trymv("*.so", package:installdir("lib"))
  149. os.trymv("*.dylib", package:installdir("lib"))
  150. os.trymv("*", package:installdir("bin"))
  151. end
  152. end)
  153. on_test(function (package)
  154. assert(package:check_cxxsnippets({test = [[
  155. void test() {
  156. SkPaint paint;
  157. paint.setStyle(SkPaint::kFill_Style);
  158. }
  159. ]]}, {configs = {languages = "c++17"}, includes = "core/SkPaint.h"}))
  160. end)