xmake.lua 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.0", "b82c5de030e18cb2bcbcefcd5f45afd526920c517a96413f0b59b4332d752a1e")
  8. add_versions("v3.2.3", "f74158f92996f476786be9c9e83f8275129bb1da2a8d517d050421ac160a4b9e")
  9. add_versions("v3.2.2", "141790dae0c1821dd2dbac3595433de49ba72545845efc3ec7d88de8b0a3b2da")
  10. add_versions("v3.2.1", "b10f88dc1246f74a10348faef7d2c06e2784693307df74dcd87c4641cf6a6828")
  11. 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"})
  12. add_patches(">=3.3.0", path.join(os.scriptdir(), "patches", "3.3.0", "optional.patch"), "8440f25e5dedc29229c3def85aa6f24e0eb165d4c390fd0e1312452a569a01a6")
  13. if is_plat("mingw") and is_subhost("msys") then
  14. add_extsources("pacman::sol2")
  15. elseif is_plat("linux") then
  16. add_extsources("pacman::sol2")
  17. end
  18. add_deps("cmake")
  19. on_load(function (package)
  20. if package:config("includes_lua") then
  21. if package:version() and package:version():ge("3.3") then
  22. package:add("deps", "lua >=5.4")
  23. else
  24. package:add("deps", "lua")
  25. end
  26. end
  27. end)
  28. on_install("!wasm", function (package)
  29. local configs = {}
  30. if package:config("includes_lua") then
  31. if package:version() and package:version():ge("3.3") then
  32. table.insert(configs, "-DSOL2_BUILD_LUA=FALSE")
  33. local lua = package:dep("lua"):fetch()
  34. if lua then
  35. local includedirs = lua.includedirs or lua.sysincludedirs
  36. if includedirs and #includedirs > 0 then
  37. table.insert(configs, "-DLUA_INCLUDE_DIR=" .. table.concat(includedirs, " "))
  38. end
  39. local libfiles = lua.libfiles
  40. if libfiles then
  41. table.insert(configs, "-DLUA_LIBRARIES=" .. table.concat(libfiles, " "))
  42. end
  43. end
  44. end
  45. end
  46. import("package.tools.cmake").install(package, configs)
  47. end)
  48. on_test(function (package)
  49. if package:config("includes_lua") then
  50. assert(package:check_cxxsnippets({test = [[
  51. #include <sol/sol.hpp>
  52. #include <cassert>
  53. void test() {
  54. sol::state lua;
  55. int x = 0;
  56. lua.set_function("beep", [&x]{ ++x; });
  57. lua.script("beep()");
  58. assert(x == 1);
  59. }
  60. ]]}, {configs = {languages = "c++17"}}))
  61. end
  62. end)