Skip to content

Commit 6d9e5a9

Browse files
togeuilianries
andauthored
(#15017) uni-algo: add recipe
* uni-algo: add recipe * add header-only topics * fix typo * fix license Co-authored-by: Uilian Ries <[email protected]> --------- Co-authored-by: Uilian Ries <[email protected]>
1 parent b0f1b59 commit 6d9e5a9

File tree

8 files changed

+154
-0
lines changed

8 files changed

+154
-0
lines changed

recipes/uni-algo/all/conandata.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
sources:
2+
"0.6.0":
3+
url: "https://github.com/uni-algo/uni-algo/archive/refs/tags/v0.6.0.tar.gz"
4+
sha256: "b2b0cf62c8476895ce2dae51459f8df82cd27b6f199b014cb5b2dbb45a605187"

recipes/uni-algo/all/conanfile.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from conan import ConanFile
2+
from conan.errors import ConanInvalidConfiguration
3+
from conan.tools.build import check_min_cppstd
4+
from conan.tools.files import get, copy
5+
from conan.tools.layout import basic_layout
6+
from conan.tools.scm import Version
7+
import os
8+
9+
required_conan_version = ">=1.52.0"
10+
11+
class UniAlgoConan(ConanFile):
12+
name = "uni-algo"
13+
description = "Unicode Algorithms Implementation for C/C++"
14+
license = ("MIT", "Unlicense")
15+
url = "https://github.com/conan-io/conan-center-index"
16+
homepage = "https://github.com/uni-algo/uni-algo"
17+
topics = ("unicode", "utf-8", "utf-16", "header-only")
18+
settings = "os", "arch", "compiler", "build_type"
19+
no_copy_source = True
20+
21+
@property
22+
def _min_cppstd(self):
23+
return 17
24+
25+
@property
26+
def _compiler_required_cpp(self):
27+
return {
28+
"Visual Studio": "16",
29+
"msvc": "191",
30+
"gcc": "8",
31+
"clang": "7",
32+
"apple-clang": "12.0",
33+
}
34+
35+
def layout(self):
36+
basic_layout(self, src_folder="src")
37+
38+
def package_id(self):
39+
self.info.clear()
40+
41+
def validate(self):
42+
if self.settings.compiler.get_safe("cppstd"):
43+
check_min_cppstd(self, self._min_cppstd)
44+
45+
minimum_version = self._compiler_required_cpp.get(str(self.settings.compiler), False)
46+
if minimum_version:
47+
if Version(self.settings.compiler.version) < minimum_version:
48+
raise ConanInvalidConfiguration(f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support.")
49+
else:
50+
self.output.warn(f"{self.ref} requires C++{self._min_cppstd}. Your compiler is unknown. Assuming it supports C++{self._min_cppstd}.")
51+
52+
def source(self):
53+
get(self, **self.conan_data["sources"][self.version], strip_root=True)
54+
55+
def package(self):
56+
copy(self, pattern="LICENSE.md", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
57+
copy(
58+
self,
59+
pattern="*.h",
60+
dst=os.path.join(self.package_folder, "include"),
61+
src=os.path.join(self.source_folder, "include"),
62+
)
63+
64+
def package_info(self):
65+
self.cpp_info.bindirs = []
66+
self.cpp_info.libdirs = []
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required(VERSION 3.8)
2+
project(test_package LANGUAGES CXX)
3+
4+
find_package(uni-algo REQUIRED CONFIG)
5+
6+
add_executable(${PROJECT_NAME} test_package.cpp)
7+
target_link_libraries(${PROJECT_NAME} PRIVATE uni-algo::uni-algo)
8+
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from conan import ConanFile
2+
from conan.tools.build import can_run
3+
from conan.tools.cmake import cmake_layout, CMake
4+
import os
5+
6+
7+
class TestPackageConan(ConanFile):
8+
settings = "os", "arch", "compiler", "build_type"
9+
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
10+
test_type = "explicit"
11+
12+
def layout(self):
13+
cmake_layout(self)
14+
15+
def requirements(self):
16+
self.requires(self.tested_reference_str)
17+
18+
def build(self):
19+
cmake = CMake(self)
20+
cmake.configure()
21+
cmake.build()
22+
23+
def test(self):
24+
if can_run(self):
25+
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
26+
self.run(bin_path, env="conanrun")
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// This code was cited from https://github.com/uni-algo/uni-algo/tree/v0.1.0#convert-module
2+
#include "uni_algo/all.h"
3+
4+
int main() {
5+
// Lenient conversion (cannot fail) "\xD800" is unpaired high surrogate in
6+
// UTF-16
7+
{
8+
std::string str8 = uni::utf16to8(u"Te\xD800st");
9+
assert(str8 == "Te\xEF\xBF\xBDst"); // "\xEF\xBF\xBD" is replacement
10+
// character U+FFFD in UTF-8
11+
}
12+
13+
// Strict conversion
14+
{
15+
uni::error error;
16+
std::string str8 = uni::strict::utf16to8(u"Te\xD800st", error);
17+
assert(str8.empty() && error && error.pos() == 2);
18+
}
19+
20+
return 0;
21+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
project(test_package)
3+
4+
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5+
conan_basic_setup(TARGETS)
6+
7+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
8+
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from conans import ConanFile, CMake
2+
from conan.tools.build import cross_building
3+
import os
4+
5+
6+
class TestPackageV1Conan(ConanFile):
7+
settings = "os", "arch", "compiler", "build_type"
8+
generators = "cmake", "cmake_find_package_multi"
9+
10+
def build(self):
11+
cmake = CMake(self)
12+
cmake.configure()
13+
cmake.build()
14+
15+
def test(self):
16+
if not cross_building(self):
17+
bin_path = os.path.join("bin", "test_package")
18+
self.run(bin_path, run_environment=True)

recipes/uni-algo/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
versions:
2+
"0.6.0":
3+
folder: all

0 commit comments

Comments
 (0)