Repository: conan-io/conan-center-index

Issue:
[package] pcre2/10.40: Need disable fork function call for tvOS and watchOS
### Package and Environment Details

* Package Name/Version: **pcre2/10.40**
* Operating System+version: **macos 11**
* Compiler+version: **clang 13**
* Conan version: **conan latest**
* Python version: **Python 3.9**


### Conan profile

```
Configuration (profile_host):
[settings]
arch=armv8
arch_build=x86_64
build_type=Debug
compiler=apple-clang
compiler.libcxx=libc++
compiler.version=13
os=tvOS
os.sdk=appletvos
os.version=11.0
os_build=Macos
[options]
nativium_arch=arm64
nativium_build_type=debug
nativium_group=tvos
nativium_product_name=Nativium
nativium_project_name=nativium
nativium_target=ios
nativium_version=1.0.0
nativium_version_code=1
darwin-toolchain:enable_bitcode=True
[build_requires]
*: darwin-toolchain/1.0.0@nativium/stable
[env]

Configuration (profile_build):
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=apple-clang
compiler.libcxx=libc++
compiler.version=13
os=Macos
os_build=Macos
[options]
[build_requires]
[env]
```

### Steps to reproduce

_No response_

### Logs

<details><summary>Click to expand log</summary>

Full log:
https://github.com/nativium/nativium-modules/runs/7808806039?check_suite_focus=true#step:14:22284

Resume:

```
/Users/runner/.conan/data/pcre2/10.40/_/_/build/ca066de8bff8ee34f9b2866f5633069da970d2b4/source_subfolder/src/pcre2grep.c:2432:7: error: 'fork' is unavailable: not available on tvOS
pid = fork();
      ^
/Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS15.2.sdk/usr/include/unistd.h:447:8: note: 'fork' has been explicitly marked unavailable here
pid_t    fork(void) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
         ^
/Users/runner/.conan/data/pcre2/10.40/_/_/build/ca066de8bff8ee34f9b2866f5633069da970d2b4/source_subfolder/src/pcre2grep.c:2435:9: error: 'execv' is unavailable: not available on tvOS
  (void)execv(argsvector[0], argsvector);
        ^
/Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS15.2.sdk/usr/include/unistd.h:444:6: note: 'execv' has been explicitly marked unavailable here
int      execv(const char * __path, char * const * __argv) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
         ^
2 errors generated.
```

</details>



Discussion:
@jcar87 @uilianries  could you help me here?

i think that we need create a new option for `pcre2` to disable it.
Is the same problem that was solved for poco:
https://github.com/pocoproject/poco/issues/3334

Resolving patch:
diff --git a/recipes/pcre2/all/conanfile.py b/recipes/pcre2/all/conanfile.py
--- a/recipes/pcre2/all/conanfile.py
+++ b/recipes/pcre2/all/conanfile.py
@@ -1,12 +1,14 @@
 from conan.tools.microsoft import msvc_runtime_flag, is_msvc
-from conans import CMake, tools
+from conan.tools.files import get, rmdir, replace_in_file
+from conan.tools.scm import Version
 from conan import ConanFile
-from conans.errors import ConanInvalidConfiguration
+from conan.errors import ConanInvalidConfiguration
+from conans import CMake
 import functools
 import os
 
 
-required_conan_version = ">=1.45.0"
+required_conan_version = ">=1.48.0"
 
 
 class PCRE2Conan(ConanFile):
@@ -28,6 +30,7 @@ class PCRE2Conan(ConanFile):
         "with_zlib": [True, False],
         "with_bzip2": [True, False],
         "support_jit": [True, False],
+        "grep_support_callout_fork": [True, False],
     }
     default_options = {
         "shared": False,
@@ -39,6 +42,7 @@ class PCRE2Conan(ConanFile):
         "with_zlib": True,
         "with_bzip2": True,
         "support_jit": False,
+        "grep_support_callout_fork": True,
     }
 
     exports_sources = "CMakeLists.txt"
@@ -64,6 +68,7 @@ def configure(self):
         if not self.options.build_pcre2grep:
             del self.options.with_zlib
             del self.options.with_bzip2
+            del self.options.grep_support_callout_fork
 
     def requirements(self):
         if self.options.get_safe("with_zlib"):
@@ -72,32 +77,32 @@ def requirements(self):
             self.requires("bzip2/1.0.8")
 
     def validate(self):
-        if not self.options.build_pcre2_8 and not self.options.build_pcre2_16 and not self.options.build_pcre2_32:
+        if not self.info.options.build_pcre2_8 and not self.info.options.build_pcre2_16 and not self.info.options.build_pcre2_32:
             raise ConanInvalidConfiguration("At least one of build_pcre2_8, build_pcre2_16 or build_pcre2_32 must be enabled")
-        if self.options.build_pcre2grep and not self.options.build_pcre2_8:
+        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 source(self):
-        tools.get(**self.conan_data["sources"][self.version],
+        get(self, **self.conan_data["sources"][self.version],
                   destination=self._source_subfolder, strip_root=True)
 
     def _patch_sources(self):
         cmakelists = os.path.join(self._source_subfolder, "CMakeLists.txt")
         # Do not add ${PROJECT_SOURCE_DIR}/cmake because it contains a custom
         # FindPackageHandleStandardArgs.cmake which can break conan generators
-        if tools.Version(self.version) < "10.34":
-            tools.replace_in_file(cmakelists, "SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)", "")
+        if Version(self.version) < "10.34":
+            replace_in_file(self, cmakelists, "SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)", "")
         else:
-            tools.replace_in_file(cmakelists, "LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)", "")
+            replace_in_file(self, cmakelists, "LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)", "")
         # Avoid CMP0006 error (macos bundle)
-        tools.replace_in_file(cmakelists,
+        replace_in_file(self, cmakelists,
                               "RUNTIME DESTINATION bin",
                               "RUNTIME DESTINATION bin BUNDLE DESTINATION bin")
 
     @functools.lru_cache(1)
     def _configure_cmake(self):
         cmake = CMake(self)
-        if tools.Version(self.version) >= "10.38":
+        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)
@@ -110,7 +115,8 @@ def _configure_cmake(self):
         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
-        if tools.Version(self.version) < "10.38":
+        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)
@@ -125,10 +131,10 @@ def package(self):
         self.copy(pattern="LICENCE", dst="licenses", src=self._source_subfolder)
         cmake = self._configure_cmake()
         cmake.install()
-        tools.rmdir(os.path.join(self.package_folder, "cmake"))
-        tools.rmdir(os.path.join(self.package_folder, "man"))
-        tools.rmdir(os.path.join(self.package_folder, "share"))
-        tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
+        rmdir(self, os.path.join(self.package_folder, "cmake"))
+        rmdir(self, os.path.join(self.package_folder, "man"))
+        rmdir(self, os.path.join(self.package_folder, "share"))
+        rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
 
     def package_info(self):
         self.cpp_info.set_property("cmake_file_name", "PCRE2")
@@ -189,7 +195,7 @@ def package_info(self):
 
     def _lib_name(self, name):
         libname = name
-        if tools.Version(self.version) >= "10.38" and is_msvc(self) and not self.options.shared:
+        if Version(self.version) >= "10.38" and is_msvc(self) and not self.options.shared:
             libname += "-static"
         if self.settings.os == "Windows":
             if self.settings.build_type == "Debug":


Test patch: