xmake.lua 5.9 KB

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