Skip to content

Commit

Permalink
(conan-io#5780) add oniguruma/6.9.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceIm authored and madebr committed Jun 21, 2021
1 parent 5f1226d commit d6b4110
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 0 deletions.
7 changes: 7 additions & 0 deletions recipes/oniguruma/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 2.8.11)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory(source_subfolder)
4 changes: 4 additions & 0 deletions recipes/oniguruma/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"6.9.7.1":
url: "https://github.com/kkos/oniguruma/releases/download/v6.9.7.1/onig-6.9.7.1.tar.gz"
sha256: "6444204b9c34e6eb6c0b23021ce89a0370dad2b2f5c00cd44c342753e0b204d9"
79 changes: 79 additions & 0 deletions recipes/oniguruma/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from conans import ConanFile, CMake, tools
import os

required_conan_version = ">=1.33.0"


class OnigurumaConan(ConanFile):
name = "oniguruma"
description = "Oniguruma is a modern and flexible regular expressions library."
license = "BSD-2-Clause"
topics = ("conan", "oniguruma", "regex")
homepage = "https://github.com/kkos/oniguruma"
url = "https://github.com/conan-io/conan-center-index"

settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"posix_api": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"posix_api": True,
}

exports_sources = "CMakeLists.txt"
generators = "cmake"
_cmake = None

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

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd

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

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["ENABLE_POSIX_API"] = self.options.posix_api
self._cmake.definitions["ENABLE_BINARY_COMPATIBLE_POSIX_API"] = self.options.posix_api
self._cmake.configure()
return self._cmake

def build(self):
cmake = self._configure_cmake()
cmake.build()

def package(self):
self.copy("COPYING", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.rmdir(os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "oniguruma"
self.cpp_info.names["cmake_find_package_multi"] = "oniguruma"
self.cpp_info.names["pkg_config"] = "oniguruma"
self.cpp_info.components["onig"].names["cmake_find_package"] = "onig"
self.cpp_info.components["onig"].names["cmake_find_package_multi"] = "onig"
self.cpp_info.components["onig"].names["pkg_config"] = "oniguruma"
self.cpp_info.components["onig"].libs = ["onig"]
if not self.options.shared:
self.cpp_info.components["onig"].defines.append("ONIG_STATIC")
10 changes: 10 additions & 0 deletions recipes/oniguruma/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.1)
project(test_package C)

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

find_package(oniguruma REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} oniguruma::onig)
17 changes: 17 additions & 0 deletions recipes/oniguruma/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
58 changes: 58 additions & 0 deletions recipes/oniguruma/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <oniguruma.h>

#include <stdio.h>
#include <string.h>

int main(void) {
int r;
unsigned char *start, *range, *end;
regex_t* reg;
OnigErrorInfo einfo;
OnigRegion *region;
OnigEncoding use_encs[1];

static UChar* pattern = (UChar* )"a(.*)b|[e-f]+";
static UChar* str = (UChar* )"zzzzaffffffffb";

use_encs[0] = ONIG_ENCODING_ASCII;
onig_initialize(use_encs, sizeof(use_encs)/sizeof(use_encs[0]));

r = onig_new(&reg, pattern, pattern + strlen((char* )pattern),
ONIG_OPTION_DEFAULT, ONIG_ENCODING_ASCII, ONIG_SYNTAX_DEFAULT, &einfo);
if (r != ONIG_NORMAL) {
char s[ONIG_MAX_ERROR_MESSAGE_LEN];
onig_error_code_to_str((UChar* )s, r, &einfo);
fprintf(stderr, "ERROR: %s\n", s);
return -1;
}

region = onig_region_new();

end = str + strlen((char* )str);
start = str;
range = end;
r = onig_search(reg, str, end, start, range, region, ONIG_OPTION_NONE);
if (r >= 0) {
int i;

fprintf(stderr, "match at %d\n", r);
for (i = 0; i < region->num_regs; i++) {
fprintf(stderr, "%d: (%d-%d)\n", i, region->beg[i], region->end[i]);
}
} else if (r == ONIG_MISMATCH) {
fprintf(stderr, "search fail\n");
} else { /* error */
char s[ONIG_MAX_ERROR_MESSAGE_LEN];
onig_error_code_to_str((UChar* )s, r);
fprintf(stderr, "ERROR: %s\n", s);
onig_region_free(region, 1 /* 1:free self, 0:free contents only */);
onig_free(reg);
onig_end();
return -1;
}

onig_region_free(region, 1 /* 1:free self, 0:free contents only */);
onig_free(reg);
onig_end();
return 0;
}
3 changes: 3 additions & 0 deletions recipes/oniguruma/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"6.9.7.1":
folder: all

0 comments on commit d6b4110

Please sign in to comment.