2
0

xmake.lua 3.9 KB

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