xmake.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package("sol2")
  2. set_kind("library", {headeronly = true})
  3. set_homepage("https://github.com/ThePhD/sol2")
  4. set_description("A C++ library binding to Lua.")
  5. set_urls("https://github.com/ThePhD/sol2/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/ThePhD/sol2.git")
  7. add_versions("v3.3.1", "ad121461047d52b449aa84234a6b578fa3ed95d67d1a0703902eba72417f61bb")
  8. add_versions("v3.3.0", "b82c5de030e18cb2bcbcefcd5f45afd526920c517a96413f0b59b4332d752a1e")
  9. add_versions("v3.2.3", "f74158f92996f476786be9c9e83f8275129bb1da2a8d517d050421ac160a4b9e")
  10. add_versions("v3.2.2", "141790dae0c1821dd2dbac3595433de49ba72545845efc3ec7d88de8b0a3b2da")
  11. add_versions("v3.2.1", "b10f88dc1246f74a10348faef7d2c06e2784693307df74dcd87c4641cf6a6828")
  12. add_configs("includes_lua", {description = "Should this package includes the Lua package (set to false if you're shipping a custom Lua)", default = true, type = "boolean"})
  13. add_patches(">=3.3.0", path.join(os.scriptdir(), "patches", "3.3.0", "optional.patch"), "8440f25e5dedc29229c3def85aa6f24e0eb165d4c390fd0e1312452a569a01a6")
  14. if is_plat("mingw") and is_subhost("msys") then
  15. add_extsources("pacman::sol2")
  16. elseif is_plat("linux") then
  17. add_extsources("pacman::sol2")
  18. end
  19. add_deps("cmake")
  20. on_load(function (package)
  21. if package:config("includes_lua") then
  22. if package:version() and package:version():ge("3.3") then
  23. package:add("deps", "lua >=5.4")
  24. else
  25. package:add("deps", "lua")
  26. end
  27. end
  28. end)
  29. on_install("!wasm", function (package)
  30. local configs = {}
  31. if package:config("includes_lua") then
  32. if package:version() and package:version():ge("3.3") then
  33. table.insert(configs, "-DSOL2_BUILD_LUA=FALSE")
  34. local lua = package:dep("lua"):fetch()
  35. if lua then
  36. local includedirs = lua.includedirs or lua.sysincludedirs
  37. if includedirs and #includedirs > 0 then
  38. table.insert(configs, "-DLUA_INCLUDE_DIR=" .. table.concat(includedirs, " "))
  39. end
  40. local libfiles = lua.libfiles
  41. if libfiles then
  42. table.insert(configs, "-DLUA_LIBRARIES=" .. table.concat(libfiles, " "))
  43. end
  44. end
  45. end
  46. end
  47. import("package.tools.cmake").install(package, configs)
  48. end)
  49. on_test(function (package)
  50. if package:config("includes_lua") then
  51. assert(package:check_cxxsnippets({test = [[
  52. #include <sol/sol.hpp>
  53. #include <cassert>
  54. void test() {
  55. sol::state lua;
  56. int x = 0;
  57. lua.set_function("beep", [&x]{ ++x; });
  58. lua.script("beep()");
  59. assert(x == 1);
  60. }
  61. ]]}, {configs = {languages = "c++17"}}))
  62. end
  63. end)