xmake.lua 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package("libsdl_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::SDL2_ttf")
  7. elseif is_plat("linux") then
  8. add_extsources("pacman::sdl2_ttf", "apt::libsdl2-ttf-dev")
  9. elseif is_plat("macosx") then
  10. add_extsources("brew::sdl2_ttf")
  11. end
  12. add_urls("https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-$(version).zip",
  13. "https://github.com/libsdl-org/SDL_ttf/releases/download/release-$(version)/SDL2_ttf-$(version).zip")
  14. add_versions("2.20.0", "04e94fc5ecac3475ab35c1d5cf52650df691867e7e4befcc861bf982a747111a")
  15. add_versions("2.20.1", "18d81ab399c8e39adababe8918691830ba6e0d6448e5baa141ee0ddf87ede2dc")
  16. add_versions("2.20.2", "aa6256bfcffd8381a75b3a2a2384ac12109b5b148e72722a19b0ede54c4051dc")
  17. add_versions("2.22.0", "5766070145111cb047807fa3f91c2c6b81bc1008d63817e100417959b42a2484")
  18. add_patches(">=2.20.0 <=2.20.1", path.join(os.scriptdir(), "patches", "2.20.1", "cmakelists.patch"), "fe04ada62d9ed70029c0efb3c04bfec22fc7596bd6b73a567beb964e61ebd82c")
  19. add_deps("cmake", "freetype")
  20. add_includedirs("include", "include/SDL2")
  21. if is_plat("wasm") then
  22. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  23. end
  24. on_load(function (package)
  25. if package:config("shared") then
  26. package:add("deps", "libsdl", { configs = { shared = true }})
  27. else
  28. package:add("deps", "libsdl")
  29. end
  30. end)
  31. on_install(function (package)
  32. local configs = {"-DSDL2TTF_SAMPLES=OFF"}
  33. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  34. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  35. table.insert(configs, "-DSDL2TTF_VENDORED=OFF")
  36. local libsdl = package:dep("libsdl")
  37. if libsdl and not libsdl:is_system() then
  38. table.insert(configs, "-DSDL2_DIR=" .. libsdl:installdir())
  39. local fetchinfo = libsdl:fetch()
  40. if fetchinfo then
  41. for _, dir in ipairs(fetchinfo.includedirs or fetchinfo.sysincludedirs) do
  42. if os.isfile(path.join(dir, "SDL_version.h")) then
  43. table.insert(configs, "-DSDL2_INCLUDE_DIR=" .. dir)
  44. break
  45. end
  46. end
  47. for _, libfile in ipairs(fetchinfo.libfiles) do
  48. if libfile:match("SDL2%..+$") or libfile:match("SDL2-static%..+$") then
  49. table.insert(configs, "-DSDL2_LIBRARY=" .. libfile)
  50. end
  51. end
  52. end
  53. end
  54. local freetype = package:dep("freetype")
  55. if freetype then
  56. local fetchinfo = freetype:fetch()
  57. if fetchinfo then
  58. local includedirs = table.wrap(fetchinfo.includedirs or fetchinfo.sysincludedirs)
  59. if #includedirs > 0 then
  60. table.insert(configs, "-DFREETYPE_INCLUDE_DIRS=" .. table.concat(includedirs, ";"))
  61. end
  62. local libfiles = table.wrap(fetchinfo.libfiles)
  63. if #libfiles > 0 then
  64. table.insert(configs, "-DFREETYPE_LIBRARY=" .. libfiles[1])
  65. end
  66. if not freetype:config("shared") then
  67. local libfiles = {}
  68. for _, dep in ipairs(freetype:librarydeps()) do
  69. local depinfo = dep:fetch()
  70. if depinfo then
  71. table.join2(libfiles, depinfo.libfiles)
  72. end
  73. end
  74. if #libfiles > 0 then
  75. local libraries = ""
  76. for _, libfile in ipairs(libfiles) do
  77. libraries = libraries .. " " .. (libfile:gsub("\\", "/"))
  78. end
  79. io.replace("CMakeLists.txt", "target_link_libraries(SDL2_ttf PRIVATE Freetype::Freetype)",
  80. "target_link_libraries(SDL2_ttf PRIVATE Freetype::Freetype " .. libraries .. ")", {plain = true})
  81. end
  82. end
  83. end
  84. end
  85. import("package.tools.cmake").install(package, configs)
  86. end)
  87. on_test(function (package)
  88. assert(package:check_cxxsnippets({test = [[
  89. #include <SDL2/SDL.h>
  90. #include <SDL2/SDL_ttf.h>
  91. int main(int argc, char** argv) {
  92. TTF_Init();
  93. TTF_Quit();
  94. return 0;
  95. }
  96. ]]}, {configs = {defines = "SDL_MAIN_HANDLED"}}));
  97. end)