Built in Support:
CMake does not support IAR for anything other than the architectures listed in IAR-C.cmake
, if you want to use CMake for something else you would need to submit an issue to the CMake gitlab page. I'm not sure if any of the mainline CMake developers would want to take the time to add C51 support, so it might not get done unless you want to do it yourself.
Judging by your error message you are probably using an "older" version of cmake. The last version that I worked on was 3.14 and at that time it only supported AVR and ARM with IAR. It looks like the latest IAR-C.cmake
supports several other architectures. The error message (if you look at the bottom of the file you linked to) should be
CMAKE_C_COMPILER_ARCHITECTURE_ID not detected. This should be automatic.
The newer IAR module code is in CMake 3.15.0 so you should get the latest release from the CMake website.
Adding Support:
I made some changes to the IAR-CXX.cmake
module to support AVR better, but it is still experimental in my opinion. The problem lies in the fact that the binaries produces by IAR-AVR are in a difficult to parse proprietary format, the compiler doesn't support a specific C++ standard (it uses embedded c++), and the command line options don't map easily to the cmake defaults.
I don't have the IAR 8051 compiler but I will list what I think are the major changes to make. because this is all within *.cmake
files in the module folder you will not need to recompile cmake it will just change your existing install. Of course if you get it working you should submit a pull request and get them into mainline cmake!
you will need: the IAR 8051 compiler guide, and to edit to following files in your CMake installation, relative to C:\Program Files\CMake\share
:
- cmake-3.15.0\Modules\Compiler\IAR-DetermineCompiler.cmake
- cmake-3.15.0\Modules\CMakePlatformId.h.in
- cmake-3.15.0\Modules\Compiler\IAR-C.cmake
cmake-3.15.0\Modules\Compiler\IAR-DetermineCompiler.cmake
this file defines some macro templates that are compiled in a simple C file. CMake then dumps the strings from the produced object file to read these macros and discover the compiler information.
page 391 of the compiler manual you can see IAR 8051 compiler defines __IAR_SYSTEMS_ICC__
, __VER__
, and __ICC8051__
. great! the first two are already handled, you just need to add || defined(__ICC8051__)
to the end of the #elif
chain on line 34.
cmake-3.15.0\Modules\CMakePlatformId.h.in
this file is a template that is part of the file that gets compiled for the configuration test. starting around line 155 you can see all the IAR compiler macros being defined. Just before # else /* unknown architecture */
on line 173 you should add
# elif defined(__ICC8051__)
# define ARCHITECTURE_ID "8051"
cmake-3.15.0\Modules\Compiler\IAR-C.cmake
the C51 compiler will need another elseif
in IAR-C.cmake, for example:
# CMAKE_C_COMPILER_ARCHITECTURE_ID should be 8051 because of our edit in the template file
elseif("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "8051")
# pretty sure 8051 IAR uses xlink? (compiler guide page 42)
__compiler_iar_xlink(C)
# after `C` the format is compiler version followed by default C standard
# the compiler manual i found says the default version is C99, but I have no idea
# what the compiler version is. 10.2 is the latest...
__compiler_check_default_language_standard(C 10.2 99)
# set to output extension you need, or remove if you want an .elf
set(CMAKE_C_OUTPUT_EXTENSION ".r90")
Try Configuring Again
At this point you can try cleaning your cache and re-configuring the project. Cmake will use the modules we just changed, and if you are lucky it will work. I wrote all this without access to the compiler so hopefully you will edit my answer with any additional steps you needed to take.
Additional Suggestions
Add the line set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
to your toolchain file. This prevents the cmake test compiler from trying to link. Often embedded linkers need special scripts, flags, etc to work. This causes the configure step to fail with the message The C compiler ... is not able to compile a simple test program.
Also if you need some flags set in the toolchain to make the compiler work at a basic level refer to this answer.