diff --git a/recipes/pcre2/all/conanfile.py b/recipes/pcre2/all/conanfile.py index 14600c9abe85c9..808167fb88d672 100644 --- a/recipes/pcre2/all/conanfile.py +++ b/recipes/pcre2/all/conanfile.py @@ -118,6 +118,14 @@ def _patch_sources(self): replace_in_file(self, cmakelists, "RUNTIME DESTINATION bin", "RUNTIME DESTINATION bin BUNDLE DESTINATION bin") + # pcre2-config does not correctly include '-static' in static library names + if Version(self.version) > "10.36": + replace_in_file(self, cmakelists, + "CONFIGURE_FILE(libpcre2-posix.pc.in", + ('if(NOT BUILD_SHARED_LIBS)\n' + ' string(PREPEND LIB_POSTFIX "-static")\n' + 'endif()\n' + 'CONFIGURE_FILE(libpcre2-posix.pc.in')) def build(self): self._patch_sources() @@ -166,7 +174,7 @@ def package_info(self): if self.options.build_pcre2grep: bin_path = os.path.join(self.package_folder, "bin") - self.output.info("Appending PATH environment variable: {}".format(bin_path)) + self.output.info(f"Appending PATH environment variable: {bin_path}") self.env_info.PATH.append(bin_path) # FIXME: This is a workaround to avoid ConanException. zlib and bzip2 # are optional requirements of pcre2grep executable, not of any pcre2 lib. diff --git a/recipes/pcre2/all/test_package/conanfile.py b/recipes/pcre2/all/test_package/conanfile.py index 0a6bc68712d901..d0bc51cb53f7ae 100644 --- a/recipes/pcre2/all/test_package/conanfile.py +++ b/recipes/pcre2/all/test_package/conanfile.py @@ -1,7 +1,10 @@ from conan import ConanFile from conan.tools.build import can_run +from conan.tools.files import save, load from conan.tools.cmake import CMake, cmake_layout +from conan.tools.scm import Version import os +from io import StringIO class TestPackageConan(ConanFile): @@ -9,12 +12,29 @@ class TestPackageConan(ConanFile): generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv" test_type = "explicit" + @property + def _settings_build(self): + return getattr(self, "settings_build", self.settings) + def layout(self): cmake_layout(self) def requirements(self): self.requires(self.tested_reference_str) + def build_requirements(self): + self.tool_requires(self.tested_reference_str) + if self._settings_build.os == "Windows": + self.win_bash = True + if not self.conf.get("tools.microsoft.bash:path", check_type=str): + self.tool_requires("msys2/cci.latest") + + def generate(self): + pcre2_cpp_info = self.dependencies["pcre2"].cpp_info.aggregated_components() + save(self, os.path.join(self.build_folder, "bindir"), pcre2_cpp_info.bindir) + save(self, os.path.join(self.build_folder, "libdir"), pcre2_cpp_info.libdir) + save(self, os.path.join(self.build_folder, "libs"), " ".join(pcre2_cpp_info.libs)) + def build(self): cmake = CMake(self) cmake.configure() @@ -22,5 +42,17 @@ def build(self): def test(self): if can_run(self): - bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + bin_path = os.path.join(self.cpp.build.bindir, "test_package") self.run(bin_path, env="conanrun") + + if Version(self.tested_reference_str.split("/")[1]) >= "10.36": + bindir = load(self, os.path.join(self.build_folder, "bindir")) + libdir = load(self, os.path.join(self.build_folder, "libdir")).replace("\\", "/") + libs = load(self, os.path.join(self.build_folder, "libs")).split(" ") + output = StringIO() + self.run(f"bash {bindir}/pcre2-config --libs8", output) + conf = output.getvalue().strip().split(" ") + assert f"-L{libdir}" in conf, f"Expected '-L{libdir}' not set by pcre2-config: {conf}" + for param in conf: + if param.startswith("-l"): + assert param[2:] in libs, f"Invalid library target '{param[2:]}' output by pcre2-config. Not found in {libs}."