From 53aeaa92069f3d81165d8ab221a476793e1a24a5 Mon Sep 17 00:00:00 2001 From: rajanyadav0307 Date: Sun, 1 Feb 2026 00:08:59 -0600 Subject: [PATCH] Issue-3613: Fix Sign-off: Rajan Y.(rajanyadav0307@gmail.com) --- cmake/compiler_settings.cmake | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/cmake/compiler_settings.cmake b/cmake/compiler_settings.cmake index 41fcf9378596..b8fcd143a364 100644 --- a/cmake/compiler_settings.cmake +++ b/cmake/compiler_settings.cmake @@ -3,6 +3,15 @@ set(COMPILER_MSVC 0) set(COMPILER_GCC 0) set(COMPILER_CLANG 0) +# pkg-config consumers blindly apply Cflags to downstream compilation. Historically +# aws-sdk-cpp exported -std=c++${CPP_STANDARD} (and other policy flags) in .pc files, +# which can override a consumer's chosen language level. Keep default behavior for +# backward compatibility, but allow packagers/consumers to disable exporting the C++ +# standard (and related policy flags) via pkg-config. +option(NO_CPPSTD_IN_PKG_CONFIG + "Do not export -std=c++XX (and related policy flags) in pkg-config Cflags" + OFF) + # ToDo: extend as necessary and remove common assumptions if(MSVC) set(COMPILER_MSVC 1) @@ -23,7 +32,19 @@ function(set_compiler_flags target) set_gcc_flags() target_compile_options(${target} PRIVATE "${AWS_COMPILER_FLAGS}") string(REPLACE ";" " " _TMP "${AWS_COMPILER_FLAGS}") - set(PKG_CONFIG_CFLAGS "${_TMP}" CACHE INTERNAL "C++ compiler flags which affect the ABI") + if(NO_CPPSTD_IN_PKG_CONFIG) + # pkg-config has no PRIVATE/PUBLIC separation: everything in Cflags leaks. + # Remove policy flags that should be controlled by the downstream project. + + # Remove any explicit -std=c++NN + string(REPLACE "-std=c++${CPP_STANDARD}" "" _TMP "${_TMP}") + + # Also remove -fno-exceptions since it changes downstream semantics + string(REPLACE "-fno-exceptions" "" _TMP "${_TMP}") + + string(STRIP "${_TMP}" _TMP) + endif() + set(PKG_CONFIG_CFLAGS "${_TMP}" CACHE INTERNAL "Compiler flags exported via pkg-config") endif() endfunction()