xmake.lua 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package("centurion")
  2. set_kind("library", { headeronly = true })
  3. set_homepage("https://github.com/albin-johansson/centurion")
  4. set_description("A modern C++ wrapper library for SDL2 in order to improve type-safety, memory safety and overall ease-of-use.")
  5. set_license("MIT")
  6. set_urls("https://github.com/albin-johansson/centurion/archive/refs/tags/$(version).tar.gz",
  7. "https://github.com/albin-johansson/centurion.git")
  8. add_versions("v7.3.0", "ad8b7c27074939fa46380a878e82c2b0365d1c4ad31b4a71bfcd5ce3ac0198e6")
  9. add_patches("v7.3.0", path.join(os.scriptdir(), "patches", "7.3.0", "fix_method_name.patch"), "2c5faf24867440e53bdabf79b4354cdbf2c79707ca9e372ba7cdd94bcb1dcc52")
  10. add_configs("pragma_once", { description = "Use #pragma once in centurion.hpp", default = true, type = "boolean" })
  11. add_configs("debug_macros", { description = "Include debug-only logging macros, such as CENTURION_LOG_INFO", default = true, type = "boolean" })
  12. add_configs("sdl_image", { description = "Enable library components that rely on the SDL_image library", default = true, type = "boolean" })
  13. add_configs("sdl_mixer", { description = "Enable library components that rely on the SDL_mixer library", default = true, type = "boolean" })
  14. add_configs("sdl_ttf", { description = "Enable library components that rely on the SDL_ttf library", default = true, type = "boolean" })
  15. add_configs("vulkan", { description = "Enable library components related to Vulkan", default = true, type = "boolean" })
  16. add_configs("opengl", { description = "Enable library components related to OpenGL", default = true, type = "boolean" })
  17. if is_plat("wasm") then
  18. add_configs("shared", { description = "Build shared library.", default = false, type = "boolean", readonly = true })
  19. end
  20. add_includedirs("include", "include/SDL2")
  21. on_load(function (package)
  22. package:add("deps", "libsdl2", { configs = { shared = package:config("shared") } })
  23. if not package:config("pragma_once") then
  24. package:add("defines", "CENTURION_NO_PRAGMA_ONCE")
  25. end
  26. if not package:config("debug_macros") then
  27. package:add("defines", "CENTURION_NO_DEBUG_LOG_MACROS")
  28. end
  29. if package:config("sdl_image") then
  30. package:add("deps", "libsdl2_image", { configs = { shared = package:config("shared") } })
  31. else
  32. package:add("defines", "CENTURION_NO_SDL_IMAGE")
  33. end
  34. if package:config("sdl_mixer") then
  35. package:add("deps", "libsdl2_mixer", { configs = { shared = package:config("shared") } })
  36. else
  37. package:add("defines", "CENTURION_NO_SDL_MIXER")
  38. end
  39. if package:config("sdl_ttf") then
  40. package:add("deps", "libsdl2_ttf", { configs = { shared = package:config("shared") } })
  41. else
  42. package:add("defines", "CENTURION_NO_SDL_TTF")
  43. end
  44. if not package:config("vulkan") then
  45. package:add("defines", "CENTURION_NO_VULKAN")
  46. end
  47. if not package:config("opengl") then
  48. package:add("defines", "CENTURION_NO_OPENGL")
  49. end
  50. end)
  51. on_install(function (package)
  52. os.cp("src/*", package:installdir("include"))
  53. end)
  54. on_test(function (package)
  55. assert(package:check_cxxsnippets({ test = [[
  56. int main() {
  57. const cen::sdl sdl;
  58. cen::window window { "Centurion" };
  59. cen::renderer renderer = window.make_renderer();
  60. window.show();
  61. window.hide();
  62. }
  63. ]] }, { configs = { languages = "c++17", defines = "SDL_MAIN_HANDLED" }, includes = "centurion.hpp" }))
  64. if package:config("sdl_image") then
  65. assert(package:check_cxxsnippets({ test = [[
  66. int main() {
  67. const cen::img img;
  68. }
  69. ]] }, { configs = { languages = "c++17", defines = "SDL_MAIN_HANDLED" }, includes = "centurion.hpp" }))
  70. end
  71. if package:config("sdl_mixer") then
  72. assert(package:check_cxxsnippets({ test = [[
  73. int main() {
  74. const cen::mix mix;
  75. }
  76. ]] }, { configs = { languages = "c++17", defines = "SDL_MAIN_HANDLED" }, includes = "centurion.hpp" }))
  77. end
  78. if package:config("sdl_ttf") then
  79. assert(package:check_cxxsnippets({ test = [[
  80. int main() {
  81. const cen::ttf ttf;
  82. }
  83. ]] }, { configs = { languages = "c++17", defines = "SDL_MAIN_HANDLED" }, includes = "centurion.hpp" }))
  84. end
  85. end)