@@ -29,16 +29,36 @@ FetchContent_Declare(aws-sdk-cpp
2929# fails to find AWS Core symbols at link time (the AWS SDK's visibility
3030# configuration doesn't export them consistently across its FetchContent
3131# build). Linking aws-sdk-cpp statically into our shared wrapper sidesteps
32- # the issue and matches the redis pattern of pinning dep build shape via
33- # a scoped variable rather than overwriting the global BUILD_SHARED_LIBS.
32+ # the issue.
3433#
35- # Using a function for scope: `set(BUILD_SHARED_LIBS OFF)` inside the
36- # function shadows any cached/parent value during FetchContent_MakeAvailable
37- # without persisting after the call, so user `-D LD_BUILD_SHARED_LIBS=ON`
38- # for the rest of the project remains untouched.
39- function (_ld_fetch_aws_sdk_cpp_static )
40- set (BUILD_SHARED_LIBS OFF )
41- FetchContent_MakeAvailable (aws-sdk-cpp)
42- endfunction ()
43-
44- _ld_fetch_aws_sdk_cpp_static ()
34+ # This needs cache manipulation rather than a function-scoped `set()`:
35+ # aws-sdk-cpp's top-level CMakeLists pins `cmake_policy(SET CMP0077 OLD)`,
36+ # which makes its `option(BUILD_SHARED_LIBS ... ON)` ignore non-cache
37+ # variables and unconditionally write the cache. The only way to stop
38+ # `option()` from setting the cache to ON is to pre-populate the cache
39+ # with OFF before FetchContent_MakeAvailable runs.
40+ #
41+ # The prior cache state is saved before the FORCE-write and restored
42+ # immediately after FetchContent finishes, so other subprojects (e.g.
43+ # libs/server-sdk-otel) see whatever BUILD_SHARED_LIBS value was in the
44+ # cache when this file was first included. An earlier attempt that
45+ # FORCE-wrote OFF without restoring leaked into those subprojects; the
46+ # save/restore here is the fix for that.
47+ if (DEFINED CACHE{BUILD_SHARED_LIBS })
48+ set (_LD_AWS_BSL_PREV "${BUILD_SHARED_LIBS} " )
49+ set (_LD_AWS_BSL_WAS_CACHED TRUE )
50+ else ()
51+ set (_LD_AWS_BSL_WAS_CACHED FALSE )
52+ endif ()
53+
54+ set (BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE )
55+
56+ FetchContent_MakeAvailable (aws-sdk-cpp)
57+
58+ if (_LD_AWS_BSL_WAS_CACHED)
59+ set (BUILD_SHARED_LIBS "${_LD_AWS_BSL_PREV} " CACHE BOOL "" FORCE )
60+ else ()
61+ unset (BUILD_SHARED_LIBS CACHE )
62+ endif ()
63+ unset (_LD_AWS_BSL_PREV)
64+ unset (_LD_AWS_BSL_WAS_CACHED)
0 commit comments