diff --git a/recipes/hfsm2/all/conandata.yml b/recipes/hfsm2/all/conandata.yml new file mode 100644 index 0000000000000..5594813185b1e --- /dev/null +++ b/recipes/hfsm2/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "2.5.1": + url: "https://github.com/andrew-gresyk/HFSM2/archive/refs/tags/2.5.1.zip" + sha256: "77252DB9FD25BB28A6EEA2776F4397963A3B4F00437C1439FFF0484AA551A052" diff --git a/recipes/hfsm2/all/conanfile.py b/recipes/hfsm2/all/conanfile.py new file mode 100644 index 0000000000000..8db3e0f36e2c9 --- /dev/null +++ b/recipes/hfsm2/all/conanfile.py @@ -0,0 +1,43 @@ +import os + +from conan import ConanFile +from conan.tools.files import copy +from conan.tools.build import check_min_cppstd +from conan.tools.layout import basic_layout +from conan.tools.files import get + +required_conan_version = ">=1.54.0" + +class Hfsm2Conan(ConanFile): + name = "hfsm2" + description = "High-Performance Hierarchical Finite State Machine Framework" + license = "MIT" + topics = ("embedded", "fsm", "state-machine", "cpp", "modern-cpp", "game-development", + "cpp11", "embedded-systems", "template-metaprogramming", "header-only", + "mit-license", "fsm-library", "hierarchical-state-machine", "game-dev", "hfsm") + homepage = "https://hfsm.dev/" + url = "https://github.com/conan-io/conan-center-index" + + package_type = "header-library" + settings = "os", "arch", "compiler", "build_type" + no_copy_source = True + + def layout(self): + basic_layout(self, src_folder="src") + + def validate(self): + if self.settings.compiler.get_safe("cppstd"): + check_min_cppstd(self, 11) + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def package(self): + copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses")) + copy(self, "*.hpp", os.path.join(self.source_folder, "include"), os.path.join(self.package_folder, "include")) + + def package_info(self): + # For header-only packages, libdirs and bindirs are not used + # so it's necessary to set those as empty. + self.cpp_info.bindirs = [] + self.cpp_info.libdirs = [] diff --git a/recipes/hfsm2/all/test_package/CMakeLists.txt b/recipes/hfsm2/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..5d6f2b429ee40 --- /dev/null +++ b/recipes/hfsm2/all/test_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(PackageTest CXX) + +find_package(hfsm2 REQUIRED CONFIG) + +add_executable(example example.cpp) +target_link_libraries(example PRIVATE hfsm2::hfsm2) +set_property(TARGET example PROPERTY CXX_STANDARD 11) diff --git a/recipes/hfsm2/all/test_package/conanfile.py b/recipes/hfsm2/all/test_package/conanfile.py new file mode 100644 index 0000000000000..e0f447388fa1b --- /dev/null +++ b/recipes/hfsm2/all/test_package/conanfile.py @@ -0,0 +1,26 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "CMakeToolchain" + test_type = "explicit" + + def requirements(self): + self.requires(self.tested_reference_str) + + def layout(self): + cmake_layout(self) + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindir, "example") + self.run(bin_path, env="conanrun") diff --git a/recipes/hfsm2/all/test_package/example.cpp b/recipes/hfsm2/all/test_package/example.cpp new file mode 100644 index 0000000000000..04ca4bd9083e9 --- /dev/null +++ b/recipes/hfsm2/all/test_package/example.cpp @@ -0,0 +1,45 @@ +#include +#include + +struct Context { + bool on = false; +}; + +using Config = hfsm2::Config + ::ContextT; + +using M = hfsm2::MachineT; + +using FSM = M::PeerRoot< + struct Off, + struct On + >; + +struct Off + : FSM::State +{ + void enter(PlanControl& control) { + control.context().on = false; + } +}; + +struct On + : FSM::State +{ + void enter(PlanControl& control) { + control.context().on = true; + } +}; + +int +main() { + Context context; + FSM::Instance machine{context}; + + machine.changeTo(); + machine.update(); + + assert(context.on == true); + + return 0; +} diff --git a/recipes/hfsm2/config.yml b/recipes/hfsm2/config.yml new file mode 100644 index 0000000000000..eab83a303df52 --- /dev/null +++ b/recipes/hfsm2/config.yml @@ -0,0 +1,3 @@ +versions: + "2.5.1": + folder: all