From 6cbd9dcf131f26bf9bdac726d290155ad5f673e2 Mon Sep 17 00:00:00 2001 From: Chris Marsh Date: Thu, 12 Dec 2024 19:38:10 -0600 Subject: [PATCH] Add +pic variant by default such that consumers of the static version of pcre2 can use it in a shared library. Fixes #47614 (#48071) --- .../repos/builtin/packages/pcre2/package.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/var/spack/repos/builtin/packages/pcre2/package.py b/var/spack/repos/builtin/packages/pcre2/package.py index 67f0566385e..2b66bacb273 100644 --- a/var/spack/repos/builtin/packages/pcre2/package.py +++ b/var/spack/repos/builtin/packages/pcre2/package.py @@ -31,12 +31,18 @@ class Pcre2(AutotoolsPackage, CMakePackage): depends_on("c", type="build") - variant("multibyte", default=True, description="Enable support for 16 and 32 bit characters.") - variant("jit", default=False, description="enable Just-In-Time compiling support") + variant("multibyte", default=True, description="Enable support for 16 and 32 bit characters") + variant("jit", default=False, description="Enable Just-In-Time compiling support") + variant( + "pic", + default=True, + description="Build the static library with the option position independent code enabled", + ) + # Building static+shared can cause naming colisions and other problems # for dependents on Windows. It generally does not cause problems on # other systems, so this variant is not exposed for non-Windows. - variant("shared", default=True, description="build shared pcre2", when="platform=windows") + variant("shared", default=True, description="Build shared pcre2", when="platform=windows") build_system("autotools", "cmake", default="autotools") with when("build_system=cmake"): @@ -60,6 +66,10 @@ def libs(self): class AutotoolsBuilder(spack.build_systems.autotools.AutotoolsBuilder): + def build_environment(self, env): + if "+pic" in self.spec: + env.append_flags("CFLAGS", self.compiler.cc_pic_flag) + def configure_args(self): args = [] @@ -79,6 +89,7 @@ def cmake_args(self): args.append(self.define_from_variant("PCRE2_BUILD_PCRE2_16", "multibyte")) args.append(self.define_from_variant("PCRE2_BUILD_PCRE2_32", "multibyte")) args.append(self.define_from_variant("PCRE2_SUPPORT_JIT", "jit")) + args.append(self.define_from_variant("PCRE2_STATIC_PIC", "pic")) # Don't need to check for on or off, just if the variant is available # If not specified, the build system will build both static and shared # by default, this is in parity with the autotools build, so on