@@ -3,6 +3,15 @@ set(COMPILER_MSVC 0)
33set (COMPILER_GCC 0)
44set (COMPILER_CLANG 0)
55
6+ # pkg-config consumers blindly apply Cflags to downstream compilation. Historically
7+ # aws-sdk-cpp exported -std=c++${CPP_STANDARD} (and other policy flags) in .pc files,
8+ # which can override a consumer's chosen language level. Keep default behavior for
9+ # backward compatibility, but allow packagers/consumers to disable exporting the C++
10+ # standard (and related policy flags) via pkg-config.
11+ option (NO_CPPSTD_IN_PKG_CONFIG
12+ "Do not export -std=c++XX (and related policy flags) in pkg-config Cflags"
13+ OFF )
14+
615# ToDo: extend as necessary and remove common assumptions
716if (MSVC )
817 set (COMPILER_MSVC 1)
@@ -23,7 +32,19 @@ function(set_compiler_flags target)
2332 set_gcc_flags ()
2433 target_compile_options (${target} PRIVATE "${AWS_COMPILER_FLAGS} " )
2534 string (REPLACE ";" " " _TMP "${AWS_COMPILER_FLAGS} " )
26- set (PKG_CONFIG_CFLAGS "${_TMP} " CACHE INTERNAL "C++ compiler flags which affect the ABI" )
35+ if (NO_CPPSTD_IN_PKG_CONFIG)
36+ # pkg-config has no PRIVATE/PUBLIC separation: everything in Cflags leaks.
37+ # Remove policy flags that should be controlled by the downstream project.
38+
39+ # Remove any explicit -std=c++NN
40+ string (REPLACE "-std=c++${CPP_STANDARD} " "" _TMP "${_TMP} " )
41+
42+ # Also remove -fno-exceptions since it changes downstream semantics
43+ string (REPLACE "-fno-exceptions" "" _TMP "${_TMP} " )
44+
45+ string (STRIP "${_TMP} " _TMP)
46+ endif ()
47+ set (PKG_CONFIG_CFLAGS "${_TMP} " CACHE INTERNAL "Compiler flags exported via pkg-config" )
2748 endif ()
2849endfunction ()
2950
0 commit comments