Repository: conan-io/conan-center-index

Issue:
[request] primesieve/8.0
### Package Details
  * Package Name/Version: **primesieve/8.0**
  * Website: **https://github.com/kimwalisch/primesieve**
  * Source code: **https://github.com/kimwalisch/primesieve**


### Description Of The Library / Tool
primesieve is a command-line program and C/C++ library for quickly generating prime numbers.
It is very cache efficient, it detects your CPU's L1 & L2 cache sizes and allocates its main
data structures accordingly. It is also multi-threaded by default, it uses all available CPU
cores whenever possible i.e. if sequential ordering is not required. primesieve
can generate primes and [prime k-tuplets](https://en.wikipedia.org/wiki/Prime_k-tuple)
up to 2<sup>64</sup>.

primesieve generates primes using the segmented
[sieve of Eratosthenes](https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes) with
[wheel factorization](https://en.wikipedia.org/wiki/Wheel_factorization).
This algorithm has a run time complexity of $O(n\log{\log{n}})$ operations and uses
$O(\sqrt{n})$ memory. Furthermore primesieve uses the
[bucket sieve](http://sweet.ua.pt/tos/software/prime_sieve.html)
algorithm which improves the cache efficiency when generating primes > 2<sup>32</sup>.
primesieve uses 8 bytes per sieving prime, in practice its memory usage is about
$\pi(\sqrt{n})\times 8$ bytes per thread.



Discussion:
I'm on it
I'm on it.

Resolving patch:
diff --git a/recipes/primesieve/all/conanfile.py b/recipes/primesieve/all/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/primesieve/all/conanfile.py
@@ -0,0 +1,97 @@
+from conan import ConanFile
+from conan.errors import ConanInvalidConfiguration
+from conan.tools.build import check_min_cppstd
+from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
+from conan.tools.files import get, copy, rename, rm, rmdir
+from conan.tools.microsoft import is_msvc_static_runtime, is_msvc
+from conan.tools.scm import Version
+import os
+
+
+required_conan_version = ">=1.53.0"
+
+class PrimesieveConan(ConanFile):
+    name = "primesieve"
+    description = "Fast prime number generator"
+    license = "BSD-2-Clause"
+    url = "https://github.com/conan-io/conan-center-index"
+    homepage = "https://github.com/kimwalisch/primesieve"
+    topics = ("math", "prime-numbers", "sieve-of-eratosthenes")
+    settings = "os", "arch", "compiler", "build_type"
+    options = {
+        "shared": [True, False],
+        "fPIC": [True, False],
+        "with_multiarch": [True, False],
+        "with_msvc_crt_static": [True, False],
+    }
+    default_options = {
+        "shared": False,
+        "fPIC": True,
+        "with_multiarch": True,
+        "with_msvc_crt_static": False,
+    }
+    package_type = "library"
+
+    @property
+    def _min_cppstd(self):
+        return 11
+
+    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")
+
+    def layout(self):
+        cmake_layout(self, src_folder="src")
+
+    def validate(self):
+        if self.settings.compiler.cppstd:
+            check_min_cppstd(self, self._min_cppstd)
+        
+        if self.settings.compiler == "gcc" and Version(self.settings.compiler.version) <= "5":
+            raise ConanInvalidConfiguration("GCC<=5 is currently not supported. Contributions with fixes are welcome.")
+
+    def source(self):
+        get(self, **self.conan_data["sources"][self.version], strip_root=True)
+
+    def generate(self):
+        tc = CMakeToolchain(self)
+        tc.variables["BUILD_PRIMESIEVE"] = False
+        tc.variables["BUILD_DOC"] = False
+        tc.variables["BUILD_EXAMPLES"] = False
+        tc.variables["BUILD_TESTS"] = False
+        tc.variables["WITH_MULTIARCH"] = self.options.with_multiarch
+        tc.variables["BUILD_STATIC_LIBS"] = not self.options.shared
+        if is_msvc(self):
+            tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0091"] = "NEW"
+            tc.variables["WITH_MSVC_CRT_STATIC"] = self.options.with_msvc_crt_static
+            tc.variables["USE_MSVC_RUNTIME_LIBRARY_DLL"] = not is_msvc_static_runtime(self)
+        tc.generate()
+
+    def build(self):
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.build()
+
+    def package(self):
+        copy(self, pattern="COPYING", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
+        cmake = CMake(self)
+        cmake.install()
+        rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
+        rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
+        rmdir(self, os.path.join(self.package_folder, "share"))
+        rm(self, "*.la", os.path.join(self.package_folder, "lib"))
+        rm(self, "*.pdb", os.path.join(self.package_folder, "lib"))
+        rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))
+        if is_msvc(self) and self.options.shared:
+            rename(self, os.path.join(self.package_folder, "lib", "primesieve.dll.lib"), os.path.join(self.package_folder, "lib", "primesieve.lib"))
+
+    def package_info(self):
+        self.cpp_info.libs = ["primesieve"]
+        self.cpp_info.set_property("cmake_file_name", "primesieve")
+        self.cpp_info.set_property("cmake_target_name", "primesieve::primesieve")
+        if self.settings.os in ["Linux", "FreeBSD"]:
+            self.cpp_info.system_libs = ["pthread", "m"]


Test patch:
diff --git a/recipes/primesieve/all/test_package/CMakeLists.txt b/recipes/primesieve/all/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/primesieve/all/test_package/CMakeLists.txt
@@ -0,0 +1,9 @@
+cmake_minimum_required(VERSION 3.8)
+
+project(test_package CXX) # if the project uses c++
+
+find_package(primesieve REQUIRED CONFIG)
+
+add_executable(${PROJECT_NAME} test_package.cpp)
+target_link_libraries(${PROJECT_NAME} PRIVATE primesieve::primesieve)
+target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
diff --git a/recipes/primesieve/all/test_package/conanfile.py b/recipes/primesieve/all/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/primesieve/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.bindirs[0], "test_package")
+            self.run(bin_path, env="conanrun")
diff --git a/recipes/primesieve/all/test_package/test_package.cpp b/recipes/primesieve/all/test_package/test_package.cpp
new file mode 100644
--- /dev/null
+++ b/recipes/primesieve/all/test_package/test_package.cpp
@@ -0,0 +1,15 @@
+#include <primesieve.hpp>
+
+#include <cstdint>
+#include <iostream>
+#include <vector>
+
+int main() {
+  std::vector<uint64_t> primes;
+  primesieve::generate_n_primes(5, &primes);
+  std::cout << "First 5 primes: ";
+  for (const auto prime : primes) {
+    std::cout << prime << ' ';
+  }
+  std::cout << '\n';
+}