Repository: conan-io/conan-center-index

Issue:
Add intel-ipsec-mb recipe
**intel-ipsec-mb/1.0**

[intel-ipsec-mb](https://github.com/intel/intel-ipsec-mb) is a dependency of [DPDK](https://www.dpdk.org/) to support [AESN-NI Multi Buffer Crypto Poll Mode Driver](http://doc.dpdk.org/guides-21.05/cryptodevs/aesni_mb.html). I would like to use this dependency from conan center, which would be a little step forward towards packaging DPDK itself.

- [x] I've read the guidelines for contributing.
- [x] I've followed the PEP8 style guides for Python code in the recipes.
- [x] I've used the latest Conan client version.
- [x] I've tried at least one configuration locally with the conan-center hook activated.



Discussion:

Resolving patch:
diff --git a/recipes/intel-ipsec-mb/all/conanfile.py b/recipes/intel-ipsec-mb/all/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/intel-ipsec-mb/all/conanfile.py
@@ -0,0 +1,104 @@
+from conan import ConanFile
+from conan.errors import ConanInvalidConfiguration
+from conan.tools.files import get, copy, rmdir, apply_conandata_patches, export_conandata_patches
+from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
+from conan.tools.env import VirtualBuildEnv, Environment
+from conan.tools.microsoft import is_msvc
+import os
+
+required_conan_version = ">=1.53.0"
+
+
+class PackageConan(ConanFile):
+    name = "intel-ipsec-mb"
+    description = "Intel(R) Multi-Buffer Crypto for IPSec"
+    license = "BSD-3-Clause"
+    homepage = "https://github.com/intel/intel-ipsec-mb"
+    url = "https://github.com/conan-io/conan-center-index"
+    topics = ("intel", "ipsec", "crypto", "security")
+    package_type = "library"
+    settings = "os", "arch", "compiler", "build_type"
+    options = {
+        "shared": [True, False],
+        "fPIC": [True, False],
+    }
+    default_options = {
+        "shared": False,
+        "fPIC": True,
+    }
+
+    @property
+    def _cmake_target(self):
+        return "libIPSec_MB" if is_msvc(self) else "IPSec_MB"
+
+    @property
+    def _settings_build(self):
+        return getattr(self, "settings_build", self.settings)
+
+    def export_sources(self):
+        export_conandata_patches(self)
+
+    def config_options(self):
+        if self.settings.os == "Windows":
+            del self.options.fPIC
+
+    def configure(self):
+        if self.options.shared:
+            self.options.rm_safe("fPIC")
+        self.settings.rm_safe("compiler.libcxx")
+        self.settings.rm_safe("compiler.cppstd")
+
+    def layout(self):
+        cmake_layout(self, src_folder="src")
+
+    def validate(self):
+        if self.settings.os not in ("FreeBSD", "Linux", "Windows"):
+            raise ConanInvalidConfiguration(f"{self.ref} does not support the O.S. {self.settings.os}.")
+
+    def build_requirements(self):
+        self.tool_requires("nasm/2.15.05")
+        self.tool_requires("cmake/[>3.16 <4]")
+
+    def source(self):
+        get(self, **self.conan_data["sources"][self.version], strip_root=True)
+
+    def generate(self):
+        # INFO: Conan 1.x does not find nasm package automatically due PATH priority.
+        nasm_bin_folder = os.path.join(self.dependencies.direct_build["nasm"].package_folder, "bin").replace("\\", "/")
+        nasm_path = os.path.join(nasm_bin_folder, "nasm").replace("\\", "/")
+        env = Environment()
+        env.define("AS", nasm_path)
+        env.prepend("PATH", nasm_bin_folder)
+        envvars = env.vars(self, scope="build")
+        envvars.save_script("asm_configuration")
+
+        env = VirtualBuildEnv(self)
+        env.generate(scope="build")
+        tc = CMakeToolchain(self)
+        # INFO: intel-ipsec-mb project forces shared by default.
+        tc.cache_variables["BUILD_SHARED_LIBS"] = self.options.shared
+        # INFO: When running on Linux, uses /usr/bin/nasm in case no enforced
+        if self._settings_build.os == "Linux":
+            tc.cache_variables["CMAKE_ASM_NASM_COMPILER"] = nasm_path
+        tc.generate()
+        tc = CMakeDeps(self)
+        tc.generate()
+
+    def build(self):
+        apply_conandata_patches(self)
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.build(target=self._cmake_target)
+
+    def package(self):
+        copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
+        copy(self, "intel-ipsec-mb.h", dst=os.path.join(self.package_folder, "include"), src=os.path.join(self.source_folder, "lib"), keep_path=False)
+        cmake = CMake(self)
+        cmake.install()
+        rmdir(self, os.path.join(self.package_folder, "man"))
+        rmdir(self, os.path.join(self.package_folder, "intel-ipsec-mb"))
+
+    def package_info(self):
+        self.cpp_info.libs = [self._cmake_target]
+        if self.settings.os in ["Linux", "FreeBSD"]:
+            self.cpp_info.system_libs = ["pthread"]


Test patch:
diff --git a/recipes/intel-ipsec-mb/all/test_package/CMakeLists.txt b/recipes/intel-ipsec-mb/all/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/intel-ipsec-mb/all/test_package/CMakeLists.txt
@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.15)
+project(test_package C)
+
+find_package(intel-ipsec-mb REQUIRED CONFIG)
+
+add_executable(${PROJECT_NAME} test_package.c)
+target_link_libraries(${PROJECT_NAME} PRIVATE intel-ipsec-mb::intel-ipsec-mb)
+target_compile_features(${PROJECT_NAME} PRIVATE c_std_99)
diff --git a/recipes/intel-ipsec-mb/all/test_package/conanfile.py b/recipes/intel-ipsec-mb/all/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/intel-ipsec-mb/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", "VirtualRunEnv"
+    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, "test_package")
+            self.run(bin_path, env="conanrun")
diff --git a/recipes/intel-ipsec-mb/all/test_package/test_package.c b/recipes/intel-ipsec-mb/all/test_package/test_package.c
new file mode 100644
--- /dev/null
+++ b/recipes/intel-ipsec-mb/all/test_package/test_package.c
@@ -0,0 +1,13 @@
+#include "intel-ipsec-mb.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main() {
+    const char * version = NULL;
+
+    version = imb_get_version_str();
+    printf("Intel IPSec MB Version: %s\n", version);
+
+    return EXIT_SUCCESS;
+}