Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pcre2: conan v2 support #12343

Merged
merged 3 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions recipes/pcre2/all/CMakeLists.txt

This file was deleted.

36 changes: 36 additions & 0 deletions recipes/pcre2/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,39 @@ sources:
- "https://github.com/PhilipHazel/pcre2/releases/download/pcre2-10.32/pcre2-10.32.tar.bz2"
- "https://sourceforge.net/projects/pcre/files/pcre2/10.32/pcre2-10.32.tar.bz2"
sha256: "f29e89cc5de813f45786580101aaee3984a65818631d4ddbda7b32f699b87c2e"
patches:
"10.40":
- patch_file: "patches/0001-fix-cmake-1.39.patch"
patch_description: "correct the order of cmake_minimum_required() and project()"
patch_type: "backport"
patch_source: "https://github.com/PCRE2Project/pcre2/pull/142"
"10.39":
- patch_file: "patches/0001-fix-cmake-1.39.patch"
patch_description: "correct the order of cmake_minimum_required() and project()"
patch_type: "backport"
patch_source: "https://github.com/PCRE2Project/pcre2/pull/142"
"10.37":
- patch_file: "patches/0001-fix-cmake-1.36.patch"
patch_description: "correct the order of cmake_minimum_required() and project()"
patch_type: "backport"
patch_source: "https://github.com/PCRE2Project/pcre2/pull/142"
"10.36":
- patch_file: "patches/0001-fix-cmake-1.36.patch"
patch_description: "correct the order of cmake_minimum_required() and project()"
patch_type: "backport"
patch_source: "https://github.com/PCRE2Project/pcre2/pull/142"
"10.35":
- patch_file: "patches/0001-fix-cmake-1.35.patch"
patch_description: "correct the order of cmake_minimum_required() and project()"
patch_type: "backport"
patch_source: "https://github.com/PCRE2Project/pcre2/pull/142"
"10.33":
- patch_file: "patches/0001-fix-cmake-1.33.patch"
patch_description: "correct the order of cmake_minimum_required() and project()"
patch_type: "backport"
patch_source: "https://github.com/PCRE2Project/pcre2/pull/142"
"10.32":
- patch_file: "patches/0001-fix-cmake-1.32.patch"
patch_description: "correct the order of cmake_minimum_required() and project()"
patch_type: "backport"
patch_source: "https://github.com/PCRE2Project/pcre2/pull/142"
100 changes: 53 additions & 47 deletions recipes/pcre2/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from conan.tools.microsoft import msvc_runtime_flag, is_msvc
from conan.tools.files import get, rmdir, replace_in_file
from conan.tools.scm import Version
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conans import CMake
import functools
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, get, replace_in_file, rmdir
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime
from conan.tools.scm import Version
import os


required_conan_version = ">=1.48.0"
required_conan_version = ">=1.50.0"


class PCRE2Conan(ConanFile):
Expand Down Expand Up @@ -45,16 +43,9 @@ class PCRE2Conan(ConanFile):
"grep_support_callout_fork": True,
}

exports_sources = "CMakeLists.txt"
generators = "cmake", "cmake_find_package"

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

@property
def _build_subfolder(self):
return "build_subfolder"
def export_sources(self):
for p in self.conan_data.get("patches", {}).get(self.version, []):
copy(self, p["patch_file"], self.recipe_folder, self.export_sources_folder)

def config_options(self):
if self.settings.os == "Windows":
Expand All @@ -63,8 +54,14 @@ def config_options(self):
def configure(self):
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
try:
del self.settings.compiler.libcxx
except Exception:
pass
try:
del self.settings.compiler.cppstd
except Exception:
pass
if not self.options.build_pcre2grep:
del self.options.with_zlib
del self.options.with_bzip2
Expand All @@ -82,12 +79,43 @@ def validate(self):
if self.info.options.build_pcre2grep and not self.info.options.build_pcre2_8:
raise ConanInvalidConfiguration("build_pcre2_8 must be enabled for the pcre2grep program")

def layout(self):
cmake_layout(self, src_folder="src")

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

def generate(self):
tc = CMakeToolchain(self)
# Mandatory because upstream CMakeLists overrides BUILD_SHARED_LIBS as a CACHE variable
# (see https://github.com/conan-io/conan/issues/11840)
tc.variables["BUILD_SHARED_LIBS"] = self.options.shared
if Version(self.version) >= "10.38":
tc.variables["BUILD_STATIC_LIBS"] = not self.options.shared
tc.variables["PCRE2_BUILD_PCRE2GREP"] = self.options.build_pcre2grep
tc.variables["PCRE2_SUPPORT_LIBZ"] = self.options.get_safe("with_zlib", False)
tc.variables["PCRE2_SUPPORT_LIBBZ2"] = self.options.get_safe("with_bzip2", False)
tc.variables["PCRE2_BUILD_TESTS"] = False
if is_msvc(self):
tc.variables["PCRE2_STATIC_RUNTIME"] = is_msvc_static_runtime(self)
tc.variables["PCRE2_DEBUG"] = self.settings.build_type == "Debug"
tc.variables["PCRE2_BUILD_PCRE2_8"] = self.options.build_pcre2_8
tc.variables["PCRE2_BUILD_PCRE2_16"] = self.options.build_pcre2_16
tc.variables["PCRE2_BUILD_PCRE2_32"] = self.options.build_pcre2_32
tc.variables["PCRE2_SUPPORT_JIT"] = self.options.support_jit
tc.variables["PCRE2GREP_SUPPORT_CALLOUT_FORK"] = self.options.get_safe("grep_support_callout_fork", False)
if Version(self.version) < "10.38":
# relocatable shared libs on Macos
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0042"] = "NEW"
tc.generate()

cd = CMakeDeps(self)
cd.generate()

def _patch_sources(self):
cmakelists = os.path.join(self._source_subfolder, "CMakeLists.txt")
apply_conandata_patches(self)
cmakelists = os.path.join(self.source_folder, "CMakeLists.txt")
# Do not add ${PROJECT_SOURCE_DIR}/cmake because it contains a custom
# FindPackageHandleStandardArgs.cmake which can break conan generators
if Version(self.version) < "10.34":
Expand All @@ -99,37 +127,15 @@ def _patch_sources(self):
"RUNTIME DESTINATION bin",
"RUNTIME DESTINATION bin BUNDLE DESTINATION bin")

@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
if Version(self.version) >= "10.38":
cmake.definitions["BUILD_STATIC_LIBS"] = not self.options.shared
cmake.definitions["PCRE2_BUILD_PCRE2GREP"] = self.options.build_pcre2grep
cmake.definitions["PCRE2_SUPPORT_LIBZ"] = self.options.get_safe("with_zlib", False)
cmake.definitions["PCRE2_SUPPORT_LIBBZ2"] = self.options.get_safe("with_bzip2", False)
cmake.definitions["PCRE2_BUILD_TESTS"] = False
if is_msvc(self):
cmake.definitions["PCRE2_STATIC_RUNTIME"] = "MT" in msvc_runtime_flag(self)
cmake.definitions["PCRE2_DEBUG"] = self.settings.build_type == "Debug"
cmake.definitions["PCRE2_BUILD_PCRE2_8"] = self.options.build_pcre2_8
cmake.definitions["PCRE2_BUILD_PCRE2_16"] = self.options.build_pcre2_16
cmake.definitions["PCRE2_BUILD_PCRE2_32"] = self.options.build_pcre2_32
cmake.definitions["PCRE2_SUPPORT_JIT"] = self.options.support_jit
cmake.definitions["PCRE2GREP_SUPPORT_CALLOUT_FORK"] = self.options.get_safe("grep_support_callout_fork", False)
if Version(self.version) < "10.38":
# relocatable shared libs on Macos
cmake.definitions["CMAKE_POLICY_DEFAULT_CMP0042"] = "NEW"
cmake.configure(build_folder=self._build_subfolder)
return cmake

def build(self):
self._patch_sources()
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy(pattern="LICENCE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, "LICENCE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "cmake"))
rmdir(self, os.path.join(self.package_folder, "man"))
Expand Down
17 changes: 17 additions & 0 deletions recipes/pcre2/all/patches/0001-fix-cmake-1.32.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -83,13 +83,13 @@
# 2018-06-19 PH added checks for stdint.h and inttypes.h
# 2018-06-27 PH added Daniel's patch to increase the stack for MSVC

-PROJECT(PCRE2 C)

# Increased minimum to 2.8.0 to support newer add_test features. Set policy
# CMP0026 to avoid warnings for the use of LOCATION in GET_TARGET_PROPERTY.

CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0)
CMAKE_POLICY(SET CMP0026 OLD)
+PROJECT(PCRE2 C)

SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) # for FindReadline.cmake

14 changes: 14 additions & 0 deletions recipes/pcre2/all/patches/0001-fix-cmake-1.33.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -86,10 +86,10 @@
# 2018-11-16 PH added PCRE2GREP_SUPPORT_CALLOUT_FORK support and tidied
# 2019-02-16 PH hacked to avoid CMP0026 policy issue (see comments below)

-PROJECT(PCRE2 C)

# Increased minimum to 2.8.0 to support newer add_test features.
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0)
+PROJECT(PCRE2 C)

# Set policy CMP0026 to avoid warnings for the use of LOCATION in
# GET_TARGET_PROPERTY. This should no longer be required.
14 changes: 14 additions & 0 deletions recipes/pcre2/all/patches/0001-fix-cmake-1.35.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -93,10 +93,10 @@
# 2020-04-25 Carlo added function check for mkostemp used in ProtExecAllocator
# 2020-04-28 PH added function check for memfd_create based on Carlo's patch

-PROJECT(PCRE2 C)

# Increased minimum to 2.8.0 to support newer add_test features.
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0)
+PROJECT(PCRE2 C)

# Set policy CMP0026 to avoid warnings for the use of LOCATION in
# GET_TARGET_PROPERTY. This should no longer be required.
14 changes: 14 additions & 0 deletions recipes/pcre2/all/patches/0001-fix-cmake-1.36.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -95,10 +95,10 @@
# 2020-05-25 PH added a check for Intel CET
# 2020-12-03 PH altered the definition of pcre2test as suggested by Daniel

-PROJECT(PCRE2 C)

# Increased minimum to 2.8.5 to support GNUInstallDirs.
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.5)
+PROJECT(PCRE2 C)

# Set policy CMP0026 to avoid warnings for the use of LOCATION in
# GET_TARGET_PROPERTY. This should no longer be required.
15 changes: 15 additions & 0 deletions recipes/pcre2/all/patches/0001-fix-cmake-1.39.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -100,11 +100,11 @@
# 2021-08-28 PH increased minimum version
# 2021-08-28 PH added test for realpath()

-PROJECT(PCRE2 C)

# Increased minimum to 2.8.5 to support GNUInstallDirs.
# Increased minimum to 3.0.0 because older than 2.8.12 is deprecated.
CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0)
+PROJECT(PCRE2 C)

# Set policy CMP0026 to avoid warnings for the use of LOCATION in
# GET_TARGET_PROPERTY. This should no longer be required.
7 changes: 2 additions & 5 deletions recipes/pcre2/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
project(test_package LANGUAGES C)

find_package(PCRE2 REQUIRED 8BIT CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PCRE2::8BIT)
target_link_libraries(${PROJECT_NAME} PRIVATE PCRE2::8BIT)
25 changes: 12 additions & 13 deletions recipes/pcre2/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import cross_building
from conan.tools.cmake import CMake, cmake_layout
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"

def build_requirements(self):
if self.settings.os == "Macos" and self.settings.arch == "armv8":
# Workaround for CMake bug with error message:
# Attempting to use @rpath without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being
# set. This could be because you are using a Mac OS X version less than 10.5
# or because CMake's platform configuration is corrupt.
# FIXME: Remove once CMake on macOS/M1 CI runners is upgraded.
self.build_requires("cmake/3.22.0")
def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if not cross_building(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
10 changes: 10 additions & 0 deletions recipes/pcre2/all/test_v1_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 LANGUAGES C)

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

find_package(PCRE2 REQUIRED 8BIT CONFIG)

add_executable(${PROJECT_NAME} ../test_package/test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE PCRE2::8BIT)
18 changes: 18 additions & 0 deletions recipes/pcre2/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# pylint: skip-file
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):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)