4

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.

Valmir
  • 401
  • 1
  • 5
  • 14

2 Answers2

5

That's exactly the use case of a relatively new (version 3.6) global CMake variable named CMAKE_TRY_COMPILE_TARGET_TYPE. So just add the following to your toolchain file:

set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

Edit: If your custom linker also gives you trouble outside the compiler check, simply split your toolchain into 2 files (toolchain.cmake to be read before and makerules.cmake after the CMake's compiler detection):

toolchain.cmake

[...]
set (CMAKE_USER_MAKE_RULES_OVERRIDE "${CMAKE_CURRENT_LIST_FILE}/makerules.cmake")

makerules.cmake

set (CMAKE_C_LINK_EXECUTABLE "<CMAKE_LINKER> <CMAKE_EXE_LINKER_FLAGS> <OBJECTS> <LINK_LIBRARIES> -o <TARGET>")
set (CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_LINKER> <CMAKE_EXE_LINKER_FLAGS> <OBJECTS> <LINK_LIBRARIES> -o <TARGET>")

Refrences

Community
  • 1
  • 1
Florian
  • 39,996
  • 9
  • 133
  • 149
  • Thanks for your reply @Florian. This way the the check step works, but when I try to link my application the "--list .map" still here (ignoring the override of the CMAKE_CXX_LINK_EXECUTABLE variable) . – Valmir Jul 13 '16 at 20:08
  • 1
    @Valmir The toolchain is loaded before everything else (see [here](http://stackoverflow.com/questions/30503631)). If you want to change normal variables after the CMake compiler detection you need another script to be given via [`CMAKE_USER_MAKE_RULES_OVERRIDE`](https://cmake.org/cmake/help/latest/variable/CMAKE_USER_MAKE_RULES_OVERRIDE.html) (see [here](http://stackoverflow.com/questions/28732209)). You shouldn't normally need to move your `CMAKE_CXX_LINK_EXECUTABLE` settings from your toolchain to such a separate file. I consider those variables being none-cached a bug in the ARMCC support. – Florian Jul 13 '16 at 20:25
  • Thanks again @Florian. Unfortunately I will keep my change in ARMCC.cmake in order to keep my project working. – Valmir Jul 14 '16 at 13:21
0

Apparently this is a bug in the cmake's armcc support, so I will keep my change in the ARMCC.cmake file.

Valmir
  • 401
  • 1
  • 5
  • 14