Skip to content

Commit

Permalink
(#22577) primesieve: new package
Browse files Browse the repository at this point in the history
* primesieve: add version 11.0

* primesieve: Fix version numer

* Update to 11.2

* Simplify test package

* Misc conanfile cleanup/fixes, drop GCC 5 for now

* Don't build static lib when building shared, add pthread

* Fix MSVC shared package

* Add m to system libs

* Drop 1.x-specific changes

---------

Co-authored-by: Alexis Placet <[email protected]>
  • Loading branch information
Ahajha and Alexis Placet authored Mar 7, 2024
1 parent f452bca commit 0bff285
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 0 deletions.
4 changes: 4 additions & 0 deletions recipes/primesieve/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"11.2":
url: "https://github.com/kimwalisch/primesieve/archive/refs/tags/v11.2.tar.gz"
sha256: "86c31bae9c378340b19669eafef8c5e45849adf7b9c92af1d212a2a2bfa0a5db"
97 changes: 97 additions & 0 deletions recipes/primesieve/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -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"]
9 changes: 9 additions & 0 deletions recipes/primesieve/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
26 changes: 26 additions & 0 deletions recipes/primesieve/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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")
15 changes: 15 additions & 0 deletions recipes/primesieve/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -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';
}
3 changes: 3 additions & 0 deletions recipes/primesieve/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"11.2":
folder: all

0 comments on commit 0bff285

Please sign in to comment.