Repository: conan-io/conan-center-index

Issue:
[request] entt/3.2.2
### Package Details
  * Package Name/Version: **entt/3.2.2**
  * Website: **https://github.com/skypjack/entt**
  * Source code: **https://github.com/skypjack/entt**


### Description Of The Library / Tool
Gaming meets modern C++ - a fast and reliable entity-component system (ECS) and much more

CC @skypjack


Discussion:

Resolving patch:
diff --git a/recipes/entt/3.x.x/conanfile.py b/recipes/entt/3.x.x/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/entt/3.x.x/conanfile.py
@@ -0,0 +1,85 @@
+import os
+
+from conans import ConanFile, CMake, tools
+from conans.errors import ConanInvalidConfiguration
+
+
+class ConanRecipe(ConanFile):
+    name = "entt"
+
+    description = "Gaming meets modern C++ - a fast and reliable entity-component system (ECS) and much more"
+    topics = ("conan," "entt", "gaming", "entity", "ecs")
+
+    homepage = "https://github.com/skypjack/entt"
+    url = "https://github.com/conan-io/conan-center-index"
+
+    license = "MIT"
+
+    settings = "os", "compiler", "build_type", "arch"
+    generators = "cmake", "cmake_find_package_multi"
+
+    @property
+    def _source_subfolder(self):
+        return "source_subfolder"
+
+    @property
+    def _build_subfolder(self):
+        return "build_subfolder"
+
+    def configure(self):
+        minimal_cpp_standard = "17"
+        if self.settings.compiler.cppstd:
+            tools.check_min_cppstd(self, minimal_cpp_standard)
+
+        minimal_version = {
+            "Visual Studio": "15.9",
+            "gcc": "7",
+            "clang": "5",
+            "apple-clang": "10"
+        }
+
+        compiler = str(self.settings.compiler)
+        if compiler not in minimal_version:
+            self.output.warn(
+                "%s recipe lacks information about the %s compiler standard version support" % (self.name, compiler))
+            self.output.warn(
+                "%s requires a compiler that supports at least C++%s" % (self.name, minimal_cpp_standard))
+            return
+
+        version = tools.Version(self.settings.compiler.version)
+        if version < minimal_version[compiler]:
+            raise ConanInvalidConfiguration(
+                "%s requires a compiler that supports at least C++%s" % (self.name, minimal_cpp_standard))
+
+    def source(self):
+        tools.get(**self.conan_data["sources"][self.version])
+        extracted_dir = "entt-" + self.version
+        os.rename(extracted_dir, self._source_subfolder)
+
+    def _configure_cmake(self):
+        cmake = CMake(self)
+        cmake.definitions["BUILD_TESTING"] = "OFF"
+        cmake.definitions["USE_LIBCPP"] = "OFF"
+        cmake.configure(
+            source_folder=self._source_subfolder,
+            build_folder=self._build_subfolder
+        )
+        return cmake
+
+    def build(self):
+        cmake = self._configure_cmake()
+        cmake.build()
+
+    def package(self):
+        self.copy(pattern="LICENSE", dst="licenses",
+                  src=self._source_subfolder)
+        cmake = self._configure_cmake()
+        cmake.install()
+        tools.rmdir(os.path.join(self.package_folder, "cmake"))
+        tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
+
+    def package_id(self):
+        self.info.header_only()
+
+    def package_info(self):
+        self.cpp_info.name = "EnTT"


Test patch:
diff --git a/recipes/entt/3.x.x/test_package/CMakeLists.txt b/recipes/entt/3.x.x/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/entt/3.x.x/test_package/CMakeLists.txt
@@ -0,0 +1,15 @@
+cmake_minimum_required(VERSION 3.5)
+project(test_package)
+
+set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
+set(CMAKE_VERBOSE_MAKEFILE TRUE)
+
+include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+conan_output_dirs_setup()
+
+find_package(EnTT REQUIRED CONFIG)
+
+add_executable(${PROJECT_NAME} example.cpp)
+target_link_libraries(${PROJECT_NAME} EnTT::EnTT)
diff --git a/recipes/entt/3.x.x/test_package/conanfile.py b/recipes/entt/3.x.x/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/entt/3.x.x/test_package/conanfile.py
@@ -0,0 +1,17 @@
+from conans import ConanFile, CMake, tools
+import os
+
+
+class TestPackageConan(ConanFile):
+    settings = "os", "compiler", "build_type", "arch"
+    generators = "cmake", "cmake_find_package_multi"
+
+    def build(self):
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.build()
+
+    def test(self):
+        if not tools.cross_building(self.settings):
+            bin_path = os.path.join("bin", "test_package")
+            self.run(bin_path, run_environment=True)
diff --git a/recipes/entt/3.x.x/test_package/example.cpp b/recipes/entt/3.x.x/test_package/example.cpp
new file mode 100644
--- /dev/null
+++ b/recipes/entt/3.x.x/test_package/example.cpp
@@ -0,0 +1,64 @@
+#include <entt/entt.hpp>
+#include <cstdint>
+
+struct position
+{
+    float x;
+    float y;
+};
+
+struct velocity
+{
+    float dx;
+    float dy;
+};
+
+void update(entt::registry &registry)
+{
+    auto view = registry.view<position, velocity>();
+
+    for (auto entity : view)
+    {
+        // gets only the components that are going to be used ...
+
+        auto &vel = view.get<velocity>(entity);
+
+        vel.dx = 0.;
+        vel.dy = 0.;
+
+        // ...
+    }
+}
+
+void update(std::uint64_t dt, entt::registry &registry)
+{
+    registry.view<position, velocity>().each([dt](auto &pos, auto &vel) {
+        // gets all the components of the view at once ...
+
+        pos.x += vel.dx * dt;
+        pos.y += vel.dy * dt;
+
+        // ...
+    });
+}
+
+int main()
+{
+    entt::registry registry;
+    std::uint64_t dt = 16;
+
+    for (auto i = 0; i < 10; ++i)
+    {
+        auto entity = registry.create();
+        registry.assign<position>(entity, i * 1.f, i * 1.f);
+        if (i % 2 == 0)
+        {
+            registry.assign<velocity>(entity, i * .1f, i * .1f);
+        }
+    }
+
+    update(dt, registry);
+    update(registry);
+
+    // ...
+}