forked from conan-io/conan-center-index
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* tre: add recipe * tre: remove comment * tre: add license * tre: add libtool, clean package folder * tre: fix sha256 * tre: remove compiler.libcxx, etc * tre: fix_apple_shared_install_name() * tre: add Windows support
- Loading branch information
Showing
7 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
sources: | ||
"cci.20230717": | ||
url: "https://github.com/laurikari/tre/archive/07e66d07b44ae95a7a89f79c7ce1090f0f4d64db.tar.gz" | ||
sha256: "f2390091a35c31e90efcce88006c2396f5698759f2f7abd136e771c3e0996961" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.bindir, "test_package") | ||
self.run(bin_path, env="conanrun") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "tre/tre.h" | ||
#include <stdio.h> | ||
|
||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"cci.20230717": | ||
folder: all |