IAR Toolchain ignores CMAKE_<LANG>_LINKER_LAUNCHER
I tried to use the new CMAKE_<LANG>_LINKER_LAUNCHER
feature in CMake version 3.21.0-rc2 in a CMake project using the Ninja generator and an IAR toolchain.
Expected result
The linker launcher is executed instead of the linker.
[4/4] cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -P C:/path/to/project/DevOps/Scripts/InvokeCompilerAndCompanion.cmake -- "C:/Program Files (x86)/IAR Systems/Embedded Workbench 8.4/arm/bin/icstat.exe" link_analyze --checks C:/path/to/project/DevOps/C-STAT_checks.txt --db C:/binary/path/cstat.db -- C:\PROGRA~2\IARSYS~1\EMBEDD~1.4\arm\bin\ilinkarm.exe --silent Source\Example\CMakeFiles\SampleClient.dir\main.cpp.o --basic_heap --semihosting Source\Library\libClient.a -o Source\Example\SampleClient.elf && cd ."
Actual result
The linker was executed without linker launcher.
[4/4] cmd.exe /C "cd . && "C:/Program Files (x86)/IAR Systems/Embedded Workbench 8.4/arm/bin/ilinkarm.exe" --silent Source\Example\CMakeFiles\SampleClient.dir\main.cpp.o --basic_heap --semihosting Source\Library\libClient.a -o Source\Example\SampleClient.elf && cd ."
First analysis
I did take a look of the implementation (by reading the pull request !6092 (merged)) and noticed !6164 (merged) while reading it. So, I dived into the Modules/Compiler/IAR*.cmake
files. I noticed in Modules/Compiler/IAR.cmake the following line (take a look at \"${CMAKE_IAR_LINKER}\"
):
set(CMAKE_${lang}_LINK_EXECUTABLE "\"${CMAKE_IAR_LINKER}\" -S <OBJECTS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES> -o <TARGET>")
Changing that line to
set(CMAKE_${lang}_LINK_EXECUTABLE "<CMAKE_LINKER> -S <OBJECTS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES> -o <TARGET>")
makes everything working as expected. Since I am not familiar with the code base, I cannot claim that this change has no side effect.
(If I am interpreting everything correctly, the current version is hardcoding the linker executable whereas the variant with <CMAKE_LINKER>
delays the substitution to the build rule generation.)
Background
Actually, I was trying to invoke IAR C-STAT Static Analysis for link analysis which requires the linker command line. Since there is no build-in support, I have tried to mimic the CMAKE_<LANG>_CLANG_TIDY
behavior with CMAKE_<LANG>_COMPILER_LAUNCHER
and CMAKE_<LANG>_LINKER_LAUNCHER
. I'm happy to share details of this implementation if anybody is interested.