But the CMAKE_CXX_STANDARD_LIBRARY
is set in CMakeDetermineComilerId.cmake
:
set(CMAKE_${lang}_STANDARD_LIBRARY "")
if ("x${lang}" STREQUAL "xCXX" AND
EXISTS "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/${lang}-DetectStdlib.h" AND
("x${CMAKE_${lang}_COMPILER_ID}" STREQUAL "xClang" AND
"x${CMAKE_${lang}_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU") OR
("x${CMAKE_${lang}_COMPILER_ID}" STREQUAL "xGNU"))
# See #20851 for a proper abstraction for this.
execute_process(
COMMAND "${CMAKE_${lang}_COMPILER}"
${CMAKE_${lang}_COMPILER_ID_ARG1}
${CMAKE_CXX_COMPILER_ID_FLAGS_LIST}
-E
-x c++-header
"${CMAKE_CURRENT_FUNCTION_LIST_DIR}/${lang}-DetectStdlib.h"
-o - # Write to stdout.
OUTPUT_VARIABLE _lang_stdlib_out
ERROR_VARIABLE _lang_stdlib_err
RESULT_VARIABLE _lang_stdlib_res
ERROR_STRIP_TRAILING_WHITESPACE)
if (_lang_stdlib_res EQUAL 0)
string(REGEX REPLACE ".*CMAKE-STDLIB-DETECT: (.+)\n.*" "\\1" "CMAKE_${lang}_STANDARD_LIBRARY" "${_lang_stdlib_out}")
endif ()
endif ()
default set to:
Modules/CMakeDetermineCompilerId.cmake(434): set(CMAKE_CXX_STANDARD_LIBRARY libstdc++ PARENT_SCOPE )
But this helps:
CXX=clang++-20 CXXFLAGS=-stdlib=libc++ cmake -G Ninja -S . -B build --trace-expand --trace-source=CMakeDetermineCompilerId.cmake --fresh