diff --git a/recipes/primesieve/all/conandata.yml b/recipes/primesieve/all/conandata.yml new file mode 100644 index 0000000000000..f4f2c000a99cc --- /dev/null +++ b/recipes/primesieve/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "11.2": + url: "https://github.com/kimwalisch/primesieve/archive/refs/tags/v11.2.tar.gz" + sha256: "86c31bae9c378340b19669eafef8c5e45849adf7b9c92af1d212a2a2bfa0a5db" diff --git a/recipes/primesieve/all/conanfile.py b/recipes/primesieve/all/conanfile.py new file mode 100644 index 0000000000000..c8e88390ec7a5 --- /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"] diff --git a/recipes/primesieve/all/test_package/CMakeLists.txt b/recipes/primesieve/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..ee808a6efb8b5 --- /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 index 0000000000000..a9fb96656f203 --- /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 index 0000000000000..a8281d9952969 --- /dev/null +++ b/recipes/primesieve/all/test_package/test_package.cpp @@ -0,0 +1,15 @@ +#include + +#include +#include +#include + +int main() { + std::vector primes; + primesieve::generate_n_primes(5, &primes); + std::cout << "First 5 primes: "; + for (const auto prime : primes) { + std::cout << prime << ' '; + } + std::cout << '\n'; +} diff --git a/recipes/primesieve/config.yml b/recipes/primesieve/config.yml new file mode 100644 index 0000000000000..3b46283d96d88 --- /dev/null +++ b/recipes/primesieve/config.yml @@ -0,0 +1,3 @@ +versions: + "11.2": + folder: all