[runtimes] Don't create shared library targets when unsupported (#205517)
On platforms that don't support shared libraries (e.g. CMAKE_SYSTEM_NAME
of "Generic", used for GPU and other baremetal targets), CMake's
Platform/Generic.cmake sets the global TARGET_SUPPORTS_SHARED_LIBS
property to FALSE. Under CMP0164's OLD behavior (the default, since the runtimes
set cmake_minimum_required(3.20)), CMake silently demotes SHARED library
targets to STATIC archives. libcxx, libcxxabi and libunwind always create their
shared target, so after demotion both the shared and static targets emit e.g.
"libc++abi.a" and Ninja fails with "multiple rules generate ...".
Rather than papering over the collision with a distinct output name,
skip creating the shared library targets entirely when the platform does not
support them, gating on the TARGET_SUPPORTS_SHARED_LIBS property (left
undefined on platforms that do support shared libraries). The few consumers of
the shared targets are guarded with TARGET checks so they fall back to the static
library or are skipped.
Also set policy CMP0164 to NEW so that any future unguarded
add_library(... SHARED ...) on an unsupported platform fails at
configure time instead of silently producing a colliding static archive.
See https://gitlab.kitware.com/cmake/cmake/-/issues/25759.
The bodies of the newly-conditional blocks are left at their original
indentation to keep this diff minimal. A follow-up commit will fix the
indentation. This was mostly AI generated with some comment fixups.
Co-authored-by: Claude (Opus 4.8) <noreply@anthropic.com>
GitOrigin-RevId: 885ef9daac3570ddfdd20cc82296eeae5b2c6613
2 files changed