2
0

xmake.lua 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package("freetype")
  2. set_homepage("https://www.freetype.org")
  3. set_description("A freely available software library to render fonts.")
  4. set_license("BSD") -- FreeType License (FTL) is a BSD-style license
  5. add_urls("https://downloads.sourceforge.net/project/freetype/freetype2/$(version)/freetype-$(version).tar.gz",
  6. "https://download.savannah.gnu.org/releases/freetype/freetype-$(version).tar.gz", {alias="archive"})
  7. add_urls("https://gitlab.freedesktop.org/freetype/freetype.git",
  8. "https://github.com/freetype/freetype.git", {alias = "git"})
  9. add_versions("archive:2.13.3", "5c3a8e78f7b24c20b25b54ee575d6daa40007a5f4eea2845861c3409b3021747")
  10. add_versions("archive:2.13.1", "0b109c59914f25b4411a8de2a506fdd18fa8457eb86eca6c7b15c19110a92fa5")
  11. add_versions("archive:2.13.0", "a7aca0e532a276ea8d85bd31149f0a74c33d19c8d287116ef8f5f8357b4f1f80")
  12. add_versions("archive:2.12.1", "efe71fd4b8246f1b0b1b9bfca13cfff1c9ad85930340c27df469733bbb620938")
  13. add_versions("archive:2.11.1", "f8db94d307e9c54961b39a1cc799a67d46681480696ed72ecf78d4473770f09b")
  14. add_versions("archive:2.11.0", "a45c6b403413abd5706f3582f04c8339d26397c4304b78fa552f2215df64101f")
  15. add_versions("archive:2.10.4", "5eab795ebb23ac77001cfb68b7d4d50b5d6c7469247b0b01b2c953269f658dac")
  16. add_versions("archive:2.9.1", "ec391504e55498adceb30baceebd147a6e963f636eb617424bcfc47a169898ce")
  17. add_versions("git:2.13.3", "VER-2-13-3")
  18. add_versions("git:2.13.1", "VER-2-13-1")
  19. add_versions("git:2.13.0", "VER-2-13-0")
  20. add_versions("git:2.12.1", "VER-2-12-1")
  21. add_versions("git:2.12.0", "VER-2-12-0")
  22. add_versions("git:2.11.1", "VER-2-11-1")
  23. add_versions("git:2.11.0", "VER-2-11-0")
  24. add_versions("git:2.10.4", "VER-2-10-4")
  25. add_versions("git:2.9.1", "VER-2-9-1")
  26. add_patches("2.11.0", path.join(os.scriptdir(), "patches", "2.11.0", "writing_system.patch"), "3172cf1e50501fc7455d9bb04ef4d5bb35b9712bb635f217f90ae6b2f7532eef")
  27. if not is_host("windows") then
  28. add_extsources("pkgconfig::freetype2")
  29. end
  30. if is_plat("mingw") and is_subhost("msys") then
  31. add_extsources("pacman::freetype")
  32. elseif is_plat("linux") then
  33. add_extsources("pacman::freetype2", "apt::libfreetype-dev")
  34. elseif is_plat("macosx") then
  35. add_extsources("brew::freetype")
  36. end
  37. add_configs("bzip2", {description = "Support bzip2 compressed fonts", default = false, type = "boolean"})
  38. add_configs("png", {description = "Support PNG compressed OpenType embedded bitmaps", default = false, type = "boolean"})
  39. add_configs("woff2", {description = "Use Brotli library to support decompressing WOFF2 fonts", default = false, type = "boolean"})
  40. add_configs("zlib", {description = "Support reading gzip-compressed font files", default = true, type = "boolean"})
  41. add_configs("harfbuzz", {description = "Support harfbuzz", default = false, type = "boolean"})
  42. add_deps("cmake")
  43. if is_plat("windows", "mingw") and is_subhost("windows") then
  44. add_deps("pkgconf")
  45. elseif is_plat("wasm") then
  46. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  47. end
  48. add_includedirs("include/freetype2")
  49. on_load(function (package)
  50. local function add_dep(conf, pkg)
  51. if package:config(conf) then
  52. package:add("deps", pkg or conf)
  53. end
  54. end
  55. add_dep("bzip2")
  56. add_dep("zlib")
  57. add_dep("png", "libpng")
  58. add_dep("woff2", "brotli")
  59. add_dep("harfbuzz")
  60. end)
  61. on_install(function (package)
  62. local configs = {"-DCMAKE_INSTALL_LIBDIR=lib"}
  63. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  64. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  65. local function add_dep(opt)
  66. if package:config(opt.conf) then
  67. if package:version():ge("2.11.1") then
  68. table.insert(configs, "-DFT_REQUIRE_" .. opt.cmakewith .. "=ON")
  69. else
  70. table.insert(configs, "-DFT_WITH_" .. opt.cmakewith .. "=ON")
  71. end
  72. local lib = package:dep(opt.pkg or opt.conf)
  73. if lib and not lib:is_system() then
  74. local includeconf = opt.cmakeinclude or (opt.cmakewith .. "_INCLUDE_DIRS")
  75. local libconf = opt.cmakelib or (opt.cmakewith .. "_LIBRARIES")
  76. local fetchinfo = lib:fetch()
  77. if fetchinfo then
  78. table.insert(configs, "-D" .. includeconf .. "=" .. table.concat(fetchinfo.includedirs or fetchinfo.sysincludedirs, ";"))
  79. table.insert(configs, "-D" .. libconf .. "=" .. table.concat(fetchinfo.libfiles, ";"))
  80. end
  81. end
  82. else
  83. if package:version():ge("2.11.1") then
  84. table.insert(configs, "-DFT_DISABLE_" .. opt.cmakewith .. "=ON")
  85. else
  86. table.insert(configs, "-DCMAKE_DISABLE_FIND_PACKAGE_" .. (opt.cmakedisable or opt.cmakewith) .. "=ON")
  87. end
  88. end
  89. end
  90. add_dep({conf = "bzip2", cmakewith = "BZIP2", cmakedisable = "BZip2", cmakeinclude = "BZIP2_INCLUDE_DIR"})
  91. add_dep({conf = "png", pkg = "libpng", cmakewith = "PNG", cmakeinclude = "PNG_PNG_INCLUDE_DIR", cmakelib = "PNG_LIBRARY"})
  92. add_dep({conf = "woff2", pkg = "brotli", cmakewith = "BROTLI", cmakedisable = "BrotliDec", cmakeinclude = "BROTLIDEC_INCLUDE_DIRS", cmakelib = "BROTLIDEC_LIBRARIES"})
  93. add_dep({conf = "zlib", cmakewith = "ZLIB", cmakeinclude = "ZLIB_INCLUDE_DIR", cmakelib = "ZLIB_LIBRARY"})
  94. add_dep({conf = "harfbuzz", pkg = "harfbuzz", cmakewith = "HARFBUZZ", cmakedisable = "HarfBuzz", cmakeinclude = "HarfBuzz_INCLUDE_DIR", cmakelib = "HarfBuzz_LIBRARY"})
  95. import("package.tools.cmake").install(package, configs)
  96. end)
  97. on_test(function (package)
  98. assert(package:has_cfuncs("FT_Init_FreeType", {includes = {"ft2build.h", "freetype/freetype.h"}}))
  99. end)