xmake.lua 7.3 KB

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