I am trying to use CMAKE to run the Arduino compiler in Windows via CMAKE. I created a little .cmake
file that can locate and override a few toolchain variables such as CMAKE_C_COMPILER
. This works great on Linux. Everything is getting found and built. In Linux, I am using the UNIX Makefiles generator.
However, when I come over to Windows, I have problems. I would like to have both the NMake and Visual Studio generators working. If I had to pick one, I will go with least complex (NMake)
The NMake generator insists on adding command line switches for cl.exe (/nologo, /DWIN32, etc) These create errors and stop the build.
The NMake generator does use the path to the arduino compiler. (good)
The Visual Studio generator insists on using cl.exe (bad) and it puts into the command line switches for cl.exe (bad)
How do I stop it from adding the cl.exe command line switches?
The code looks something like this:
set(TOOLCHAIN_ROOT "C:\Program Files (x86)\Arduino\hardware\tools\arm")
if(WIN32)
set(TOOL_OS_SUFFIX .exe)
else(WIN32)
set(TOOL_OS_SUFFIX )
endif(WIN32)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_CROSSCOMPILING 1)
set(CMAKE_C_COMPILER "${TOOLCHAIN_ROOT}/bin/${TRIPLE}-gcc${TOOL_OS_SUFFIX}")
set(CMAKE_CXX_COMPILER "${TOOLCHAIN_ROOT}/bin/${TRIPLE}-g++${TOOL_OS_SUFFIX}")
set(CMAKE_AR "${TOOLCHAIN_ROOT}/bin/${TRIPLE}-ar${TOOL_OS_SUFFIX}")
set(CMAKE_LINKER "${TOOLCHAIN_ROOT}/bin/${TRIPLE}-ld${TOOL_OS_SUFFIX}")
set(CMAKE_NM "${TOOLCHAIN_ROOT}/bin/${TRIPLE}-nm${TOOL_OS_SUFFIX}")
set(CMAKE_OBJCOPY "${TOOLCHAIN_ROOT}/bin/${TRIPLE}-objcopy${TOOL_OS_SUFFIX}")
set(CMAKE_OBJDUMP "${TOOLCHAIN_ROOT}/bin/${TRIPLE}-objdump${TOOL_OS_SUFFIX}")
set(CMAKE_STRIP "${TOOLCHAIN_ROOT}/bin/${TRIPLE}-strip${TOOL_OS_SUFFIX}")
set(CMAKE_RANLIB "${TOOLCHAIN_ROOT}/bin/${TRIPLE}-ranlib${TOOL_OS_SUFFIX}")
Here is what the output looks like:
Scanning dependencies of target MyProject
[ 2%] Building C object CMakeFiles/MyProject.dir/main.c.obj
arm-none-eabi-gcc.exe: error: /nologo: No such file or directory
arm-none-eabi-gcc.exe: error: /DWIN32: No such file or directory
arm-none-eabi-gcc.exe: error: /D_WINDOWS: No such file or directory
arm-none-eabi-gcc.exe: error: /W3: No such file or directory
arm-none-eabi-gcc.exe: error: /D_DEBUG: No such file or directory
arm-none-eabi-gcc.exe: error: /MDd: No such file or directory
arm-none-eabi-gcc.exe: error: /Zi: No such file or directory
arm-none-eabi-gcc.exe: error: /Ob0: No such file or directory
arm-none-eabi-gcc.exe: error: /Od: No such file or directory
arm-none-eabi-gcc.exe: error: /RTC1: No such file or directory
arm-none-eabi-gcc.exe: error: /FoCMakeFilesMyProject.dirmain.c.obj: No such file or directory
arm-none-eabi-gcc.exe: error: /FdCMakeFilesMyProject.dir -c: No such
file or directory
arm-none-eabi-gcc.exe: error: D:projectsexamplecode.c: No such file or directory
arm-none-eabi-gcc.exe: fatal error: no input files
compilation terminated.