xmake.lua 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package("ntkernel-error-category")
  2. set_homepage("https://github.com/ned14/ntkernel-error-category")
  3. set_description("A C++ 11 std::error_category for the NT kernel's NTSTATUS error codes ")
  4. set_license("Apache-2.0")
  5. add_urls("https://github.com/ned14/ntkernel-error-category/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/ned14/ntkernel-error-category.git")
  7. add_versions("v1.0.0", "481b60ac0b1d2c179120b3e6589884217508b6b5025a25dd6bf47399aa5d2cc5")
  8. add_configs("cmake", {description = "Use cmake build system", default = true, type = "boolean"})
  9. add_configs("headeronly", {description = "Use header only version.", default = false, type = "boolean"})
  10. on_load(function (package)
  11. if package:config("cmake") then
  12. package:add("deps", "cmake")
  13. package:config_set("headeronly", false)
  14. end
  15. if package:config("headeronly") then
  16. package:set("kind", "library", {headeronly = true})
  17. package:add("defines", "NTKERNEL_ERROR_CATEGORY_INLINE")
  18. elseif not package:config("shared") then
  19. package:add("defines", "NTKERNEL_ERROR_CATEGORY_STATIC")
  20. end
  21. end)
  22. on_install(function (package)
  23. if package:config("cmake") then
  24. io.replace("CMakeLists.txt", "if(NOT PROJECT_IS_DEPENDENCY)", "if(0)", {plain = true})
  25. local configs = {"-DBUILD_TESTING=OFF"}
  26. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  27. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  28. import("package.tools.cmake").install(package, configs)
  29. if package:config("shared") then
  30. os.tryrm(package:installdir("lib/*ntkernel-error-category_sl*"))
  31. else
  32. os.tryrm(package:installdir("bin/*.dll"))
  33. os.tryrm(package:installdir("lib/*ntkernel-error-category_dl*"))
  34. end
  35. else
  36. local configs = {}
  37. if package:config("headeronly") then
  38. configs.kind = "headeronly"
  39. end
  40. os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
  41. import("package.tools.xmake").install(package, configs)
  42. end
  43. end)
  44. on_test(function (package)
  45. assert(package:check_cxxsnippets({test = [[
  46. #include <system_error>
  47. #include <ntkernel-error-category/ntkernel_category.hpp>
  48. void test () {
  49. using namespace ntkernel_error_category;
  50. std::error_code ec(static_cast<int>(0xc000003a), ntkernel_category());
  51. }
  52. ]]}, {configs = {languages = "c++17"}}))
  53. end)