Skip to content

Commit

Permalink
(#17793) re2: add version 20230602, add with_icu option
Browse files Browse the repository at this point in the history
* re2: add version 20230602, add with_icu option

* require C++14 since 20230601

* enable C++14 in test_package
  • Loading branch information
toge authored Jun 12, 2023
1 parent cb81489 commit 25fa203
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
3 changes: 3 additions & 0 deletions recipes/re2/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"20230602":
url: "https://github.com/google/re2/releases/download/2023-06-02/re2-2023-06-02.tar.gz"
sha256: "4ccdd5aafaa1bcc24181e6dd3581c3eee0354734bb9f3cb4306273ffa434b94f"
"20230301":
url: "https://github.com/google/re2/archive/refs/tags/2023-03-01.tar.gz"
sha256: "7a9a4824958586980926a300b4717202485c4b4115ac031822e29aa4ef207e48"
Expand Down
42 changes: 39 additions & 3 deletions recipes/re2/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout
from conan.tools.files import copy, get, rmdir
from conan.tools.scm import Version
import os

required_conan_version = ">=1.54.0"


class Re2Conan(ConanFile):
name = "re2"
description = "Fast, safe, thread-friendly regular expression library"
Expand All @@ -20,15 +21,35 @@ class Re2Conan(ConanFile):
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_icu": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_icu": False,
}

@property
def _min_cppstd(self):
return 14 if Version(self.version) >= "20230601" else 11

@property
def _compilers_minimum_version(self):
return {
"14": {
"gcc": "6",
"clang": "5",
"apple-clang": "10",
"Visual Studio": "15",
"msvc": "191",
},
}.get(self._min_cppstd, {})

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
if Version(self.version) < "20230201":
del self.options.with_icu

def configure(self):
if self.options.shared:
Expand All @@ -37,9 +58,21 @@ def configure(self):
def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
if self.options.get_safe("with_icu"):
self.requires("icu/73.1")
if Version(self.version) >= "20230601":
self.requires("abseil/20230125.3", transitive_headers=True)

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, 11)
check_min_cppstd(self, self._min_cppstd)

minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
Expand All @@ -49,6 +82,9 @@ def generate(self):
tc.variables["RE2_BUILD_TESTING"] = False
tc.generate()

deps = CMakeDeps(self)
deps.generate()

def build(self):
cmake = CMake(self)
cmake.configure()
Expand Down
6 changes: 5 additions & 1 deletion recipes/re2/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ find_package(re2 REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE re2::re2)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
if (re2_VERSION VERSION_GREATER_EQUAL "20230602")
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
else()
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
endif()
2 changes: 2 additions & 0 deletions recipes/re2/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
versions:
"20230602":
folder: all
"20230301":
folder: all
"20230201":
Expand Down

0 comments on commit 25fa203

Please sign in to comment.