Closed SHO538 closed 1 year ago
Thank you for your feedback and for choosing IAR.
Please try this:
C:\Users\felipeto>cd cmake-tutorial\examples\arm\hello-world
C:\Users\felipeto\cmake-tutorial\examples\arm\hello-world>cmake -Bbuild -GNinja --toolchain ../../iar-toolchain.cmake
-- The C compiler identification is IAR ARM 9.40.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/IAR/EW/ARM/9.40.1.63915/arm/bin/iccarm.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring done (1.1s)
-- Generating done (0.0s)
-- Build files have been written to: C:/Users/felipeto/cmake-tutorial/examples/arm/hello-world/build
C:\Users\felipeto\cmake-tutorial\examples\arm\hello-world>cmake --build build --verbose
Change Dir: 'C:/Users/felipeto/cmake-tutorial/examples/arm/hello-world/build'
Run Build Command(s): C:/Windows/ninja.exe -v
[1/2] C:\IAR\EW\ARM\9.40.1.63915\arm\bin\iccarm.exe --silent C:\Users\felipeto\cmake-tutorial\examples\arm\hello-world\main.c --cpu=Cortex-M4 --fpu=VFPv4_sp --dlib_config normal --dependencies=ns CMakeFiles\hello-world.dir\main.o.d -o CMakeFiles\hello-world.dir\main.o
[2/2] cmd.exe /C "cd . && C:\IAR\EW\ARM\9.40.1.63915\arm\bin\ilinkarm.exe CMakeFiles\hello-world.dir\main.o --silent --semihosting --config C:/IAR/EW/ARM/9.40.1.63915/arm/config/linker/ST/stm32f407xG.icf -o hello-world.elf && cd ."
C:\Users\felipeto\cmake-tutorial\examples\arm\hello-world>
Note As you can see, my tools were installed at
C:/IAR/EW/ARM/9.40.1.63915
so that I set myTOOLKIT
variable toC:/IAR/EW/ARM/9.40.1.63915
. Here is myiar-toolchain.cmake
for your reference:# Toolchain File for the IAR C/C++ Compiler
set(CMAKE_SYSTEM_NAME Generic)
TOOLKIT
variable#
#
set(TOOLKIT "C:/IAR/EW/ARM/9.40.1.63915/arm")
get_filename_component(CMAKE_SYSTEM_PROCESSOR ${TOOLKIT} NAME)
find_program(CMAKE_C_COMPILER NAMES icc${CMAKE_SYSTEM_PROCESSOR} PATHS ${TOOLKIT} "$ENV{ProgramFiles}/IAR Systems/" "$ENV{ProgramFiles(x86)}/IAR Systems/" /opt/iarsystems/bx${CMAKE_SYSTEM_PROCESSOR} PATH_SUFFIXES bin ${CMAKE_SYSTEM_PROCESSOR}/bin REQUIRED )
find_program(CMAKE_CXX_COMPILER NAMES icc${CMAKE_SYSTEM_PROCESSOR} PATHS ${TOOLKIT} "$ENV{PROGRAMFILES}/IAR Systems/" "$ENV{ProgramFiles(x86)}/IAR Systems/" /opt/iarsystems/bx${CMAKE_SYSTEM_PROCESSOR}- PATH_SUFFIXES bin ${CMAKE_SYSTEM_PROCESSOR}/bin REQUIRED )
find_program(CMAKE_ASM_COMPILER NAMES iasm${CMAKE_SYSTEM_PROCESSOR} a${CMAKE_SYSTEM_PROCESSOR} PATHS ${TOOLKIT} "$ENV{PROGRAMFILES}/IAR Systems/" "$ENV{ProgramFiles(x86)}/IAR Systems/" /opt/iarsystems/bx${CMAKE_SYSTEM_PROCESSOR} PATH_SUFFIXES bin ${CMAKE_SYSTEM_PROCESSOR}/bin REQUIRED )
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
get_filename_component(BIN_DIR ${CMAKE_C_COMPILER} DIRECTORY) get_filename_component(TOOLKIT_DIR ${BIN_DIR} PATH) unset(BIN_DIR)
Please adjust the paths as needed and let me know if that worked.
Thank you for your answer. I tried to change the TOOLKIT variable from arm to my arm IAR path, but I still got the issue. It seems the TOOLKIT variable has no incidence at the end, the arch is empty.
Here is my iar-toolchain.cmake file.
# Toolchain File for the IAR C/C++ Compiler
# Action: Set the `TOOLKIT` variable
# Examples: arm, riscv, rh850, rl78, rx, stm8, 430, 8051, avr or v850
# Alternative: override the default TOOLKIT_DIR (/path/to/installation/<arch>)
set(TOOLKIT "C:/Program Files/IAR Systems/Embedded Workbench 9.0/arm")
# Get the toolchain target from the TOOLKIT
get_filename_component(CMAKE_SYSTEM_PROCESSOR ${TOOLKIT} NAME)
# Set CMake for cross-compiling
set(CMAKE_SYSTEM_NAME Generic)
# IAR C Compiler
find_program(CMAKE_C_COMPILER
NAMES icc${CMAKE_SYSTEM_PROCESSOR}
PATHS ${TOOLKIT}
"$ENV{ProgramFiles}/IAR Systems/*"
"$ENV{ProgramFiles\(x86\)}/IAR Systems/*"
/opt/iarsystems/bx${CMAKE_SYSTEM_PROCESSOR}
PATH_SUFFIXES bin ${CMAKE_SYSTEM_PROCESSOR}/bin
REQUIRED )
# IAR C++ Compiler
find_program(CMAKE_CXX_COMPILER
NAMES icc${CMAKE_SYSTEM_PROCESSOR}
PATHS ${TOOLKIT}
"$ENV{PROGRAMFILES}/IAR Systems/*"
"$ENV{ProgramFiles\(x86\)}/IAR Systems/*"
/opt/iarsystems/bx${CMAKE_SYSTEM_PROCESSOR}
PATH_SUFFIXES bin ${CMAKE_SYSTEM_PROCESSOR}/bin
REQUIRED )
# IAR Assembler
find_program(CMAKE_ASM_COMPILER
NAMES iasm${CMAKE_SYSTEM_PROCESSOR} a${CMAKE_SYSTEM_PROCESSOR}
PATHS ${TOOLKIT}
"$ENV{PROGRAMFILES}/IAR Systems/*"
"$ENV{ProgramFiles\(x86\)}/IAR Systems/*"
/opt/iarsystems/bx${CMAKE_SYSTEM_PROCESSOR}
PATH_SUFFIXES bin ${CMAKE_SYSTEM_PROCESSOR}/bin
REQUIRED )
# Avoids running the linker during try_compile()
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
# Set the TOOLKIT_DIR variable for the CMakeLists
get_filename_component(BIN_DIR ${CMAKE_C_COMPILER} DIRECTORY)
get_filename_component(TOOLKIT_DIR ${BIN_DIR} PATH)
unset(BIN_DIR)
and here is my terminal output :
`C:\DEV\zephyr_iar\cmake-tutorial\examples\arm\hello-world>cmake -B_builds -GNinja --toolchain ..\..\iar-toolchain.cmake
-- The C compiler identification is IAR
CMake Error at C:/Program Files/CMake/share/cmake-3.27/Modules/CMakeFindBinUtils.cmake:146 (message):
Failed to find linker and librarian for IAR on .
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.27/Modules/CMakeDetermineCCompiler.cmake:196 (include)
CMakeLists.txt:5 (project)
-- Configuring incomplete, errors occurred!
C:\DEV\zephyr_iar\cmake-tutorial\examples\arm\hello-world>`
I printed CMAKE_SYSTEM_PROCESSOR and CMAKE_C_COMPILER value to check, and they are OK : CMAKE_SYSTEM_PROCESSOR = arm CMAKE_C_COMPILER = C:/Program Files/IAR Systems/Embedded Workbench 9.0/arm/bin/iccarm.exe
But after that, it seems the ARM part is missing. We can see that the difference between us is on the C compiler value seen by cmake. You : -- The C compiler identification is IAR ARM 9.40.1 Me : -- The C compiler identification is IAR
Don't know how to fix that...
Thanks for your reply. The only difference I can immediately spot is the position in which we set CMAKE_SYSTEM_NAME
to Generic
. This enables CMake for cross-compiling. Please try to move it to the top of your toolchain file and let me know if there was any difference.
Thank you for replying so quickly.
I moved the
set(CMAKE_SYSTEM_NAME Generic)
line to the top of the file, but I still have the same issue.
Sometimes when CMake fails on initial detection, it caches broken location information. Please try removing _builds
entirely and then re-run the CMake's configuration step with the updated toolchain file (CMAKE_SYSTEM_NAME
on top). Does it change anything?
Yes, I delete the _builds
entirely each time before launching the CMake's configuration step command.
May I ask which versions of CMake and IAR toolchain are currently in use at your end? I might try to reproduce this behavior from my end.
Thank you for your help.
I finally SOLVED my issue. It was quite stupid. Actually, I had a IAR Compiler for ARM License issue. I just got a new License and now it works.
(For info : I moved back the set(CMAKE_SYSTEM_NAME Generic)
line further in the file and it still works.)
I'm very sorry for the time loss.
This is wonderful news and I am glad you figured it out yourself. 😃 I will update the toolchain file template with an additional message hinting that this might be the case.
This issue is stale because it has been open for 30 days with no activity. If there is no further activity, the ticket will be automatically closed in 14 days.
This issue was closed because it has been inactive for 14 days since being marked as stale.
Hello, and thank you for this useful tutorial. I'm trying to follow the minimal exemple tutorial, but I got an error at the step "cmake -B_builds -G "Ninja Multi-Config" --toolchain /path/to/iar-toolchain.cmake". In my case, I use simply "Ninja" instead of Ninja Multi-Config. Almost everything seems to be OK, but I got this error :
CMake Error at C:/Program Files/CMake/share/cmake-3.27/Modules/CMakeFindBinUtils.cmake:146 (message): Failed to find linker and librarian for IAR on .
I got into CMakeFindBinUtils.cmake file to understand this error message case, and I saw that the CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ARCHITECTURE_ID variable is empty. I think it should be "arm". Have you some elements ?