xmake.lua 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package("libsdl_gfx")
  2. set_homepage("https://www.ferzkopp.net/wordpress/2016/01/02/sdl_gfx-sdl2_gfx/")
  3. set_description("Simple DirectMedia Layer primitives drawing library")
  4. if is_plat("windows") then
  5. set_urls("https://www.ferzkopp.net/Software/SDL2_gfx/SDL2_gfx-$(version).zip", {alias = "ferzkopp"})
  6. add_urls("https://sourceforge.net/projects/sdl2gfx/files/SDL2_gfx-$(version).tar.gz", {alias = "sourceforge"})
  7. add_versions("ferzkopp:1.0.4", "b6da07583b7fb8f4d8cee97cac9176b97a287f56a8112e22f38183ecf47b9dcb")
  8. add_versions("sourceforge:1.0.4", "63e0e01addedc9df2f85b93a248f06e8a04affa014a835c2ea34bfe34e576262")
  9. add_patches("1.0.4", path.join(os.scriptdir(), "patches", "1.0.4", "add-x64-support.patch"), "623ed5796c2771dc959ef0249b46a07762981a98dd25a534977f2614791d61a0")
  10. add_patches("1.0.4", path.join(os.scriptdir(), "patches", "1.0.4", "lrint_fix.patch"), "9fb928306fb25293720214377bff2f605f60ea26f43ea5346cf1268c504aff1a")
  11. elseif is_plat("macosx", "linux") then
  12. set_urls("https://www.ferzkopp.net/Software/SDL2_gfx/SDL2_gfx-$(version).tar.gz")
  13. add_urls("https://sourceforge.net/projects/sdl2gfx/files/SDL2_gfx-$(version).tar.gz")
  14. add_versions("1.0.4", "63e0e01addedc9df2f85b93a248f06e8a04affa014a835c2ea34bfe34e576262")
  15. end
  16. if is_plat("mingw") and is_subhost("msys") then
  17. add_extsources("pacman::SDL2_gfx")
  18. elseif is_plat("linux") then
  19. add_extsources("pacman::sdl2_gfx", "apt::libsdl2-gfx-dev")
  20. elseif is_plat("macosx") then
  21. add_extsources("brew::sdl2_gfx")
  22. end
  23. add_deps("libsdl")
  24. add_links("SDL2_gfx")
  25. add_includedirs("include", "include/SDL2")
  26. on_install("windows", function(package)
  27. import("core.tool.toolchain")
  28. local vs = tonumber(toolchain.load("msvc"):config("vs"))
  29. if vs < 2019 then
  30. raise("Your compiler is too old to use this library.")
  31. end
  32. local file_name = "SDL2_gfx.vcxproj"
  33. local content = io.readfile(file_name)
  34. content = content:gsub("%%%(AdditionalIncludeDirectories%)", package:dep("libsdl"):installdir("include", "SDL2") .. ";%%(AdditionalIncludeDirectories)")
  35. content = content:gsub("%%%(AdditionalLibraryDirectories%)", package:dep("libsdl"):installdir("lib") .. ";%%(AdditionalLibraryDirectories)")
  36. io.writefile(file_name, content)
  37. -- MSVC trick no longer required since C++11
  38. io.replace("SDL2_gfxPrimitives.c", "#if defined(_MSC_VER)", "#if 0", {plain = true})
  39. local configs = {}
  40. local arch = package:is_arch("x86") and "Win32" or "x64"
  41. local mode = package:debug() and "Debug" or "Release"
  42. table.insert(configs, "/property:Configuration=" .. mode)
  43. table.insert(configs, "/property:Platform=" .. arch)
  44. if vs >= 2022 then
  45. table.insert(configs, "/p:PlatformToolset=v143")
  46. end
  47. table.insert(configs, "-target:SDL2_gfx")
  48. import("package.tools.msbuild").build(package, configs)
  49. local build_dir = path.join(arch, mode)
  50. os.cp(path.join(build_dir, "*.lib"), package:installdir("lib"))
  51. os.cp(path.join(build_dir, "*.dll"), package:installdir("bin"))
  52. os.cp("*.h", package:installdir("include", "SDL2"))
  53. end)
  54. on_install("macosx", "linux", function (package)
  55. local configs = {}
  56. if package:config("shared") then
  57. table.insert(configs, "--enable-shared=yes")
  58. else
  59. table.insert(configs, "--enable-shared=no")
  60. end
  61. if package:is_plat("linux") and package:config("pic") ~= false then
  62. table.insert(configs, "--with-pic")
  63. end
  64. local libsdl = package:dep("libsdl")
  65. if libsdl and not libsdl:is_system() then
  66. table.insert(configs, "--with-sdl-prefix=" .. libsdl:installdir())
  67. end
  68. import("package.tools.autoconf").install(package, configs)
  69. end)
  70. on_test(function (package)
  71. assert(package:has_cfuncs("aacircleRGBA", {includes = "SDL2/SDL2_gfxPrimitives.h", configs = {defines = "SDL_MAIN_HANDLED"}}))
  72. assert(package:has_cfuncs("SDL_initFramerate", {includes = "SDL2/SDL2_framerate.h", configs = {defines = "SDL_MAIN_HANDLED"}}))
  73. assert(package:has_cfuncs("rotozoomSurface", {includes = "SDL2/SDL2_rotozoom.h", configs = {defines = "SDL_MAIN_HANDLED"}}))
  74. assert(package:has_cfuncs("SDL_imageFilterAdd", {includes = "SDL2/SDL2_imageFilter.h", configs = {defines = "SDL_MAIN_HANDLED"}}))
  75. end)