From 6260b82e5f6996e749e94b71728616f704ad7776 Mon Sep 17 00:00:00 2001 From: star9029 Date: Sat, 2 Sep 2023 21:49:22 +0800 Subject: [PATCH] fruit: add package (#2545) * fruit: add package * Update xmake.lua --------- Co-authored-by: ruki --- packages/f/fruit/xmake.lua | 69 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 packages/f/fruit/xmake.lua diff --git a/packages/f/fruit/xmake.lua b/packages/f/fruit/xmake.lua new file mode 100644 index 000000000..6ab7f2357 --- /dev/null +++ b/packages/f/fruit/xmake.lua @@ -0,0 +1,69 @@ +package("fruit") + set_homepage("https://github.com/google/fruit/wiki") + set_description("Fruit, a dependency injection framework for C++") + set_license("Apache-2.0") + + add_urls("https://github.com/google/fruit/archive/refs/tags/$(version).tar.gz", + "https://github.com/google/fruit.git") + + add_versions("v3.7.0", "134d65c8e6dff204aeb771058c219dcd9a353853e30a3961a5d17a6cff434a09") + add_versions("v3.7.1", "ed4c6b7ebfbf75e14a74e21eb74ce2703b8485bfc9e660b1c36fb7fe363172d0") + + add_configs("boost", {description = "Whether to use Boost (specifically, boost::unordered_set and boost::unordered_map).If this is false, Fruit will use std::unordered_set and std::unordered_map instead (however this causes injection to be a bit slower).", default = false, type = "boolean"}) + + if is_plat("linux") then + add_syslinks("m") + end + + add_deps("cmake") + + on_load(function (package) + if package:config("boost") then + package:add("deps", "boost") + end + end) + + on_install(function (package) + local configs = {"-DFRUIT_ENABLE_COVERAGE=OFF", "-DRUN_TESTS_UNDER_VALGRIND=OFF"} + table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release")) + table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF")) + table.insert(configs, "-DFRUIT_USES_BOOST=" .. (package:config("boost") and "ON" or "OFF")) + io.replace("CMakeLists.txt", "add_subdirectory(tests)", "", {plain = true}) + import("package.tools.cmake").install(package, configs) + end) + + on_test(function (package) + assert(package:check_cxxsnippets({test = [[ + #include + class Writer { + public: + virtual void write(std::string s) = 0; + }; + + class StdoutWriter : public Writer { + public: + INJECT(StdoutWriter()) = default; + virtual void write(std::string s) override {} + }; + + class Greeter { + public: + virtual void greet() = 0; + }; + + class GreeterImpl : public Greeter { + private: + Writer* writer; + public: + INJECT(GreeterImpl(Writer* writer)) : writer(writer) {} + virtual void greet() override { + writer->write("Hello world!\n"); + } + }; + fruit::Component test() { + return fruit::createComponent() + .bind() + .bind(); + } + ]]}, {configs = {languages = "c++11"}})) + end)