Cross compilation with linaro toolchain on windows

Hi,

I’m trying to cross compile a project on windows using visual studio:
cmake -G “Visual Studio 17 2022” -A ARM -DCMAKE_TOOLCHAIN_FILE=C:/CMAKE_sample/toolchain/toolchain_windows.cmake …

this is my toolchain file:

INCLUDE(CMakeForceCompiler)
message(STATUS "toolchain windows called")
#SET(CMAKE_ECLIPSE_VERSION 4.22.0)
set(CMAKE_VERBOSE_MAKEFILE ON)
# this one is important
SET(CMAKE_SYSTEM_NAME Linux)
#this one not so much
SET(CMAKE_SYSTEM_VERSION 1)
SET(CMAKE_SYSTEM_PROCESSOR arm)

#set(CMAKE_C_COMPILER_WORKS 1)

# https://releases.linaro.org/components/toolchain/binaries/4.9-2016.02/arm-linux-gnueabihf/gcc-linaro-4.9-2016.02-i686-mingw32_arm-linux-gnueabihf.tar.xz
SET(TOOLCHAIN_ROOT_PATH C:/vendors/toolchains/windows/gcc-linaro-4.9-2-mingw32_arm-linux-gnueabihf)
#message(STATUS "toolchain windows set root path ${TOOLCHAIN_ROOT_PATH}")
SET(TOOLCHAIN_GCC_PATH C:/vendors/toolchains/windows/gcc-linaro-4.9-2-mingw32_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc.exe)
#message(STATUS "toolchain windows set gcc path ${TOOLCHAIN_GCC_PATH}")
#SET(TOOLCHAIN_SYS_PATH Vendors/toolchains/linux/sysroot-linaro-eglibc-gcc4.9)

# specify the cross compiler
set(CMAKE_SYSROOT ${VENDORS}/toolchains/sysroot-linaro-eglibc-gcc4.9-2016.02-arm-linux-gnueabihf)
set(CMAKE_C_COMPILER C:/vendors/toolchains/windows/gcc-linaro-4.9-2-mingw32_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc.exe)
set(CMAKE_CXX_COMPILER C:/vendors/toolchains/windows/gcc-linaro-4.9-2-mingw32_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++.exe)
#message(STATUS "set toolchain '${TOOLCHAIN_GCC_PATH}'")

#set(CMAKE_C_COMPILER_ID_RUN TRUE)
#set(CMAKE_C_COMPILER_FORCED TRUE)

# where is the target environment 
SET(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_ROOT_PATH})
#set (CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} "${TRUNK}/${TOOLCHAIN_SYS_PATH}"))

set(CMAKE_EXPORT_COMPILE_COMMANDS=ON)
# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
#SET(SYSTEM_USR_DIR /usr/local/linaro/arm-linux-gnueabihf/)

It looks like that visual studio is not using my toolchain;

– The C compiler identification is MSVC 19.32.31329.0
– Detecting C compiler ABI info
– Detecting C compiler ABI info - done
– Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.32.31326/bin/Hostx64/arm/cl.exe - skipped

AFAIK the Visual Studio generator only knows how to use compilers available inside VS.
For other compilers use Ninja or Make generator.

Yes, for VS generators to use a toolchain, it needs to be selectable with cmake -T. Toolchain files do just about nothing with the VS generators AFAIK.

Ok, I switch to CMakePresets.json

It works.

Thanks all,