xmake.lua 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package("freetype")
  2. set_homepage("https://www.freetype.org")
  3. set_description("A freely available software library to render fonts.")
  4. set_urls("https://downloads.sourceforge.net/project/freetype/freetype2/$(version)/freetype-$(version).tar.gz",
  5. "https://download.savannah.gnu.org/releases/freetype/freetype-$(version).tar.gz",
  6. "https://gitlab.freedesktop.org/freetype/freetype.git")
  7. add_versions("2.12.1", "efe71fd4b8246f1b0b1b9bfca13cfff1c9ad85930340c27df469733bbb620938")
  8. add_versions("2.11.1", "f8db94d307e9c54961b39a1cc799a67d46681480696ed72ecf78d4473770f09b")
  9. add_versions("2.11.0", "a45c6b403413abd5706f3582f04c8339d26397c4304b78fa552f2215df64101f")
  10. add_versions("2.10.4", "5eab795ebb23ac77001cfb68b7d4d50b5d6c7469247b0b01b2c953269f658dac")
  11. add_versions("2.9.1", "ec391504e55498adceb30baceebd147a6e963f636eb617424bcfc47a169898ce")
  12. add_patches("2.11.0", path.join(os.scriptdir(), "patches", "2.11.0", "writing_system.patch"), "3172cf1e50501fc7455d9bb04ef4d5bb35b9712bb635f217f90ae6b2f7532eef")
  13. if not is_host("windows") then
  14. add_extsources("pkgconfig::freetype2")
  15. end
  16. if is_plat("mingw") and is_subhost("msys") then
  17. add_extsources("pacman::freetype")
  18. elseif is_plat("linux") then
  19. add_extsources("pacman::freetype2", "apt::libfreetype-dev")
  20. elseif is_plat("macosx") then
  21. add_extsources("brew::freetype")
  22. end
  23. add_configs("bzip2", {description = "Support bzip2 compressed fonts", default = false, type = "boolean"})
  24. add_configs("png", {description = "Support PNG compressed OpenType embedded bitmaps", default = false, type = "boolean"})
  25. add_configs("woff2", {description = "Use Brotli library to support decompressing WOFF2 fonts", default = false, type = "boolean"})
  26. add_configs("zlib", {description = "Support reading gzip-compressed font files", default = false, type = "boolean"})
  27. add_deps("cmake")
  28. add_includedirs("include/freetype2")
  29. on_load(function (package)
  30. local function add_dep(conf, pkg)
  31. if package:config(conf) then
  32. package:add("deps", pkg or conf)
  33. end
  34. end
  35. add_dep("bzip2")
  36. add_dep("zlib")
  37. add_dep("png", "libpng")
  38. add_dep("woff2", "brotli")
  39. end)
  40. on_install(function (package)
  41. local configs = {"-DCMAKE_INSTALL_LIBDIR=lib"}
  42. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  43. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  44. local function add_dep(opt)
  45. if package:config(opt.conf) then
  46. table.insert(configs, "-DFT_WITH_" .. opt.cmakewith .. "=ON")
  47. local lib = package:dep(opt.pkg or opt.conf)
  48. if lib and not lib:is_system() then
  49. local includeconf = opt.cmakeinclude or (opt.cmakewith .. "_INCLUDE_DIRS")
  50. local libconf = opt.cmakelib or (opt.cmakewith .. "_LIBRARIES")
  51. local fetchinfo = lib:fetch()
  52. if fetchinfo then
  53. table.insert(configs, "-D" .. includeconf .. "=" .. table.concat(fetchinfo.includedirs or fetchinfo.sysincludedirs, ";"))
  54. table.insert(configs, "-D" .. libconf .. "=" .. table.concat(fetchinfo.libfiles, ";"))
  55. end
  56. end
  57. else
  58. table.insert(configs, "-DCMAKE_DISABLE_FIND_PACKAGE_" .. (opt.cmakedisable or opt.cmakewith) .. "=ON")
  59. end
  60. end
  61. add_dep({conf = "bzip2", cmakewith = "BZIP2", cmakedisable = "BZip2", cmakeinclude = "BZIP2_INCLUDE_DIR"})
  62. add_dep({conf = "png", pkg = "libpng", cmakewith = "PNG", cmakeinclude = "PNG_PNG_INCLUDE_DIR", cmakelib = "PNG_LIBRARY"})
  63. add_dep({conf = "woff2", pkg = "brotli", cmakewith = "BROTLI", cmakedisable = "BrotliDec", cmakeinclude = "BROTLIDEC_INCLUDE_DIRS", cmakelib = "BROTLIDEC_LIBRARIES"})
  64. add_dep({conf = "zlib", cmakewith = "ZLIB", cmakeinclude = "ZLIB_INCLUDE_DIR", cmakelib = "ZLIB_LIBRARY"})
  65. import("package.tools.cmake").install(package, configs)
  66. end)
  67. on_test(function (package)
  68. assert(package:has_cfuncs("FT_Init_FreeType", {includes = {"ft2build.h", "freetype/freetype.h"}}))
  69. end)