Initial commit

This commit is contained in:
2026-01-23 22:15:36 +01:00
commit ca60108606
167 changed files with 5311 additions and 0 deletions

19
stduuid/all/conandata.yml Normal file
View File

@@ -0,0 +1,19 @@
sources:
"1.2.3":
url: "https://github.com/mariusbancila/stduuid/archive/v1.2.3.tar.gz"
sha256: "b1176597e789531c38481acbbed2a6894ad419aab0979c10410d59eb0ebf40d3"
"1.2.2":
url: "https://github.com/mariusbancila/stduuid/archive/v1.2.2.tar.gz"
sha256: "f554f6a9fe4d852fa217de6ab977afbf3f49e4a1dcb263afd61a94253c4c7a48"
"1.0":
url: "https://github.com/mariusbancila/stduuid/archive/v1.0.tar.gz"
sha256: "e96f2ac7c950c3c24d7e2e44a84236277b7774ee346dcc620edf400d9eda0a3c"
patches:
"1.2.2":
- patch_file: "patches/1.2.2-handle-span-header.patch"
patch_description: "Conditionally include span header based on compiler definition"
patch_type: "conan"
"1.2.3":
- patch_file: "patches/1.2.3-handle-span-header.patch"
patch_description: "Conditionally include span header based on compiler definition"
patch_type: "conan"

95
stduuid/all/conanfile.py Normal file
View File

@@ -0,0 +1,95 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd, valid_min_cppstd
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get
from conan.tools.layout import basic_layout
from conan.tools.scm import Version
import os
required_conan_version = ">=1.50.0"
class StduuidConan(ConanFile):
name = "stduuid"
description = "A C++17 cross-platform implementation for UUIDs"
topics = ("uuid", "guid", "header-only")
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/mariusbancila/stduuid"
settings = "os", "arch", "compiler", "build_type"
options = {
# True: Use std::span
# False: Use gsl::span
"with_cxx20_span": [True, False],
"with_system_generator": [True, False],
}
@property
def _min_cppstd(self):
return "20" if self.options.get_safe("with_cxx20_span") else "17"
@property
def _compilers_minimum_version(self):
return {
"apple-clang": "10",
"clang": "5",
"gcc": "7",
"msvc": "191",
"Visual Studio": "15",
}
def export_sources(self):
export_conandata_patches(self)
def layout(self):
basic_layout(self, src_folder="src")
def config_options(self):
if Version(self.version) == "1.0":
# Version 1.0 unconditionally depends on gsl span
del self.options.with_cxx20_span
else:
# Conditionally set the default value of with_cxx20_span
# if cppstd is set and is 20 or greater
self.options.with_cxx20_span = (self.settings.compiler.get_safe("cppstd", False)
and valid_min_cppstd(self, 20))
def requirements(self):
if not self.options.get_safe("with_cxx20_span") or Version(self.version) == "1.0":
self.requires("ms-gsl/4.0.0", transitive_headers=True)
if self.settings.os == "Linux" and Version(self.version) <= "1.0":
self.requires("util-linux-libuuid/2.39", transitive_headers=True, transitive_libs=True)
if self.settings.os == "Linux" and Version(self.version) == "1.2.3" and self.options.get_safe("with_system_generator"):
self.requires("libuuid/1.0.3", transitive_headers=True, transitive_libs=True)
def package_id(self):
self.info.clear()
def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._min_cppstd)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support.",
)
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
apply_conandata_patches(self)
def build(self):
pass
def package(self):
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
copy(self, "uuid.h", src=os.path.join(self.source_folder, "include"), dst=os.path.join(self.package_folder, "include"))
def package_info(self):
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []
if self.options.get_safe("with_cxx20_span"):
self.cpp_info.defines.append("LIBUUID_CPP20_OR_GREATER")
if self.options.get_safe("with_system_generator"):
self.cpp_info.defines.append("UUID_SYSTEM_GENERATOR")

View File

@@ -0,0 +1,26 @@
diff --git a/include/uuid.h b/include/uuid.h
index 600846f..5f00a49 100644
--- a/include/uuid.h
+++ b/include/uuid.h
@@ -15,7 +15,11 @@
#include <chrono>
#include <numeric>
#include <atomic>
-#include <span>
+#if defined(LIBUUID_CPP20_OR_GREATER)
+# include <span>
+#else
+# include <gsl/span>
+#endif
#ifdef _WIN32
@@ -51,7 +55,7 @@
namespace uuids
{
-#ifdef __cpp_lib_span
+#if defined(LIBUUID_CPP20_OR_GREATER)
template <class ElementType, std::size_t Extent>
using span = std::span<ElementType, Extent>;
#else

View File

@@ -0,0 +1,29 @@
diff --git a/include/uuid.h b/include/uuid.h
index d48059d..4d14e4d 100644
--- a/include/uuid.h
+++ b/include/uuid.h
@@ -17,15 +17,6 @@
#include <numeric>
#include <atomic>
-#ifdef __cplusplus
-
-# if (__cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
-# define LIBUUID_CPP20_OR_GREATER
-# endif
-
-#endif
-
-
#ifdef LIBUUID_CPP20_OR_GREATER
#include <span>
#else
@@ -66,7 +57,7 @@
namespace uuids
{
-#ifdef __cpp_lib_span
+#if defined(LIBUUID_CPP20_OR_GREATER)
template <class ElementType, std::size_t Extent>
using span = std::span<ElementType, Extent>;
#else

View File

@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)
find_package(stduuid REQUIRED CONFIG)
add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE stduuid::stduuid)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
if(stduuid_VERSION VERSION_LESS "1.1")
target_compile_definitions(${PROJECT_NAME} PRIVATE STDUUID_LT_1_1)
endif()

View File

@@ -0,0 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os
class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"
def layout(self):
cmake_layout(self)
def requirements(self):
self.requires(self.tested_reference_str)
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")

View File

@@ -0,0 +1,39 @@
#include <uuid.h>
#include <algorithm>
#include <array>
#include <cassert>
#include <functional>
#include <random>
int main() {
{
auto str = "47183823-2574-4bfd-b411-99ed177d3e43";
auto guid = uuids::uuid::from_string(str);
#ifdef STDUUID_LT_1_1
assert(uuids::to_string(guid) == str);
#else
assert(uuids::to_string(guid.value()) == str);
#endif
}
{
std::random_device rd;
auto seed_data = std::array<int, std::mt19937::state_size> {};
std::generate(std::begin(seed_data), std::end(seed_data), std::ref(rd));
std::seed_seq seq(std::begin(seed_data), std::end(seed_data));
std::mt19937 generator(seq);
uuids::uuid const guid = uuids::uuid_random_generator{generator}();
assert(!guid.is_nil());
#ifdef STDUUID_LT_1_1
assert(guid.size() == 16);
#else
assert(guid.as_bytes().size() == 16);
#endif
assert(guid.version() == uuids::uuid_version::random_number_based);
assert(guid.variant() == uuids::uuid_variant::rfc);
}
return 0;
}

View File

@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
${CMAKE_CURRENT_BINARY_DIR}/test_package)

View File

@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os
class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
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(bin_path, run_environment=True)

7
stduuid/config.yml Normal file
View File

@@ -0,0 +1,7 @@
versions:
"1.2.3":
folder: all
"1.2.2":
folder: all
"1.0":
folder: all