detect_cxx_stdlibs: Only detect for dylibs

Fixes #23115.