diff --git a/recipes/rocket/all/conandata.yml b/recipes/rocket/all/conandata.yml new file mode 100644 index 0000000000000..03683863693df --- /dev/null +++ b/recipes/rocket/all/conandata.yml @@ -0,0 +1,10 @@ +sources: + "cci.20200603": + url: "https://github.com/tripleslash/rocket/archive/348869fcda83f8b8b521c7654f83fea07ebe7a0a.tar.gz" + sha256: "de03b9c7f9b9478cfaa60683f95a7b0773dc0929d14e510c23f53b3804cc921f" +patches: + "cci.20200603": + - patch_file: "patches/0001-fix-thread_id.patch" + patch_description: "Fix compilation on different C++ std versions" + patch_type: "backport" + patch_source: "https://github.com/tripleslash/rocket/issues/10" diff --git a/recipes/rocket/all/conanfile.py b/recipes/rocket/all/conanfile.py new file mode 100644 index 0000000000000..7e395c84d11ae --- /dev/null +++ b/recipes/rocket/all/conanfile.py @@ -0,0 +1,72 @@ +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.build import check_min_cppstd +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, load, save +from conan.tools.scm import Version +import os + +required_conan_version = ">=1.53.0" + + +class RocketConan(ConanFile): + name = "rocket" + description = "Fast single header signal/slots library for C++" + license = "DocumentRef-README.md:LicenseRef-Rocket-public-domain" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/tripleslash/rocket" + topics = ("signal-slots", "observer-pattern", "header-only") + package_type = "header-library" + settings = "os", "compiler", "build_type", "arch" + + @property + def _min_cppstd(self): + return 17 + + @property + def _compilers_minimum_version(self): + return { + "gcc": "7", + "clang": "6", + "apple-clang": "10", + "Visual Studio": "15", + "msvc": "191", + } + + def export_sources(self): + export_conandata_patches(self) + + def validate(self): + if self.settings.compiler.cppstd: + check_min_cppstd(self, self._min_cppstd) + minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False) + if minimum_version and Version(self.settings.compiler.version) < minimum_version: + raise ConanInvalidConfiguration( + f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support." + ) + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def package_id(self): + self.info.clear() + + def build(self): + apply_conandata_patches(self) + + def _extract_license(self): + readme_content = load(self, os.path.join(self.source_folder, "README.md")) + first = readme_content.find("# rocket") + last = readme_content.find("signals2).") + license_content = readme_content[first:last+len("signals2).")] + # Make sure the extracted text from README has the license type + assert license_content.find("public-domain") != -1 + save(self, os.path.join(self.package_folder, "licenses", "LICENSE"), license_content) + + def package(self): + self._extract_license() + copy(self, "rocket.hpp", self.build_folder, os.path.join(self.package_folder, "include")) + + def package_info(self): + self.cpp_info.bindirs = [] + self.cpp_info.libdirs = [] + diff --git a/recipes/rocket/all/patches/0001-fix-thread_id.patch b/recipes/rocket/all/patches/0001-fix-thread_id.patch new file mode 100644 index 0000000000000..793c870ed12dc --- /dev/null +++ b/recipes/rocket/all/patches/0001-fix-thread_id.patch @@ -0,0 +1,16 @@ +diff --git a/rocket.hpp b/rocket.hpp +index 8c4e539..47d650a 100644 +--- a/rocket.hpp ++++ b/rocket.hpp +@@ -2082,8 +2082,8 @@ namespace rocket + + bool is_queued() const ROCKET_NOEXCEPT + { +- return thread_id != std::thread::id{} +- && thread_id != std::this_thread::get_id(); ++ return !(thread_id == std::thread::id{}) ++ && !(thread_id == std::this_thread::get_id()); + } + + #ifndef ROCKET_NO_BLOCKING_CONNECTIONS + diff --git a/recipes/rocket/all/test_package/CMakeLists.txt b/recipes/rocket/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..6555535f21daa --- /dev/null +++ b/recipes/rocket/all/test_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES CXX) + +find_package(rocket REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} PRIVATE rocket::rocket) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) diff --git a/recipes/rocket/all/test_package/conanfile.py b/recipes/rocket/all/test_package/conanfile.py new file mode 100644 index 0000000000000..b4c8de77c89d8 --- /dev/null +++ b/recipes/rocket/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, cmake_layout +import os + + +class RocketTestConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv" + test_type = "explicit" + + def layout(self): + cmake_layout(self) + + def requirements(self): + self.requires(self.tested_reference_str) + + 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.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/rocket/all/test_package/test_package.cpp b/recipes/rocket/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..33702a87e060d --- /dev/null +++ b/recipes/rocket/all/test_package/test_package.cpp @@ -0,0 +1,16 @@ +#include +#include +#include + +int main() +{ + rocket::signal test; + test.connect([](int x) + { return x * 3; }); + + constexpr int value = 2; + + const auto result{test(value) == value * 3}; + std::cout << "Rocket test success: " << std::boolalpha << result << '\n'; + return result? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/recipes/rocket/config.yml b/recipes/rocket/config.yml new file mode 100644 index 0000000000000..0496cb4bde798 --- /dev/null +++ b/recipes/rocket/config.yml @@ -0,0 +1,3 @@ +versions: + "cci.20200603": + folder: "all"