xmake.lua 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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", submodules = false})
  15. add_versions("archive:3.2.2", "d38c2078630e015777aafa1a1ce627df4323114a920c313274346c372ba0d19d")
  16. add_versions("archive:3.2.0", "ea75fa02ab328cccdff8bf36d2ec891e445e94fa301cd0ef34c662e24d30b704")
  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 is_host("windows") then
  26. set_policy("platform.longpaths", true)
  27. end
  28. if on_check then
  29. on_check("android", function (package)
  30. if package:config("harfbuzz") then
  31. local ndk = package:toolchain("ndk"):config("ndkver")
  32. assert(ndk and tonumber(ndk) > 22, "package(libsdl3_ttf) dep(harfbuzz) require ndk version > 22")
  33. end
  34. end)
  35. end
  36. on_load(function (package)
  37. -- libsdl3_ttf 3.2.0 requires libsdl3 >= 3.2.6
  38. package:add("deps", "libsdl3 >=3.2.6", { configs = { shared = package:config("shared") }})
  39. if package:config("harfbuzz") then
  40. package:add("deps", "harfbuzz")
  41. end
  42. if package:config("plutosvg") then
  43. package:add("deps", "plutosvg", "plutovg")
  44. end
  45. end)
  46. on_install(function (package)
  47. local configs = {"-DSDLTTF_SAMPLES=OFF", "-DSDLTTF_VENDORED=OFF"}
  48. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  49. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  50. table.insert(configs, "-DSDLTTF_HARFBUZZ=" .. (package:config("harfbuzz") and "ON" or "OFF"))
  51. table.insert(configs, "-DSDLTTF_PLUTOSVG=" .. (package:config("plutosvg") and "ON" or "OFF"))
  52. local freetype = package:dep("freetype")
  53. if freetype then
  54. local fetchinfo = freetype:fetch()
  55. if fetchinfo then
  56. local includedirs = table.wrap(fetchinfo.includedirs or fetchinfo.sysincludedirs)
  57. if #includedirs > 0 then
  58. table.insert(configs, "-DFREETYPE_INCLUDE_DIRS=" .. table.concat(includedirs, ";"))
  59. end
  60. local libfiles = table.wrap(fetchinfo.libfiles)
  61. if #libfiles > 0 then
  62. table.insert(configs, "-DFREETYPE_LIBRARY=" .. libfiles[1])
  63. end
  64. if not freetype:config("shared") then
  65. local libfiles = {}
  66. for _, dep in ipairs(freetype:librarydeps()) do
  67. local depinfo = dep:fetch()
  68. if depinfo then
  69. table.join2(libfiles, depinfo.libfiles)
  70. end
  71. end
  72. if #libfiles > 0 then
  73. local libraries = ""
  74. for _, libfile in ipairs(libfiles) do
  75. libraries = libraries .. " " .. (libfile:gsub("\\", "/"))
  76. end
  77. io.replace("CMakeLists.txt", "target_link_libraries(${sdl3_ttf_target_name} PRIVATE Freetype::Freetype)",
  78. "target_link_libraries(${sdl3_ttf_target_name} PRIVATE Freetype::Freetype " .. libraries .. ")", {plain = true})
  79. end
  80. end
  81. end
  82. end
  83. import("package.tools.cmake").install(package, configs, {packagedeps={"plutovg"}})
  84. end)
  85. on_test(function (package)
  86. assert(package:has_cfuncs("TTF_Init", {includes = "SDL3_ttf/SDL_ttf.h"}))
  87. end)