diff --git a/recipes/tre/all/CMakeLists.txt b/recipes/tre/all/CMakeLists.txt new file mode 100644 index 0000000000000..cf9c37d17b6e1 --- /dev/null +++ b/recipes/tre/all/CMakeLists.txt @@ -0,0 +1,24 @@ +cmake_minimum_required (VERSION 3.15) +project (tre) + +set(HEADERS + local_includes/regex.h + local_includes/tre.h + win32/tre-config.h +) +file(GLOB SRCS lib/*.c) + +include_directories(win32 local_includes) +add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS) +add_definitions(-DHAVE_CONFIG_H -DHAVE_MALLOC_H) +add_library(tre ${SRCS} win32/tre.def) + +install(TARGETS tre + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib +) + +install(FILES ${HEADERS} + DESTINATION include/tre +) diff --git a/recipes/tre/all/conandata.yml b/recipes/tre/all/conandata.yml new file mode 100644 index 0000000000000..683be30ad0ede --- /dev/null +++ b/recipes/tre/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "cci.20230717": + url: "https://github.com/laurikari/tre/archive/07e66d07b44ae95a7a89f79c7ce1090f0f4d64db.tar.gz" + sha256: "f2390091a35c31e90efcce88006c2396f5698759f2f7abd136e771c3e0996961" diff --git a/recipes/tre/all/conanfile.py b/recipes/tre/all/conanfile.py new file mode 100644 index 0000000000000..8991cbd800567 --- /dev/null +++ b/recipes/tre/all/conanfile.py @@ -0,0 +1,90 @@ +import os + +from conan import ConanFile +from conan.tools.apple import fix_apple_shared_install_name +from conan.tools.build import cross_building +from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout +from conan.tools.env import VirtualBuildEnv, VirtualRunEnv +from conan.tools.files import copy, get, rm, rmdir +from conan.tools.gnu import Autotools, AutotoolsToolchain + +required_conan_version = ">=1.53.0" + + +class TreConan(ConanFile): + name = "tre" + description = "TRE is a lightweight, robust, and efficient POSIX-compliant regexp matching library with some exciting features such as approximate (fuzzy) matching." + license = "BSD-2-Clause" + homepage = "https://github.com/laurikari/tre" + url = "https://github.com/conan-io/conan-center-index" + topics = "regex", "fuzzy matching" + + package_type = "library" + settings = "os", "arch", "compiler", "build_type" + options = {"shared": [True, False], "fPIC": [True, False]} + default_options = {"shared": False, "fPIC": True} + + def export_sources(self): + copy(self, "CMakeLists.txt", src=self.recipe_folder, dst=self.export_sources_folder) + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + + def configure(self): + if self.options.shared: + self.options.rm_safe("fPIC") + self.settings.rm_safe("compiler.libcxx") + self.settings.rm_safe("compiler.cppstd") + + def layout(self): + cmake_layout(self, src_folder="src") + + def build_requirements(self): + if self.settings.os != "Windows": + self.tool_requires("libtool/2.4.7") + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + if self.settings.os == "Windows": + tc = CMakeToolchain(self) + tc.generate() + else: + env = VirtualBuildEnv(self) + env.generate() + if not cross_building(self): + env = VirtualRunEnv(self) + env.generate(scope="build") + tc = AutotoolsToolchain(self) + tc.generate() + + def build(self): + if self.settings.os == "Windows": + copy(self, "CMakeLists.txt", src=self.export_sources_folder, dst=self.source_folder) + cmake = CMake(self) + cmake.configure() + cmake.build() + else: + autotools = Autotools(self) + autotools.autoreconf() + autotools.configure() + autotools.make() + + def package(self): + copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) + if self.settings.os == "Windows": + cmake = CMake(self) + cmake.install() + else: + autotools = Autotools(self) + autotools.install() + rm(self, "*.la", os.path.join(self.package_folder, "lib")) + rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) + rmdir(self, os.path.join(self.package_folder, "share")) + fix_apple_shared_install_name(self) + + def package_info(self): + self.cpp_info.set_property("pkg_config_name", "tre") + self.cpp_info.libs = ["tre"] diff --git a/recipes/tre/all/test_package/CMakeLists.txt b/recipes/tre/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..dff3b713e92cc --- /dev/null +++ b/recipes/tre/all/test_package/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES C) + +find_package(tre REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.c) +target_link_libraries(${PROJECT_NAME} PRIVATE tre::tre) diff --git a/recipes/tre/all/test_package/conanfile.py b/recipes/tre/all/test_package/conanfile.py new file mode 100644 index 0000000000000..3a91c9439218e --- /dev/null +++ b/recipes/tre/all/test_package/conanfile.py @@ -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.bindir, "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/tre/all/test_package/test_package.c b/recipes/tre/all/test_package/test_package.c new file mode 100644 index 0000000000000..605527c604de8 --- /dev/null +++ b/recipes/tre/all/test_package/test_package.c @@ -0,0 +1,21 @@ +#include "tre/tre.h" +#include + +int main() +{ + regex_t rx; + tre_regcomp(&rx, "(January|February)", REG_EXTENDED); + + regaparams_t params = {0}; + tre_regaparams_default(¶ms); + + regamatch_t match = {0}; + + if (!tre_regaexec(&rx, "Janvary", &match, params, 0)) { + printf("Levenshtein distance: %d\n", match.cost); + } else { + printf("Failed to match\n"); + } + + return 0; +} diff --git a/recipes/tre/config.yml b/recipes/tre/config.yml new file mode 100644 index 0000000000000..b32c668575dde --- /dev/null +++ b/recipes/tre/config.yml @@ -0,0 +1,3 @@ +versions: + "cci.20230717": + folder: all