|
| 1 | +package("fruit") |
| 2 | + set_homepage("https://github.com/google/fruit/wiki") |
| 3 | + set_description("Fruit, a dependency injection framework for C++") |
| 4 | + set_license("Apache-2.0") |
| 5 | + |
| 6 | + add_urls("https://github.com/google/fruit/archive/refs/tags/$(version).tar.gz", |
| 7 | + "https://github.com/google/fruit.git") |
| 8 | + |
| 9 | + add_versions("v3.7.0", "134d65c8e6dff204aeb771058c219dcd9a353853e30a3961a5d17a6cff434a09") |
| 10 | + add_versions("v3.7.1", "ed4c6b7ebfbf75e14a74e21eb74ce2703b8485bfc9e660b1c36fb7fe363172d0") |
| 11 | + |
| 12 | + 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"}) |
| 13 | + |
| 14 | + if is_plat("linux") then |
| 15 | + add_syslinks("m") |
| 16 | + end |
| 17 | + |
| 18 | + add_deps("cmake") |
| 19 | + |
| 20 | + on_load(function (package) |
| 21 | + if package:config("boost") then |
| 22 | + package:add("deps", "boost") |
| 23 | + end |
| 24 | + end) |
| 25 | + |
| 26 | + on_install(function (package) |
| 27 | + local configs = {"-DFRUIT_ENABLE_COVERAGE=OFF", "-DRUN_TESTS_UNDER_VALGRIND=OFF"} |
| 28 | + table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release")) |
| 29 | + table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF")) |
| 30 | + table.insert(configs, "-DFRUIT_USES_BOOST=" .. (package:config("boost") and "ON" or "OFF")) |
| 31 | + io.replace("CMakeLists.txt", "add_subdirectory(tests)", "", {plain = true}) |
| 32 | + import("package.tools.cmake").install(package, configs) |
| 33 | + end) |
| 34 | + |
| 35 | + on_test(function (package) |
| 36 | + assert(package:check_cxxsnippets({test = [[ |
| 37 | + #include <fruit/fruit.h> |
| 38 | + class Writer { |
| 39 | + public: |
| 40 | + virtual void write(std::string s) = 0; |
| 41 | + }; |
| 42 | +
|
| 43 | + class StdoutWriter : public Writer { |
| 44 | + public: |
| 45 | + INJECT(StdoutWriter()) = default; |
| 46 | + virtual void write(std::string s) override {} |
| 47 | + }; |
| 48 | +
|
| 49 | + class Greeter { |
| 50 | + public: |
| 51 | + virtual void greet() = 0; |
| 52 | + }; |
| 53 | +
|
| 54 | + class GreeterImpl : public Greeter { |
| 55 | + private: |
| 56 | + Writer* writer; |
| 57 | + public: |
| 58 | + INJECT(GreeterImpl(Writer* writer)) : writer(writer) {} |
| 59 | + virtual void greet() override { |
| 60 | + writer->write("Hello world!\n"); |
| 61 | + } |
| 62 | + }; |
| 63 | + fruit::Component<Greeter> test() { |
| 64 | + return fruit::createComponent() |
| 65 | + .bind<Writer, StdoutWriter>() |
| 66 | + .bind<Greeter, GreeterImpl>(); |
| 67 | + } |
| 68 | + ]]}, {configs = {languages = "c++11"}})) |
| 69 | + end) |
0 commit comments