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