xmake.lua 6.9 KB

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