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.
CMake command:
cmake -DCMAKE_TOOLCHAIN_FILE="..\Src\Build\Toolchain-clang-arm.cmake" -GNinja ..\Src\
Output:
-- 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
"C:/Program Files/LLVM/bin/clang.exe"
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):
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)-- Configuring incomplete, errors occurred!
CMake toolchain file (Toolchain-clang-arm.cmake):
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")
I used the CMake and Clang documentation and some random link 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.
EDIT
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:
CMAKE_FORCE_C_COMPILER(clang Clang)
CMAKE_FORCE_CXX_COMPILER(clang++ Clang)
The error stays the same.
EDIT
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 bug in the CMake issue tracker.
Tool versions:
- clang version 7.0.0 (tags/RELEASE_700/final)
- cmake version 3.13.4