https://github.com/wenju-he created https://github.com/llvm/llvm-project/pull/186717
When LLVM_TARGETS_TO_BUILD does not contain the host target, runtime build can not identify a compatible target triple for the host compiler. CMAKE_C_COMPILER is set to clang (e.g., instead of clang-cl on Windows), and CMAKE_C_COMPILER_ID is empty although the compiler is functional. Update CMakeDetermineCLCCompiler to manually verify compiler is clang via '--version'. This ensures valid configurations can proceed, e.g.: LLVM_TARGETS_TO_BUILD=AMDGPU;LIBCLC_TARGETS_TO_BUILD=amdgcn-amd-amdhsa-llvm >From 42cb1aa23e196c64161419d646a7d31694fbeca8 Mon Sep 17 00:00:00 2001 From: Wenju He <[email protected]> Date: Mon, 16 Mar 2026 00:24:15 +0100 Subject: [PATCH] [libclc][CMake] Allow empty CMAKE_C_COMPILER_ID when CMAKE_C_COMPILER_WORKS is set When LLVM_TARGETS_TO_BUILD does not contain the host target, runtime build can not identify a compatible target triple for the host compiler. CMAKE_C_COMPILER is set to clang (e.g., instead of clang-cl on Windows), and CMAKE_C_COMPILER_ID is empty although the compiler is functional. Update CMakeDetermineCLCCompiler to manually verify compiler is clang via '--version'. This ensures valid configurations can proceed, e.g.: LLVM_TARGETS_TO_BUILD=AMDGPU;LIBCLC_TARGETS_TO_BUILD=amdgcn-amd-amdhsa-llvm --- .../modules/CMakeDetermineCLCCompiler.cmake | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/libclc/cmake/modules/CMakeDetermineCLCCompiler.cmake b/libclc/cmake/modules/CMakeDetermineCLCCompiler.cmake index 2138ad85d0059..7aec85fdc9daa 100644 --- a/libclc/cmake/modules/CMakeDetermineCLCCompiler.cmake +++ b/libclc/cmake/modules/CMakeDetermineCLCCompiler.cmake @@ -1,9 +1,29 @@ if(NOT CMAKE_CLC_COMPILER) - if(NOT CMAKE_C_COMPILER_ID MATCHES "Clang") - message(FATAL_ERROR - "The CLC language requires the C compiler (CMAKE_C_COMPILER) to be " - "Clang, but CMAKE_C_COMPILER_ID is '${CMAKE_C_COMPILER_ID}'.") + set(is_clang FALSE) + if(CMAKE_C_COMPILER_ID MATCHES "Clang") + set(is_clang TRUE) + elseif(NOT CMAKE_C_COMPILER_ID AND CMAKE_C_COMPILER_WORKS) + # When ID is empty but compiler works, verify it's actually clang. + execute_process( + COMMAND "${CMAKE_C_COMPILER}" --version + OUTPUT_VARIABLE version_output + ERROR_VARIABLE version_output + RESULT_VARIABLE res + ) + if(res EQUAL 0 AND version_output MATCHES "[Cc]lang") + set(is_clang TRUE) + endif() endif() + + if(NOT is_clang) + if(CMAKE_C_COMPILER_ID) + set(reason "Found '${CMAKE_C_COMPILER_ID}'") + else() + set(reason "Version check failed for '${CMAKE_C_COMPILER}'") + endif() + message(FATAL_ERROR "The CLC language requires Clang. ${reason}.") + endif() + set(CMAKE_CLC_COMPILER "${CMAKE_C_COMPILER}" CACHE FILEPATH "CLC compiler") endif() _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
