Merge topic 'import-std-clang-cl'

1610aa22f4 Clang: Add support for `import std` when targeting the MSVC ABI
b9bb2b1256 CompilerId: detect MSVC STL for clang-cl

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12249
This commit is contained in:
Brad King
2026-07-09 14:04:34 +00:00
committed by Kitware Robot
5 changed files with 47 additions and 22 deletions

View File

@@ -1,4 +1,4 @@
set(CMake_TEST_MODULE_COMPILATION "named,compile_commands,collation,partitions,internal_partitions,export_bmi,install_bmi,shared,bmionly,build_database" CACHE STRING "")
set(CMake_TEST_MODULE_COMPILATION "named,compile_commands,collation,partitions,internal_partitions,export_bmi,install_bmi,shared,bmionly,build_database,import_std23" CACHE STRING "")
if("$ENV{CMAKE_CI_BUILD_NAME}" MATCHES "(^|_)cl(_|$)")
set(CMAKE_Fortran_COMPILER "flang" CACHE STRING "")
set(CMAKE_Fortran_COMPILER_ID "LLVMFlang" CACHE STRING "")

View File

@@ -395,13 +395,29 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
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 "xClang") OR
("x${CMAKE_${lang}_COMPILER_ID}" STREQUAL "xGNU"))
# See #20851 for a proper abstraction for this.
# Forward configured stdlib include dirs so this probe can find <version>
# in non-default toolchain layouts (e.g. clang-cl with MSVC STL).
set(_inc_dirs)
set(_inc_opt "")
if (CMAKE_${lang}_COMPILER_FRONTEND_VARIANT STREQUAL "GNU")
set(_inc_opt -isystem)
elseif (CMAKE_${lang}_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
set(_inc_opt -imsvc)
endif ()
if (_inc_opt)
foreach(_inc_path IN LISTS CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES)
list(APPEND _inc_dirs "${_inc_opt}" "${_inc_path}")
endforeach()
endif ()
execute_process(
COMMAND "${CMAKE_${lang}_COMPILER}"
${CMAKE_${lang}_COMPILER_ID_ARG1}
${_inc_dirs}
${CMAKE_CXX_COMPILER_ID_FLAGS_LIST}
-E
-x c++-header

View File

@@ -4,6 +4,8 @@
CMAKE-STDLIB-DETECT: libc++
#elif defined(__GLIBCXX__)
CMAKE-STDLIB-DETECT: libstdc++
#elif defined(_MSVC_STL_VERSION)
CMAKE-STDLIB-DETECT: msvc
#else
CMAKE-STDLIB-DETECT: UNKNOWN
#endif

View File

@@ -1,3 +1,10 @@
if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC" OR
CMAKE_CXX_STANDARD_LIBRARY STREQUAL "msvc" OR
CMAKE_CXX_COMPILER_TARGET MATCHES "(^|-)windows-msvc($|-)")
include(Compiler/MSVC-CXX-CXXImportStd)
return()
endif()
function (_cmake_cxx_find_modules_json)
if (NOT CMAKE_CXX_STDLIB_MODULES_JSON)
if (CMAKE_CXX_STANDARD_LIBRARY STREQUAL "libc++")

View File

@@ -1,24 +1,24 @@
function (_cmake_cxx_find_modules_json)
if (CMAKE_CXX_STDLIB_MODULES_JSON)
return ()
endif ()
find_file(_msvc_modules_json_file
NAME modules.json
HINTS
"$ENV{VCToolsInstallDir}/modules"
PATHS
"$ENV{INCLUDE}"
"${CMAKE_CXX_COMPILER}/../../.."
"${CMAKE_CXX_COMPILER}/../.." # msvc-wine layout
PATH_SUFFIXES
../modules
NO_CACHE)
# Without this file, we do not have modules installed.
if (NOT EXISTS "${_msvc_modules_json_file}")
set(CMAKE_CXX_COMPILER_IMPORT_STD_ERROR_MESSAGE "Could not find `modules.json` resource" PARENT_SCOPE)
return ()
set(_msvc_modules_json_file "${CMAKE_CXX_STDLIB_MODULES_JSON}")
else ()
find_file(_msvc_modules_json_file
NAME modules.json
HINTS
"$ENV{VCToolsInstallDir}/modules"
PATHS
"$ENV{INCLUDE}"
${CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES}
"${CMAKE_CXX_COMPILER}/../../.."
"${CMAKE_CXX_COMPILER}/../.." # msvc-wine layout
PATH_SUFFIXES
../modules
NO_CACHE)
# Without this file, we do not have modules installed.
if (NOT EXISTS "${_msvc_modules_json_file}")
set(CMAKE_CXX_COMPILER_IMPORT_STD_ERROR_MESSAGE "Could not find `modules.json` resource" PARENT_SCOPE)
return ()
endif ()
endif ()
file(READ "${_msvc_modules_json_file}" _msvc_modules_json)