cmake: Normalize GNULD_LINKER variable

Some toolchains may generate convoluted paths when reporting accessory
tools. This is the case with GCC in the Zephyr SDK toolchain. For
example, for a Zephyr SDK installed under `C:\Portable\Zephyr` a call to
`gcc --print-prog-name=ld.bfd` should normally return something like
`c:/portable/zephyr/zephyr-sdk-0.16.5/arm-zephyr-eabi/arm-zephyr-eabi/bin/ld.bfd.exe`
but because of how the toolchain was created the path reported gets all
messed up with relative fragments. In above case, the actual path reported
was `c:/portable/zephyr/zephyr-sdk-0.16.5/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe`
One might argue that this should be fixed in the toolchain which could be
possible for the Zephyr SDK but not for other toolchains (definitely not
for proprietary ones).

Signed-off-by: Nicolas Lebedenco <nicolas@lebedenco.net>
This commit is contained in:
Nicolas Lebedenco 2024-03-28 22:20:55 -04:00 committed by Carles Cufí
parent bec4faebb9
commit 6a42ede43b

View file

@ -48,6 +48,7 @@ execute_process(COMMAND ${CMAKE_C_COMPILER} --print-prog-name=ld.bfd
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(EXISTS "${GNULD_LINKER}")
cmake_path(NORMAL_PATH GNULD_LINKER)
set(GNULD_LINKER_IS_BFD ON CACHE BOOL "Linker BFD compatibility (compiler reported)" FORCE)
else()
# Need to clear it or else find_program() won't replace the value.