CMake doesn't recognize the TI ARM Clang toolchain

Hi. I’m trying to use the Texas instruments Arm Clang (tiarmclang) toolchain for cross-compiling for an ARM device. The problem is that Cmake doesn’t recognize the toolchain and output an error even when i set the compiler ID to TI or ARMClang. I dont know what to try next. Here are the configurations and outputs
toolchain.cmake

file(GLOB TOOLCHAIN_DIRECTORIES
    "$ENV{TI_TOOLCHAIN_PATH}"
    "/opt/GNU Arm Embedded Toolchain/12.2-rel1/bin"
    "/Applications/GNU Arm Embedded Toolchain/12.2-rel1/bin"
)

# Count the available toolchains
list(LENGTH TOOLCHAIN_DIRECTORIES TOOLCHAIN_DIRECTORIES_COUNT)

if(TOOLCHAIN_DIRECTORIES_COUNT LESS 1)
    message(FATAL_ERROR "Could not find an ARM toolchain installation. Please install a toolchain.")
else()
    list(GET TOOLCHAIN_DIRECTORIES 0 TOOLCHAIN_DIRECTORY)
endif()

# Set the suffix of executables if on Windows
if(WIN32)
    set(TOOLCHAIN_SUFFIX ".exe")
endif()

set(CMAKE_SYSTEM_NAME                  Generic)
set(CMAKE_SYSTEM_PROCESSOR             ARM)

if(TOOLCHAIN_DIRECTORY PATH_EQUAL "$ENV{TI_TOOLCHAIN_PATH}")
    set(TOOLCHAIN_PREFIX               "tiarm")
elseif(TOOLCHAIN_DIRECTORY PATH_EQUAL "$ENV{GNU_TOOLCHAIN_PATH}")
    set(TOOLCHAIN_PREFIX               "arm-none-eabi-")
endif()

if(DEFINED TOOLCHAIN_DIRECTORY)
    set(TOOLCHAIN_PREFIX               "${TOOLCHAIN_DIRECTORY}/${TOOLCHAIN_PREFIX}")
endif()

# Set the target architecture for cross-compiling when using LLVM/Clang
#set(CMAKE_C_COMPILER_TARGET            armv7em-none-eabi)
#set(CMAKE_ASM_COMPILER_TARGET          armv7em-none-eabi)
#set(CMAKE_CXX_COMPILER_TARGET          armv7em-none-eabi)

if(TOOLCHAIN_DIRECTORY PATH_EQUAL "$ENV{TI_TOOLCHAIN_PATH}")
    set(CPP_OPTIONS                    "-fno-rtti -fno-exceptions")
elseif(TOOLCHAIN_DIRECTORY PATH_EQUAL "$ENV{GNU_TOOLCHAIN_PATH}")
    set(CPP_OPTIONS                    "-fno-rtti -fno-exceptions -fno-threadsafe-statics")
endif()

set(ASM_OPTIONS                        "-x assembler-with-cpp")
set(CPP_OPTIONS                        "-fno-rtti -fno-exceptions -fno-threadsafe-statics")

if(TOOLCHAIN_DIRECTORY PATH_EQUAL "$ENV{TI_TOOLCHAIN_PATH}")
    set(CMAKE_C_COMPILER               ${TOOLCHAIN_PREFIX}clang${TOOLCHAIN_SUFFIX} -march=thumbv7em)
    set(CMAKE_ASM_COMPILER             ${TOOLCHAIN_PREFIX}clang${TOOLCHAIN_SUFFIX} ${ASM_OPTIONS})
    set(CMAKE_CXX_COMPILER             ${TOOLCHAIN_PREFIX}clang${TOOLCHAIN_SUFFIX} ${CPP_OPTIONS})
elseif(TOOLCHAIN_DIRECTORY PATH_EQUAL "$ENV{GNU_TOOLCHAIN_PATH}")
    set(CMAKE_C_COMPILER               ${TOOLCHAIN_PREFIX}gcc${TOOLCHAIN_SUFFIX})
    set(CMAKE_ASM_COMPILER             ${TOOLCHAIN_PREFIX}gcc${TOOLCHAIN_SUFFIX} ${ASM_OPTIONS})
    set(CMAKE_CXX_COMPILER             ${TOOLCHAIN_PREFIX}g++${TOOLCHAIN_SUFFIX} ${CPP_OPTIONS})
endif()

set(CMAKE_OBJCOPY                      ${TOOLCHAIN_PREFIX}objcopy${TOOLCHAIN_SUFFIX})
set(CMAKE_SIZE                         ${TOOLCHAIN_PREFIX}size${TOOLCHAIN_SUFFIX})
set(CMAKE_READELF                      ${TOOLCHAIN_PREFIX}readelf${TOOLCHAIN_SUFFIX})

set(CMAKE_EXECUTABLE_SUFFIX_ASM        ".elf")
set(CMAKE_EXECUTABLE_SUFFIX_C          ".elf")
set(CMAKE_EXECUTABLE_SUFFIX_CXX        ".elf")

set(CMAKE_TRY_COMPILE_TARGET_TYPE      STATIC_LIBRARY)

set(CMAKE_FIND_ROOT_PATH               ${TOOLCHAIN_DIRECTORY})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM  NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY  ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE  ONLY)

output error:

[cmake] -- The C compiler identification is Clang 15.0.7
[cmake] -- The CXX compiler identification is Clang 15.0.7
[cmake] -- The ASM compiler identification is unknown
[cmake] -- Found assembler: C:/TI_LLVM_Arm_Embedded_Toolchain/bin/tiarmclang.exe
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - failed
[cmake] -- Check for working C compiler: C:/TI_LLVM_Arm_Embedded_Toolchain/bin/tiarmclang.exe
[cmake] -- Check for working C compiler: C:/TI_LLVM_Arm_Embedded_Toolchain/bin/tiarmclang.exe - broken
[cmake] CMake Error at C:/Program Files/CMake/share/cmake-3.25/Modules/CMakeTestCCompiler.cmake:70 (message):
[cmake]   The C compiler
[cmake] 
[cmake]     "C:/TI_LLVM_Arm_Embedded_Toolchain/bin/tiarmclang.exe"
[cmake] 
[cmake]   is not able to compile a simple test program.
[cmake] 
[cmake]   It fails with the following output:
[cmake] 
[cmake]     Change Dir: C:/Users/herma/Bureau/Hermann/EBIKE/Codes/Firmware/build/debug/CMakeFiles/CMakeScratch/TryCompile-ggbdib
[cmake]     
[cmake]     Run Build Command(s):C:/PROGRA~1/Ninja/ninja.exe cmTC_3f819 && [1/2] Building C object CMakeFiles/cmTC_3f819.dir/testCCompiler.c.obj
[cmake]     [2/2] Linking C static library libcmTC_3f819.a
[cmake]     FAILED: libcmTC_3f819.a 
[cmake]     cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E rm -f libcmTC_3f819.a && C:\cygwin64\bin\llvm-ar.exe qc libcmTC_3f819.a  CMakeFiles/cmTC_3f819.dir/testCCompiler.c.obj && C:\cygwin64\bin\llvm-ranlib libcmTC_3f819.a && cd ."
[cmake]     ninja: build stopped: subcommand failed.
[cmake]     
[cmake]     
[cmake] 
[cmake]   
[cmake] 
[cmake]   CMake will not be able to correctly generate this project.
[cmake] Call Stack (most recent call first):
[cmake]   CMakeLists.txt:13 (project)
[cmake] 
[cmake] 
[cmake] -- Configuring incomplete, errors occurred!
[cmake] See also "C:/Users/herma/Bureau/Hermann/EBIKE/Codes/Firmware/build/debug/CMakeFiles/CMakeOutput.log".
[cmake] See also "C:/Users/herma/Bureau/Hermann/EBIKE/Codes/Firmware/build/debug/CMakeFiles/CMakeError.log".
[proc] The command: "C:\Program Files\CMake\bin\cmake.EXE" -DCMAKE_BUILD_TYPE=Debug "-DCMAKE_C_FLAGS_DEBUG=-g -g3 -O0 -ggdb" "-DCMAKE_ASM_FLAGS_DEBUG=-g -g3 -O0 -ggdb" "-DCMAKE_CXX_FLAGS_DEBUG=-g -g3 -O0 -ggdb" -DCMAKE_TOOLCHAIN_FILE:FILEPATH=C:/Users/herma/Bureau/Hermann/EBIKE/Codes/Firmware/cmake/arm-none-eabi.cmake -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_RUNTIME_OUTPUT_DIRECTORY:FILEPATH=C:/Users/herma/Bureau/Hermann/EBIKE/Codes/Firmware/bin/debug -DCMAKE_INSTALL_PREFIX=C:/Users/herma/Bureau/Hermann/EBIKE/Codes/Firmware/build/install/debug -SC:/Users/herma/Bureau/Hermann/EBIKE/Codes/Firmware -BC:/Users/herma/Bureau/Hermann/EBIKE/Codes/Firmware/build/debug -G Ninja exited with code: 1

I don’t think that the compiler has been taught to CMake yet. AFAICT, all TI references seem to be about their older, non-Clang toolchains.

I thinks too. by the way when I bypass the compiler check with these 2 commands the compilation success. I don’t know the drawback

set(CMAKE_C_COMPILER_WORKS             1)
set(CMAKE_CXX_COMPILER_WORKS           1)

Hello! I wanted to update this thread; support for tiarmclang was added to CMake 3.29.

Reference issue addressed by commit 9ba0a545

Thanks!