xmake.lua 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package("quickjspp")
  2. set_homepage("https://github.com/ftk/quickjspp")
  3. set_description("QuickJS C++ wrapper")
  4. add_urls("https://github.com/ftk/quickjspp.git")
  5. add_versions("2022.6.30", "e2555831d4e86486cf307d49bda803ffca9f0f43")
  6. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  7. add_includedirs("include", "include/quickjs")
  8. add_linkdirs("lib/quickjs")
  9. add_links("quickjs")
  10. add_deps("cmake")
  11. if is_plat("linux") then
  12. add_syslinks("pthread", "dl", "m")
  13. end
  14. on_install("linux", "macosx", function (package)
  15. local configs = {"-DBUILD_TESTING=OFF"}
  16. -- TODO, disable lto, maybe we need do it better
  17. io.replace("CMakeLists.txt", "set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)", "", {plain = true})
  18. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  19. table.insert(configs, "-DBUILD_TYPE=" .. (package:config("shared") and "Shared" or "Static"))
  20. import("package.tools.cmake").install(package, configs, {})
  21. end)
  22. on_test(function (package)
  23. assert(package:check_cxxsnippets({test = [[
  24. #include <iostream>
  25. void test() {
  26. using namespace qjs;
  27. Runtime runtime;
  28. Context context(runtime);
  29. auto rt = runtime.rt;
  30. auto ctx = context.ctx;
  31. js_std_init_handlers(rt);
  32. js_init_module_std(ctx, "std");
  33. js_init_module_os(ctx, "os");
  34. context.eval(R"xxx(
  35. import * as std from 'std';
  36. import * as os from 'os';
  37. globalThis.std = std;
  38. globalThis.os = os;
  39. )xxx", "<input>", JS_EVAL_TYPE_MODULE);
  40. js_std_loop(ctx);
  41. js_std_free_handlers(rt);
  42. }
  43. ]]}, {configs = {languages = "c++17"},
  44. includes = {"quickjspp.hpp","quickjs/quickjs-libc.h"}}))
  45. end)