Repository: conan-io/conan-center-index

Issue:
[request] KickCAT/v2-alpha3
### Package Name/Version

KickCAT/master

### Webpage

https://github.com/Siviuze/KickCAT

### Source code

https://github.com/Siviuze/KickCAT

### Description of the library/tool

Thin EtherCAT stack designed to be embedded in a more complex software and with efficiency in mind.


Discussion:

Resolving patch:
diff --git a/recipes/kickcat/all/conanfile.py b/recipes/kickcat/all/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/kickcat/all/conanfile.py
@@ -0,0 +1,74 @@
+from conan import ConanFile
+from conan.errors import ConanInvalidConfiguration
+from conan.tools.build import check_min_cppstd
+from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout
+from conan.tools.files import get, copy
+from conan.tools.scm import Version
+import os
+
+required_conan_version = ">=1.55"
+
+
+class KickCATRecipe(ConanFile):
+    name = "kickcat"
+    url = "https://github.com/conan-io/conan-center-index"
+    homepage = "https://github.com/Siviuze/KickCAT"
+    description = "Thin EtherCAT stack designed to be embedded in a more complex software and with efficiency in mind"
+    license = "CeCILL-C"
+    topics = ("ethercat")
+    package_type = "library"
+    settings = "os", "compiler", "build_type", "arch"
+    options = {"shared": [True, False], "fPIC": [True, False]}
+    default_options = {"shared": False, "fPIC": True}
+
+    def source(self):
+        get(self, **self.conan_data["sources"][self.version], strip_root=True)
+
+    def configure(self):
+        if self.options.get_safe("shared"):
+            self.options.rm_safe("fPIC")
+
+    def layout(self):
+        cmake_layout(self, src_folder="src")
+
+    def validate(self):
+        if self.settings.compiler.get_safe("cppstd"):
+            check_min_cppstd(self, 17)
+
+        if self.settings.os != "Linux":
+            raise ConanInvalidConfiguration(
+                f"{self.ref} is not supported on {self.settings.os}.")
+
+        if self.settings.compiler != "gcc":
+            raise ConanInvalidConfiguration(
+                f"{self.ref} is not supported on {self.settings.compiler}.")
+
+        if self.settings.compiler == 'gcc' and Version(self.settings.compiler.version) < "7":
+            raise ConanInvalidConfiguration("Building requires GCC >= 7")
+
+    def generate(self):
+        tc = CMakeToolchain(self)
+        tc.cache_variables["BUILD_UNIT_TESTS"] = "OFF"
+        tc.cache_variables["BUILD_EXAMPLES"] = "OFF"
+        tc.cache_variables["BUILD_SIMULATION"] = "OFF"
+        tc.cache_variables["BUILD_TOOLS"] = "OFF"
+        tc.cache_variables["DEBUG"] = "OFF"
+        tc.generate()
+
+    def build(self):
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.build()
+
+    def package(self):
+        copy(self, "*.h", os.path.join(self.source_folder, "include"),
+             os.path.join(self.package_folder, "include"))
+        copy(self, "*.a", self.build_folder,
+             os.path.join(self.package_folder, "lib"), keep_path=False)
+        copy(self, "*.so", self.build_folder,
+             os.path.join(self.package_folder, "lib"), keep_path=False)
+        copy(self, "LICENSE", self.source_folder,
+             os.path.join(self.package_folder, "licenses"))
+
+    def package_info(self):
+        self.cpp_info.libs = ["kickcat"]


Test patch:
diff --git a/recipes/kickcat/all/test_package/CMakeLists.txt b/recipes/kickcat/all/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/kickcat/all/test_package/CMakeLists.txt
@@ -0,0 +1,9 @@
+cmake_minimum_required(VERSION 3.8)
+project(test_package LANGUAGES CXX)
+
+set(CMAKE_CXX_STANDARD 17)
+
+find_package(kickcat REQUIRED CONFIG)
+
+add_executable(${PROJECT_NAME} test_package.cc)
+target_link_libraries(${PROJECT_NAME} PRIVATE kickcat::kickcat)
diff --git a/recipes/kickcat/all/test_package/conanfile.py b/recipes/kickcat/all/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/kickcat/all/test_package/conanfile.py
@@ -0,0 +1,25 @@
+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", "VirtualRunEnv"
+
+    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/kickcat/all/test_package/test_package.cc b/recipes/kickcat/all/test_package/test_package.cc
new file mode 100644
--- /dev/null
+++ b/recipes/kickcat/all/test_package/test_package.cc
@@ -0,0 +1,32 @@
+#include "kickcat/Bus.h"
+#include "kickcat/Link.h"
+#include "kickcat/Prints.h"
+#include "kickcat/SocketNull.h"
+
+#include <iostream>
+
+using namespace kickcat;
+
+int main(int argc, char *argv[])
+{
+    std::shared_ptr<AbstractSocket> socket = std::make_shared<SocketNull>();
+    try
+    {
+        socket->open("null");
+    }
+    catch (std::exception const &e)
+    {
+        std::cerr << e.what() << std::endl;
+        return 1;
+    }
+
+    auto report_redundancy = []() {
+    };
+
+    std::shared_ptr<Link> link = std::make_shared<Link>(socket, socket, report_redundancy);
+    link->setTimeout(2ms);
+    link->checkRedundancyNeeded();
+
+    Bus bus(link);
+    return 0;
+}