Commit 788cb28911 for openssl.org

commit 788cb28911fa80059c890794dbb200531b41ac7b
Author: Richard Levitte <levitte@openssl.foundation>
Date:   Mon Sep 7 08:49:32 2026 +0200

    cmake config test: translate target arch flags

    With Unix generators, cmake compiles the consumer project with the
    host compiler's default word size, which may deviate from the
    OpenSSL build's.  A linux-x86 build on an x86_64 host, for example,
    produces 32-bit libraries while cmake links the dummy programs
    64-bit:

        libssl.so: error adding symbols: file in wrong format

    Select the word size / ABI for the consumer project from the
    selectors in the OpenSSL build's own flags, much like the generator
    platform selection for Visual Studio generators.  Darwin's -arch
    gets the dedicated CMAKE_OSX_ARCHITECTURES, which the Xcode
    generator requires.

    Assisted-by: Pi:moonshotai/kimi-k3
    Signed-off-by: Richard Levitte <levitte@openssl.foundation>
    Reviewed-by: Andrew Dinh <andrewd@openssl.org>
    Reviewed-by: Tomas Mraz <tomas@openssl.foundation>
    Merge-date: Sat Nov 14 17:36:40 2026
    Merged-from: https://github.com/openssl/openssl/pull/32442

diff --git a/test/recipes/94-test_cmake_config.t b/test/recipes/94-test_cmake_config.t
index d6e4429a02..6c2d0f91d7 100644
--- a/test/recipes/94-test_cmake_config.t
+++ b/test/recipes/94-test_cmake_config.t
@@ -62,6 +62,32 @@ push @cmake_configure, "-A", "Win32"
     if config('target') =~ /^VC-WIN32/;
 push @cmake_configure, "-A", "ARM64"
     if config('target') =~ /^VC-WIN64-ARM/;
+
+# With Unix generators, cmake compiles the consumer project with the
+# host compiler's default word size, which may deviate from the OpenSSL
+# build's (e.g. linux-x86 on an x86_64 host).  Translate the word size
+# and ABI selectors from the OpenSSL build's own flags, much like the
+# -A platform selection above.  An arch selector may come from the
+# target's flags or from user supplied ones.
+my @flag_tokens = map { split(/\s+/, $_) } (target('cflags') // '',
+                                            target('CFLAGS') // '',
+                                            @{config('cflags') // []},
+                                            @{config('CFLAGS') // []});
+my @abi_cflags;
+while (@flag_tokens) {
+    my $token = shift @flag_tokens;
+    if ($token =~ /^(-m(?:31|32|64|x32)|-mabi=.*|-maix(?:32|64)|-q(?:32|64)|-xarch=.*|\+DD(?:32|64))$/) {
+        # cmake passes CMAKE_C_FLAGS on the C link line as well
+        push @abi_cflags, $token;
+    } elsif ($token eq '-arch' && @flag_tokens) {
+        # Darwin; the Xcode generator requires the dedicated setting
+        push @cmake_configure,
+            "-DCMAKE_OSX_ARCHITECTURES=" . shift @flag_tokens;
+    }
+}
+push @cmake_configure, "-DCMAKE_C_FLAGS=" . join(" ", @abi_cflags)
+    if @abi_cflags;
+
 push @cmake_configure, "-DTEST_LEGACY_PROVIDER=OFF"
     if disabled("legacy") || disabled("module");