title: How to set up CMake to cross compile with clang for ARM embedded on Windows?
body: <p>I'm trying to generate Ninja makefiles to cross compile a C++ project with Clang for an ARM Cortex A5 CPU. I created a toolchain file for CMake but it seems like there is an error or something missing which I'm unable to find. When invoke CMake with the toolchain file below I get the following error.</p>
  
  <p><strong>CMake command:</strong></p>
  
  <blockquote>
    <p>cmake -DCMAKE_TOOLCHAIN_FILE="..\Src\Build\Toolchain-clang-arm.cmake"
    -GNinja ..\Src\</p>
  </blockquote>
  
  <p><strong>Output:</strong></p>
  
  <blockquote>
    <p>-- The C compiler identification is Clang 7.0.0 CMake Error at C:/Users/user/scoop/apps/cmake/3.13.4/share/cmake-3.13/Modules/CMakeDetermineCompilerId.cmake:802
    (message):   The Clang compiler tool</p>
    
    <p>"C:/Program Files/LLVM/bin/clang.exe"</p>
    
    <p>targets the MSVC ABI but has a GNU-like command-line interface. 
    This is   not supported.  Use 'clang-cl' instead, e.g.  by setting
    'CC=clang-cl' in   the environment.  Furthermore, use the MSVC
    command-line environment. Call Stack (most recent call first):<br>
    C:/Users/user/scoop/apps/cmake/3.13.4/share/cmake-3.13/Modules/CMakeDetermineCCompiler.cmake:113
    (CMAKE_DIAGNOSE_UNSUPPORTED_CLANG)   CMakeLists.txt:2 (PROJECT)</p>
    
    <p>-- Configuring incomplete, errors occurred!</p>
  </blockquote>
  
  <p><strong>CMake toolchain file</strong> (Toolchain-clang-arm.cmake):</p>
  
  <pre><code>set(CMAKE_CROSSCOMPILING TRUE)
  SET(CMAKE_SYSTEM_NAME Generic)
  set(CMAKE_SYSTEM_PROCESSOR arm)
  
  # Clang target triple
  SET(TARGET armv7-none-eabi)
  
  # specify the cross compiler
  SET(CMAKE_C_COMPILER_TARGET ${TARGET})
  SET(CMAKE_C_COMPILER clang)
  SET(CMAKE_CXX_COMPILER_TARGET ${TARGET})
  SET(CMAKE_CXX_COMPILER clang++)
  SET(CMAKE_ASM_COMPILER_TARGET ${TARGET})
  SET(CMAKE_ASM_COMPILER clang)
  
  # C/C++ toolchain
  SET(TOOLCHAIN "C:/Program Files (x86)/GNU Tools ARM Embedded/7 2018-q2-update")
  SET(CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN ${TOOLCHAIN})
  SET(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN ${TOOLCHAIN})
  
  # specify compiler flags
  SET(ARCH_FLAGS "-target armv7-none-eabi -mcpu=cortex-a5")
  SET(CMAKE_C_FLAGS "-Wall -Wextra ${ARCH_FLAGS}" CACHE STRING "Common flags for C compiler")
  SET(CMAKE_CXX_FLAGS "-Wall -Wextra -std=c++11 -fno-exceptions -fno-threadsafe-statics ${ARCH_FLAGS}" CACHE STRING "Common flags for C++ compiler")
  </code></pre>
  
  <p>I used the <a href="https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-using-clang" rel="noreferrer">CMake</a> and <a href="https://clang.llvm.org/docs/CrossCompilation.html" rel="noreferrer">Clang</a> documentation and some <a href="https://gist.github.com/vpetrigo/29e3bfbe7d4aa133e4f661c8420af172" rel="noreferrer">random link</a> from the net to create the toolchain file. The whole project compiles fine with ARM GCC for Windows, so the toolchain file seems to be the only missing piece of the puzzle.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I tried to work around the CMake compiler checks by forcing the compiler. I replace the lines with SET(CMAKE_C_COMPILER clang), SET(CMAKE_CXX_COMPILER clang++) etc. with:</p>
  
  <pre><code>CMAKE_FORCE_C_COMPILER(clang Clang)
  CMAKE_FORCE_CXX_COMPILER(clang++ Clang)
  </code></pre>
  
  <p>The error stays the same.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I can successfully compile a hello world example with clang -target arm-none-eabi. So the issue seems to be in CMake. I created a <a href="https://gitlab.kitware.com/cmake/cmake/issues/18880" rel="noreferrer">bug</a> in the CMake issue tracker.</p>
  
  <p><strong>Tool versions:</strong></p>
  
  <ul>
  <li>clang version 7.0.0 (tags/RELEASE_700/final)</li>
  <li>cmake version 3.13.4</li>
  </ul>