xmake.lua 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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_configs("pragma_once", { description = "Use #pragma once in centurion.hpp", default = true, type = "boolean" })
  10. add_configs("debug_macros", { description = "Include debug-only logging macros, such as CENTURION_LOG_INFO", default = true, type = "boolean" })
  11. add_configs("sdl_image", { description = "Enable library components that rely on the SDL_image library", default = true, type = "boolean" })
  12. add_configs("sdl_mixer", { description = "Enable library components that rely on the SDL_mixer library", default = true, type = "boolean" })
  13. add_configs("sdl_ttf", { description = "Enable library components that rely on the SDL_ttf library", default = true, type = "boolean" })
  14. add_configs("vulkan", { description = "Enable library components related to Vulkan", default = true, type = "boolean" })
  15. add_configs("opengl", { description = "Enable library components related to OpenGL", default = true, type = "boolean" })
  16. if is_plat("wasm") then
  17. add_configs("shared", { description = "Build shared library.", default = false, type = "boolean", readonly = true })
  18. end
  19. add_includedirs("include", "include/SDL2")
  20. on_load(function (package)
  21. if package:config("shared") then
  22. package:add("deps", "libsdl", { configs = { shared = true } })
  23. else
  24. package:add("deps", "libsdl")
  25. end
  26. if not package:config("pragma_once") then
  27. package:add("defines", "CENTURION_NO_PRAGMA_ONCE")
  28. end
  29. if not package:config("debug_macros") then
  30. package:add("defines", "CENTURION_NO_DEBUG_LOG_MACROS")
  31. end
  32. if package:config("sdl_image") then
  33. if package:config("shared") then
  34. package:add("deps", "libsdl_image", { configs = { shared = true } })
  35. else
  36. package:add("deps", "libsdl_image")
  37. end
  38. else
  39. package:add("defines", "CENTURION_NO_SDL_IMAGE")
  40. end
  41. if package:config("sdl_mixer") then
  42. if package:config("shared") then
  43. package:add("deps", "libsdl_mixer", { configs = { shared = true } })
  44. else
  45. package:add("deps", "libsdl_mixer")
  46. end
  47. else
  48. package:add("defines", "CENTURION_NO_SDL_MIXER")
  49. end
  50. if package:config("sdl_ttf") then
  51. if package:config("shared") then
  52. package:add("deps", "libsdl_ttf", { configs = { shared = true } })
  53. else
  54. package:add("deps", "libsdl_ttf")
  55. end
  56. else
  57. package:add("defines", "CENTURION_NO_SDL_TTF")
  58. end
  59. if not package:config("vulkan") then
  60. package:add("defines", "CENTURION_NO_VULKAN")
  61. end
  62. if not package:config("opengl") then
  63. package:add("defines", "CENTURION_NO_OPENGL")
  64. end
  65. end)
  66. on_install("!wasm", function (package)
  67. os.cp("src/*", package:installdir("include"))
  68. end)
  69. on_test(function (package)
  70. assert(package:check_cxxsnippets({ test = [[
  71. int main() {
  72. const cen::sdl sdl;
  73. cen::window window { "Centurion" };
  74. cen::renderer renderer = window.make_renderer();
  75. window.show();
  76. window.hide();
  77. }
  78. ]] }, { configs = { languages = "c++17", defines = "SDL_MAIN_HANDLED" }, includes = "centurion.hpp" }))
  79. if package:config("sdl_image") then
  80. assert(package:check_cxxsnippets({ test = [[
  81. int main() {
  82. const cen::img img;
  83. }
  84. ]] }, { configs = { languages = "c++17", defines = "SDL_MAIN_HANDLED" }, includes = "centurion.hpp" }))
  85. end
  86. if package:config("sdl_mixer") then
  87. assert(package:check_cxxsnippets({ test = [[
  88. int main() {
  89. const cen::mix mix;
  90. }
  91. ]] }, { configs = { languages = "c++17", defines = "SDL_MAIN_HANDLED" }, includes = "centurion.hpp" }))
  92. end
  93. if package:config("sdl_ttf") then
  94. assert(package:check_cxxsnippets({ test = [[
  95. int main() {
  96. const cen::ttf ttf;
  97. }
  98. ]] }, { configs = { languages = "c++17", defines = "SDL_MAIN_HANDLED" }, includes = "centurion.hpp" }))
  99. end
  100. end)