I'm trying to use cmake
in a project which is compiled using armcc
, but use a custom proprietary linker (not armlink
).
I've changed the variables in the toolchain.cmake
file as following:
unset (CMAKE_LINKER CACHE)
set (CMAKE_LINKER "my_linker" CACHE STRING "" FORCE)
unset (CMAKE_ARMCC_LINKER CACHE)
set (CMAKE_ARMCC_LINKER "my_linker" CACHE STRING "" FORCE)
unset (CMAKE_EXE_LINKER_FLAGS CACHE )
set (CMAKE_EXE_LINKER_FLAGS "-flag1 -flag2" CACHE STRING "" FORCE)
unset (CMAKE_C_LINK_EXECUTABLE)
set (CMAKE_C_LINK_EXECUTABLE "<CMAKE_LINKER> <CMAKE_EXE_LINKER_FLAGS> <OBJECTS> <LINK_LIBRARIES> -o <TARGET>")
unset (CMAKE_CXX_LINK_EXECUTABLE)
set (CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_LINKER> <CMAKE_EXE_LINKER_FLAGS> <OBJECTS> <LINK_LIBRARIES> -o <TARGET>")
But when cmake
tries to check my compiler suite, it fails in the linking step:
-- Check for working C compiler: armcc.exe -- broken
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.6/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler "armcc.exe" is not able to compile a simple test program.
... (compiling commands that worked hidden here)
Linking C executable cmTC_c08ef.elf
"C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_link_script CMakeFiles\cmTC_c08ef.dir\link.txt --verbose=1
my_linker -flag1 -flag2 CMakeFiles/cmTC_c08ef.dir/testCCompiler.o -o cmTC_c08ef.elf --list cmTC_c08ef.map
The problem is the --list cmTC_c08ef.map
at the end of command line (which does not exist in the toolchain.cmake
file).
In order to make it work, I need to change the file <cmake_install_dir>\Modules\Compiler\ARMCC.cmake
as following:
set(CMAKE_${lang}_LINK_EXECUTABLE "<CMAKE_LINKER> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES> <OBJECTS> -o <TARGET> --list <TARGET_BASE>.map")
# set(CMAKE_${lang}_LINK_EXECUTABLE "<CMAKE_LINKER> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES> <OBJECTS> -o <TARGET>")
There is a better approach to solve this issue or it is the only way?
Edit: Apparently this is a bug in the cmake's armcc support, so I will keep my change in the ARMCC.cmake file.