xmake.lua 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package("minifb")
  2. set_homepage("https://github.com/emoon/minifb")
  3. set_description("MiniFB is a small cross platform library to create a frame buffer that you can draw pixels in")
  4. set_license("MIT")
  5. add_urls("https://github.com/emoon/minifb.git")
  6. add_versions("2023.09.21", "2ce2449b1bc8d7c6d20c31b86244f1e540f2e788")
  7. add_deps("cmake")
  8. if is_plat("macosx") then
  9. add_frameworks("Cocoa", "QuartzCore", "Metal", "MetalKit")
  10. elseif is_plat("iphoneos") then
  11. add_frameworks("UIKit", "QuartzCore", "Metal", "MetalKit")
  12. elseif is_plat("linux", "bsd") then
  13. add_deps("libx11", "libxkbcommon")
  14. add_deps("glx", "opengl", {optional = true})
  15. elseif is_plat("windows", "mingw") then
  16. add_syslinks("gdi32", "opengl32", "user32", "winmm")
  17. end
  18. if on_check then
  19. on_check("windows|arm64", function (package)
  20. local vs_toolset = package:toolchain("msvc"):config("vs_toolset")
  21. if vs_toolset then
  22. local vs_toolset_ver = import("core.base.semver").new(vs_toolset)
  23. local minor = vs_toolset_ver:minor()
  24. assert(minor and minor >= 30, "package(minifb) require vs_toolset >= 14.3")
  25. end
  26. end)
  27. end
  28. on_install("!android and !cross and !bsd", function (package)
  29. if package:is_plat("windows") then
  30. io.replace("CMakeLists.txt", "add_definitions(-D_DEBUG)", "", {plain = true}) -- fix M[D|T]d
  31. end
  32. io.replace("CMakeLists.txt", "STATIC", "", {plain = true})
  33. io.replace("CMakeLists.txt", 'set(CMAKE_C_FLAGS "")', "", {plain = true})
  34. io.replace("CMakeLists.txt", 'set(CMAKE_CXX_FLAGS "")', "", {plain = true})
  35. local configs = {"-DMINIFB_BUILD_EXAMPLES=OFF"}
  36. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  37. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  38. if package:config("shared") and package:is_plat("windows") then
  39. table.insert(configs, "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON")
  40. end
  41. local opt = {}
  42. if package:is_plat("linux", "bsd") then
  43. opt.packagedeps = {"libx11", "libxkbcommon", "glx", "opengl"}
  44. end
  45. import("package.tools.cmake").install(package, configs, opt)
  46. if package:is_plat("windows") and package:is_debug() then
  47. local dir = package:installdir(package:config("shared") and "bin" or "lib")
  48. os.trycp(path.join(package:buildir(), "minifb.pdb"), dir)
  49. end
  50. end)
  51. on_test(function (package)
  52. assert(package:has_cfuncs("mfb_update_ex", {includes = "MiniFB.h"}))
  53. end)