IAR: Support for Embedded Workbench is broken in CMake 3.21.x
I'm using Windows 10 and IAR Embedded Workbench for Arm 8.40.2.
Input files
CMakeLists.txt
project(TestProject ASM C CXX)
cmake_minimum_required(VERSION 3.18)
add_executable(TestExecutable)
target_sources(TestExecutable
PRIVATE
main.cpp
)
toolchain_iar.cmake
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_ASM_COMPILER "c:/Program Files (x86)/IAR Systems/Embedded Workbench 8.3/arm/bin/iasmarm.exe")
set(CMAKE_C_COMPILER "c:/Program Files (x86)/IAR Systems/Embedded Workbench 8.3/arm/bin/iccarm.exe")
set(CMAKE_CXX_COMPILER "c:/Program Files (x86)/IAR Systems/Embedded Workbench 8.3/arm/bin/iccarm.exe")
Expected result
It works as in CMake 3.20.5:
"c:\Program Files\CMake 3.20.5\bin\cmake.exe" -S . -B build -G Ninja -D CMAKE_TOOLCHAIN_FILE=toolchain_iar.cmake
-- The ASM compiler identification is IAR ARM 8.40.2
-- Found assembler: c:/Program Files (x86)/IAR Systems/Embedded Workbench 8.3/arm/bin/iasmarm.exe
-- The C compiler identification is IAR ARM 8.40.2
-- The CXX compiler identification is IAR ARM 8.40.2
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: c:/Program Files (x86)/IAR Systems/Embedded Workbench 8.3/arm/bin/iccarm.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: c:/Program Files (x86)/IAR Systems/Embedded Workbench 8.3/arm/bin/iccarm.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: M:/build
Actual result
In CMake 3.21.0, it fails because a non-IAR linker is used:
"c:\Program Files\CMake 3.21.0\bin\cmake.exe" -S . -B build -G Ninja -D CMAKE_TOOLCHAIN_FILE=toolchain_iar.cmake
-- The ASM compiler identification is IAR ARM 8.40.2
-- Found assembler: c:/Program Files (x86)/IAR Systems/Embedded Workbench 8.3/arm/bin/iasmarm.exe
-- The C compiler identification is IAR ARM 8.40.2
-- The CXX compiler identification is IAR ARM 8.40.2
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: c:/Program Files (x86)/IAR Systems/Embedded Workbench 8.3/arm/bin/iccarm.exe
-- Check for working C compiler: c:/Program Files (x86)/IAR Systems/Embedded Workbench 8.3/arm/bin/iccarm.exe - broken
CMake Error at C:/Program Files/CMake 3.21.0/share/cmake-3.21/Modules/CMakeTestCCompiler.cmake:66 (message):
The C compiler
"c:/Program Files (x86)/IAR Systems/Embedded Workbench 8.3/arm/bin/iccarm.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: M:/build/CMakeFiles/CMakeTmp
Run Build Command(s):C:/ProgramData/chocolatey/bin/ninja.exe cmTC_7eefd && [1/2] Building C object CMakeFiles\cmTC_7eefd.dir\testCCompiler.c.o
[2/2] Linking C executable cmTC_7eefd.elf
FAILED: cmTC_7eefd.elf
cmd.exe /C "cd . && C:\MinGW\bin\ld.exe --silent CMakeFiles\cmTC_7eefd.dir\testCCompiler.c.o -o cmTC_7eefd.elf && cd ."
C:\MinGW\bin\ld.exe: unrecognized option '--silent'
C:\MinGW\bin\ld.exe: use the --help option for usage information
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:1 (project)
-- Configuring incomplete, errors occurred!
See also "M:/build/CMakeFiles/CMakeOutput.log".
See also "M:/build/CMakeFiles/CMakeError.log".
In CMake 3.21.1 and 3.21.2, it fails because of an error in one of the internal CMake files:
"c:\Program Files\CMake 3.21.1\bin\cmake.exe" -S . -B build -G Ninja -D CMAKE_TOOLCHAIN_FILE=toolchain_iar.cmake
-- The ASM compiler identification is IAR ARM 8.40.2
CMake Warning (dev) at C:/Program Files/CMake 3.21.1/share/cmake-3.21/Modules/CMakeFindBinUtils.cmake:120 (if):
Policy CMP0057 is not set: Support new IN_LIST if() operator. Run "cmake
--help-policy CMP0057" for policy details. Use the cmake_policy command to
set the policy and suppress this warning.
IN_LIST will be interpreted as an operator when the policy is set to NEW.
Since the policy is not set the OLD behavior will be used.
Call Stack (most recent call first):
C:/Program Files/CMake 3.21.1/share/cmake-3.21/Modules/CMakeDetermineASMCompiler.cmake:197 (include)
CMakeLists.txt:1 (project)
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Error at C:/Program Files/CMake 3.21.1/share/cmake-3.21/Modules/CMakeFindBinUtils.cmake:120 (if):
if given arguments:
"ARM" "IN_LIST" "_CMAKE_IAR_ITOOLS"
Unknown arguments specified
Call Stack (most recent call first):
C:/Program Files/CMake 3.21.1/share/cmake-3.21/Modules/CMakeDetermineASMCompiler.cmake:197 (include)
CMakeLists.txt:1 (project)
-- Configuring incomplete, errors occurred!
See also "M:/build/CMakeFiles/CMakeOutput.log".
See also "M:/build/CMakeFiles/CMakeError.log".