Skip to content

uni-algo: add recipe #15017

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

Merged
merged 4 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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/uni-algo/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"0.6.0":
url: "https://github.com/uni-algo/uni-algo/archive/refs/tags/v0.6.0.tar.gz"
sha256: "b2b0cf62c8476895ce2dae51459f8df82cd27b6f199b014cb5b2dbb45a605187"
66 changes: 66 additions & 0 deletions recipes/uni-algo/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.files import get, copy
from conan.tools.layout import basic_layout
from conan.tools.scm import Version
import os

required_conan_version = ">=1.52.0"

class UniAlgoConan(ConanFile):
name = "uni-algo"
description = "Unicode Algorithms Implementation for C/C++"
license = ("MIT", "Public Domain")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/uni-algo/uni-algo"
topics = ("unicode", "utf-8", "utf-16", "header-only")
settings = "os", "arch", "compiler", "build_type"
no_copy_source = True

@property
def _min_cppstd(self):
return 17

@property
def _compiler_required_cpp(self):
return {
"Visual Studio": "16",
"msvc": "191",
"gcc": "8",
"clang": "7",
"apple-clang": "12.0",
}

def layout(self):
basic_layout(self, src_folder="src")

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._compiler_required_cpp.get(str(self.settings.compiler), False)
if minimum_version:
if Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support.")
else:
self.output.warn(f"{self.ref} requires C++{self._min_cppstd}. Your compiler is unknown. Assuming it supports C++{self._min_cppstd}.")

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

def package(self):
copy(self, pattern="LICENSE.md", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
copy(
self,
pattern="*.h",
dst=os.path.join(self.package_folder, "include"),
src=os.path.join(self.source_folder, "include"),
)

def package_info(self):
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []
8 changes: 8 additions & 0 deletions recipes/uni-algo/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

find_package(uni-algo REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE uni-algo::uni-algo)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
26 changes: 26 additions & 0 deletions recipes/uni-algo/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 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")
21 changes: 21 additions & 0 deletions recipes/uni-algo/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// This code was cited from https://github.com/uni-algo/uni-algo/tree/v0.1.0#convert-module
#include "uni_algo/all.h"

int main() {
// Lenient conversion (cannot fail) "\xD800" is unpaired high surrogate in
// UTF-16
{
std::string str8 = uni::utf16to8(u"Te\xD800st");
assert(str8 == "Te\xEF\xBF\xBDst"); // "\xEF\xBF\xBD" is replacement
// character U+FFFD in UTF-8
}

// Strict conversion
{
uni::error error;
std::string str8 = uni::strict::utf16to8(u"Te\xD800st", error);
assert(str8.empty() && error && error.pos() == 2);
}

return 0;
}
8 changes: 8 additions & 0 deletions recipes/uni-algo/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
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/)
18 changes: 18 additions & 0 deletions recipes/uni-algo/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from conans import ConanFile, CMake
from conan.tools.build import cross_building
import os


class TestPackageV1Conan(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 cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
3 changes: 3 additions & 0 deletions recipes/uni-algo/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"0.6.0":
folder: all