xmake.lua 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package("libassert")
  2. set_homepage("https://github.com/jeremy-rifkin/libassert")
  3. set_description("The most over-engineered and overpowered C++ assertion library.")
  4. set_license("MIT")
  5. add_urls("https://github.com/jeremy-rifkin/libassert/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/jeremy-rifkin/libassert.git")
  7. add_versions("v2.0.2", "4a0b52e6523bdde0116231a67583131ea1a84bb574076fad939fc13fc7490443")
  8. add_versions("v2.0.1", "405a44c14c5e40de5b81b01538ba12ef9d7c1f57e2c29f81b929e7e179847d4c")
  9. add_versions("v2.0.0", "d4b2da2179a94637b34d18813a814531a1eceb0ddc6dd6db6098050dd638f4a1")
  10. add_versions("v1.2.2", "68206b43bc4803357ba7d366574b4631bd327c46ab76ddef6ff9366784fa6b3c")
  11. add_versions("v1.2", "332f96181f4bdbd95ef5fcd6484782ba2d89b50fd5189bc2a33fd524962f6771")
  12. add_configs("decompose", {description = "Enables expression decomposition of && and || (this prevents short circuiting)", default = false, type = "boolean"})
  13. add_configs("lowercase", {description = "Enables assert alias for ASSERT", default = false, type = "boolean"})
  14. add_configs("magic_enum", {description = "Use the MagicEnum library to print better diagnostics for enum classes", default = true, type = "boolean"})
  15. on_load(function (package)
  16. if package:config("magic_enum") then
  17. package:add("deps", "magic_enum")
  18. end
  19. package:add("deps", "cpptrace " .. (package:version():lt("2.0.0") and "<=0.4.0" or ""))
  20. end)
  21. on_install("windows", "linux", "macosx", function (package)
  22. if package:version():lt("2.0.0") then
  23. if package:config("decompose") then
  24. package:add("defines", "ASSERT_DECOMPOSE_BINARY_LOGICAL")
  25. end
  26. if package:config("lowercase") then
  27. package:add("defines", "ASSERT_LOWERCASE")
  28. end
  29. if package:config("magic_enum") then
  30. package:add("defines", "ASSERT_USE_MAGIC_ENUM")
  31. io.replace("include/assert.hpp", "../third_party/magic_enum.hpp", "magic_enum.hpp", {plain = true})
  32. end
  33. local configs = {}
  34. configs.decompose = package:config("decompose")
  35. configs.lowercase = package:config("lowercase")
  36. configs.magic_enum = package:config("magic_enum")
  37. os.cp(path.join(package:scriptdir(), "port", "v1", "xmake.lua"), "xmake.lua")
  38. import("package.tools.xmake").install(package, configs)
  39. else
  40. local configs = {
  41. "-DLIBASSERT_USE_EXTERNAL_CPPTRACE=ON",
  42. "-DLIBASSERT_USE_MAGIC_ENUM=ON",
  43. "-DLIBASSERT_BUILD_TESTING=OFF",
  44. "-DLIBASSERT_SANITIZER_BUILD=OFF",
  45. }
  46. io.replace("CMakeLists.txt", "/WX", "", {plain = true})
  47. if not package:config("shared") then
  48. package:add("defines", "LIBASSERT_STATIC_DEFINE")
  49. end
  50. if package:config("magic_enum") then
  51. package:add("defines", "LIBASSERT_USE_MAGIC_ENUM")
  52. end
  53. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  54. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  55. table.insert(configs, "-DLIBASSERT_USE_MAGIC_ENUM=" .. (package:config("magic_enum") and "ON" or "OFF"))
  56. import("package.tools.cmake").install(package, configs)
  57. end
  58. end)
  59. on_test(function (package)
  60. local includes = (package:version():lt("2.0.0") and "assert.hpp" or "libassert/assert.hpp")
  61. local opt = {configs = {languages = "c++17"}, includes = includes}
  62. if package:config("lowercase") then
  63. assert(package:check_cxxsnippets({test = [[
  64. void test() {
  65. int x = 0;
  66. assert(x != 1, "", x);
  67. }
  68. ]]}, opt))
  69. else
  70. assert(package:check_cxxsnippets({test = [[
  71. void test() {
  72. int x = 0;
  73. ASSERT(x != 1, "", x);
  74. }
  75. ]]}, opt))
  76. end
  77. end)