xmake.lua 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package("stx")
  2. set_homepage("https://lamarrr.github.io/STX")
  3. set_description("C++17 & C++ 20 error-handling and utility extensions. ")
  4. set_license("MIT")
  5. add_urls("https://github.com/lamarrr/STX/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/lamarrr/STX.git")
  7. add_versions("v1.0.3", "0118b76a5f2a7a60132edecc9b632d9fc82a187bc232ac1a3fd9200fdd92dc7d")
  8. add_configs("backtrace", {description = "Enable stack backtraces", default = false, type = "boolean"})
  9. add_configs("custom_handler", {description = "Override the default panic behaviour by implementing a custom panic handler. The default behavior is to print the panic report and abort the program. (You can read the docs for more details)", default = false, type = "boolean"})
  10. add_configs("shared", {description = "Build shared binaries", default = false, type = "boolean", readonly = true})
  11. if is_plat("linux", "bsd") then
  12. add_syslinks("pthread")
  13. end
  14. add_deps("cmake")
  15. on_install("windows", "linux", "macosx", "bsd", "mingw", "msys", "iphoneos", "cross", function (package)
  16. local configs = {}
  17. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  18. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  19. table.insert(configs, "-DSTX_ENABLE_BACKTRACE=" .. (package:config("backtrace") and "ON" or "OFF"))
  20. table.insert(configs, "-DSTX_CUSTOM_PANIC_HANDLER=" .. (package:config("custom_handler") and "ON" or "OFF"))
  21. import("package.tools.cmake").install(package, configs)
  22. end)
  23. on_test(function (package)
  24. assert(package:check_cxxsnippets({test = [[
  25. #include <stx/option.h>
  26. using stx::Option, stx::Some, stx::None;
  27. auto safe_divide(double numerator, double denominator) -> Option<double> {
  28. if (denominator == 0.0) return None;
  29. return Some(numerator / denominator);
  30. }
  31. void test() {
  32. safe_divide(5.0, 2.0).match(
  33. [](auto value){},
  34. [](){});
  35. }
  36. ]]}, {configs = {languages = "c++17"}}))
  37. end)