xmake.lua 4.3 KB

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