From 6a42ede43b53ceffddeaa814b4bd99284c25240d Mon Sep 17 00:00:00 2001 From: Nicolas Lebedenco Date: Thu, 28 Mar 2024 22:20:55 -0400 Subject: [PATCH] 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 --- cmake/modules/FindGnuLd.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/modules/FindGnuLd.cmake b/cmake/modules/FindGnuLd.cmake index 3e137438aa1..9ee42cc82fe 100644 --- a/cmake/modules/FindGnuLd.cmake +++ b/cmake/modules/FindGnuLd.cmake @@ -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.