Chaging order of options in the link command of a cross-compilation project via CMAKE_CXX_LINK_EXECUTABLE

I have a CMake toolchain file to cross-compile to a TI C2000 (C28x) MCU. The compilation seems to go well except during the link process I receive a couple of warnings, the relevant warning says

warning: Option -o is an alias of linker option --output_file. The specified
   argument of off is also a valid argument for the compiler option --opt_level
   (-o). If the intent is to specify the optimization level, the option should
   be specified before the --run_linker(-z) option. As specified, the output
   file of the linker will be off

Specifically the part

If the intent is to specify the optimization level, the option should be specified before the --run_linker(-z) option. As specified, the output file of the linker will be off"

My understanding is that if I want to change where the linker flags are placed in the command I have to modify CMAKE_CXX_LINKER_EXECUTABLE/CMAKE_C_LINKER_EXECUTABLE, however setting this variable seems to have no effect. I’ve tried setting it on the command line, in the toolchain file and in the CMakeLists.txt.

The source code here specifies this variable as:

set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> --run_linker --output_file=<TARGET> --map_file=<TARGET>.map <CMAKE_CXX_LINK_FLAGS> <LINK_LIBRARIES> <LINK_FLAGS> <OBJECTS>")

and I’d like to place CMAKE_CXX_LINK_FLAGS and LINK_FLAGS before the --run-linker command as suggested in the warning.

Any idea how I can override this?

I found this conversation: CMAKE_C_LINK_EXECUTABLE not considered for MINGW32

Looks like their suggestion there is to make a custom platform ID where I can populate the CMAKE_C_LINK_EXECUTABLE/CMAKE_CXX_LINK_EXECUTABLE which ever way I want. This makes me wonder if this is a deficiency in the implementation of Modules/Compiler/TI-CXX.cmake. Should it be checking if it’s defined before it set()'s the variable? e.g.

if(NOT DEFINED CMAKE_C_LINK_EXECUTABLE)
    set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> --run_linker --output_file=<TARGET> --map_file=<TARGET>.map <CMAKE_CXX_LINK_FLAGS> <LINK_LIBRARIES> <LINK_FLAGS> <OBJECTS>")
endif()

Solved! See here: Modifying CMAKE_<LANG>_LINK_EXECUTABLE in toolchain file