cmake: clang: Add the runtime library to the link command

When building with clang symbols from the runtime library, like
__divdi3 were not being resolved. To fix this we add the "library path
for the currently used compiler runtime library" to the link path.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
This commit is contained in:
Sebastian Bøe 2018-12-10 15:18:20 +01:00 committed by Kumar Gala
commit 3e4b9ded0b

View file

@ -33,5 +33,20 @@ foreach(isystem_include_dir ${NOSTDINC})
list(APPEND isystem_include_flags -isystem ${isystem_include_dir})
endforeach()
execute_process(
COMMAND ${CMAKE_C_COMPILER} ${TOOLCHAIN_C_FLAGS} --print-libgcc-file-name
OUTPUT_VARIABLE LIBGCC_FILE_NAME
OUTPUT_STRIP_TRAILING_WHITESPACE
)
assert_exists(LIBGCC_FILE_NAME)
get_filename_component(LIBGCC_DIR ${LIBGCC_FILE_NAME} DIRECTORY)
assert_exists(LIBGCC_DIR)
list(APPEND LIB_INCLUDE_DIR "-L\"${LIBGCC_DIR}\"")
list(APPEND TOOLCHAIN_LIBS gcc)
set(CMAKE_REQUIRED_FLAGS -nostartfiles -nostdlib ${isystem_include_flags} -Wl,--unresolved-symbols=ignore-in-object-files)
string(REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")