xmake.lua 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package("libsdl3_ttf")
  2. set_homepage("https://github.com/libsdl-org/SDL_ttf/")
  3. set_description("Simple DirectMedia Layer text rendering library")
  4. set_license("zlib")
  5. if is_plat("mingw") and is_subhost("msys") then
  6. add_extsources("pacman::sdl3-ttf")
  7. elseif is_plat("linux") then
  8. add_extsources("pacman::sdl3_ttf", "apt::libsdl3-ttf-dev")
  9. elseif is_plat("macosx") then
  10. add_extsources("brew::sdl3_ttf")
  11. end
  12. add_urls("https://www.libsdl.org/projects/SDL_ttf/release/SDL3_ttf-$(version).tar.gz",
  13. "https://github.com/libsdl-org/SDL_ttf/releases/download/release-$(version)/SDL3_ttf-$(version).tar.gz", { alias = "archive" })
  14. add_urls("https://github.com/libsdl-org/SDL_ttf.git", { alias = "github" })
  15. add_versions("archive:3.2.2", "63547d58d0185c833213885b635a2c0548201cc8f301e6587c0be1a67e1e045d")
  16. add_versions("archive:3.2.0", "9a741defb7c7d6dff658d402cb1cc46c1409a20df00949e1572eb9043102eb62")
  17. add_versions("github:3.2.2", "release-3.2.2")
  18. add_versions("github:3.2.0", "release-3.2.0")
  19. add_deps("cmake", "freetype")
  20. add_configs("harfbuzz", {description = "Use harfbuzz to improve text shaping", default = false, type = "boolean"})
  21. add_configs("plutosvg", {description = "Use plutosvg for color emoji support", default = false, type = "boolean"})
  22. if is_plat("wasm") then
  23. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  24. end
  25. if on_check then
  26. on_check("android", function (package)
  27. if package:config("harfbuzz") then
  28. local ndk = package:toolchain("ndk"):config("ndkver")
  29. assert(ndk and tonumber(ndk) > 22, "package(libsdl3_ttf) dep(harfbuzz) require ndk version > 22")
  30. end
  31. end)
  32. end
  33. on_load(function (package)
  34. -- libsdl3_ttf 3.2.0 requires libsdl3 >= 3.2.6
  35. package:add("deps", "libsdl3 >=3.2.6", { configs = { shared = package:config("shared") }})
  36. if package:config("harfbuzz") then
  37. package:add("deps", "harfbuzz")
  38. end
  39. if package:config("plutosvg") then
  40. package:add("deps", "plutosvg", "plutovg")
  41. end
  42. end)
  43. on_install(function (package)
  44. local configs = {"-DSDLTTF_SAMPLES=OFF", "-DSDLTTF_VENDORED=OFF"}
  45. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  46. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  47. table.insert(configs, "-DSDLTTF_HARFBUZZ=" .. (package:config("harfbuzz") and "ON" or "OFF"))
  48. table.insert(configs, "-DSDLTTF_PLUTOSVG=" .. (package:config("plutosvg") and "ON" or "OFF"))
  49. local freetype = package:dep("freetype")
  50. if freetype then
  51. local fetchinfo = freetype:fetch()
  52. if fetchinfo then
  53. local includedirs = table.wrap(fetchinfo.includedirs or fetchinfo.sysincludedirs)
  54. if #includedirs > 0 then
  55. table.insert(configs, "-DFREETYPE_INCLUDE_DIRS=" .. table.concat(includedirs, ";"))
  56. end
  57. local libfiles = table.wrap(fetchinfo.libfiles)
  58. if #libfiles > 0 then
  59. table.insert(configs, "-DFREETYPE_LIBRARY=" .. libfiles[1])
  60. end
  61. if not freetype:config("shared") then
  62. local libfiles = {}
  63. for _, dep in ipairs(freetype:librarydeps()) do
  64. local depinfo = dep:fetch()
  65. if depinfo then
  66. table.join2(libfiles, depinfo.libfiles)
  67. end
  68. end
  69. if #libfiles > 0 then
  70. local libraries = ""
  71. for _, libfile in ipairs(libfiles) do
  72. libraries = libraries .. " " .. (libfile:gsub("\\", "/"))
  73. end
  74. io.replace("CMakeLists.txt", "target_link_libraries(${sdl3_ttf_target_name} PRIVATE Freetype::Freetype)",
  75. "target_link_libraries(${sdl3_ttf_target_name} PRIVATE Freetype::Freetype " .. libraries .. ")", {plain = true})
  76. end
  77. end
  78. end
  79. end
  80. import("package.tools.cmake").install(package, configs, {packagedeps={"plutovg"}})
  81. end)
  82. on_test(function (package)
  83. assert(package:has_cfuncs("TTF_Init", {includes = "SDL3_ttf/SDL_ttf.h"}))
  84. end)