Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xoshiro-cpp: new recipe #11350

Merged
merged 9 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions recipes/xoshiro-cpp/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.1":
sha256: 9e1fff51faa8754b5c61ab00f41339df0b9b1c09a13611e3357aab76c65f2ba0
url: https://github.com/Reputeless/Xoshiro-cpp/archive/refs/tags/v1.1.tar.gz
68 changes: 68 additions & 0 deletions recipes/xoshiro-cpp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from conans import ConanFile, tools
from conans.errors import ConanInvalidConfiguration

required_conan_version = ">=1.33.0"


class XoshiroCppConan(ConanFile):
name = "xoshiro-cpp"
description = "Header-only Xoshiro/Xoroshiro PRNG wrapper library for modern C++ (C++17/C++20)"
license = "MIT"
homepage = "https://github.com/Reputeless/Xoshiro-cpp"
url = "https://github.com/conan-io/conan-center-index"
topics = ("prng", "xoshiro", "header-only")
settings = "arch", "build_type", "compiler", "os"
generators = "cmake"
no_copy_source = True

@property
def _minimum_compilers_version(self):
return {
"apple-clang": "10",
"clang": "6",
"gcc": "7",
"Visual Studio": "16"
}

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _minimum_cpp_standard(self):
return 17

def validate(self):
if self.settings.get_safe("compiler.cppstd"):
tools.check_min_cppstd(self, self._minimum_cpp_standard)

compiler = self.settings.compiler
try:
min_version = self._minimum_compilers_version[str(compiler)]
if tools.Version(compiler.version) < min_version:
msg = (
"{} requires C++{} features which are not supported by compiler {} {}."
).format(self.name, self._minimum_cpp_standard, compiler, compiler.version)
raise ConanInvalidConfiguration(msg)
except KeyError:
msg = (
"{} recipe lacks information about the {} compiler, "
"support for the required C++{} features is assumed"
).format(self.name, compiler, self._minimum_cpp_standard)
self.output.warn(msg)

def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)

def package(self):
self.copy("*.hpp", dst="include/xoshiro-cpp",
src=self._source_subfolder)
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)

def package_id(self):
self.info.header_only()

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "xoshiro-cpp"
self.cpp_info.names["cmake_find_package_multi"] = "xoshiro-cpp"
13 changes: 13 additions & 0 deletions recipes/xoshiro-cpp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.8)
project(test_package)

set(CMAKE_CXX_STANDARD 17)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(xoshiro-cpp REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE xoshiro-cpp::xoshiro-cpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_${CMAKE_CXX_STANDARD})
18 changes: 18 additions & 0 deletions recipes/xoshiro-cpp/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os

from conans import ConanFile, CMake, tools


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run("{0}".format(bin_path), run_environment=True)
18 changes: 18 additions & 0 deletions recipes/xoshiro-cpp/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <cassert>
#include <iostream>

#include "xoshiro-cpp/XoshiroCpp.hpp"

template <class N> static void assert_and_print(N expected, N got) {
std::cout << expected << " == " << got << '\n';
assert(expected == got);
}

int main() {
std::cout << "# Initialize with a default 64-bit seed\n";
XoshiroCpp::Xoshiro256PlusPlus rng;
for (uint64_t expected : {10656210946825422025ULL, 3029598875750717312ULL,
8253387787243700537ULL}) {
assert_and_print(expected, rng());
}
}
3 changes: 3 additions & 0 deletions recipes/xoshiro-cpp/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.1":
folder: all