Skip to content

Commit

Permalink
cmake: llvm : add llvm support on windows
Browse files Browse the repository at this point in the history
The linker can't be found when zephyr_compiler_check_flag()
is called to check the flags of clang compiler.
So the "-fuse-ld=lld" option is added to force to use lld,
which is the built-in linker of llvm.
triple i686-pc-none-elf couldn't be recognized and
used to find a valid linker on windows, we need to use
i686-pc-linux-elf.

Signed-off-by: Chen Peng1 <[email protected]>
  • Loading branch information
Chen Peng1 committed Jul 9, 2021
1 parent 395b0c3 commit 3f53fa0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion cmake/compiler/clang/target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ if(NOT "${ARCH}" STREQUAL "posix")
list(APPEND TOOLCHAIN_LIBS gcc)
endif()

set(CMAKE_REQUIRED_FLAGS -nostartfiles -nostdlib ${isystem_include_flags})
# CMake needs a valid linker to check compiler flag, but clang
# won't use LLVM built-in linker by default, so use this option
# to force clang to use LLVM built-in linker
set(CMAKE_REQUIRED_FLAGS -nostartfiles -nostdlib -fuse-ld=lld ${isystem_include_flags})
string(REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")

endif()
Expand Down
6 changes: 4 additions & 2 deletions cmake/toolchain/llvm/generic.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ if("${ARCH}" STREQUAL "arm")
set(CMAKE_EXE_LINKER_FLAGS_INIT "--specs=nosys.specs")
elseif("${ARCH}" STREQUAL "x86")
if(CONFIG_64BIT)
set(triple x86_64-pc-none-elf)
# The LLVM built-in linker lld is a generic driver, needs to use triple os filed
# to distinguish which linker will be used.
set(triple x86_64-pc-linux-elf)
else()
set(triple i686-pc-none-elf)
set(triple i686-pc-linux-elf)
endif()
endif()

Expand Down

0 comments on commit 3f53fa0

Please sign in to comment.