Skip to content
Permalink
Browse files

cmake: Toolchain abstraction: Abstraction of binary tools, foundation.

This forms the foundation for the abstraction of the binary tools,
where the following steps are taken:
- Move binary tool resolving, such as objcopy, objdump, readelf and
so forth, out of compiler definitions and place in a dedicated binary
tools folder with the binary tools supplier as subfolder, similar to
the compiler and linker directories.
- Create binary tool sets, gnu, host-gnu and llvm.
- Each toolchain selects the required set of binary tools by setting
BINTOOLS via its generic.cmake as it also does for compiler and linker.

The intent here is to abstract Zephyr's dependence on toolchains,
thus allowing for easier porting to other, perhaps commercial,
toolchains and/or usecases.

No functional change expected.

Signed-off-by: Danny Oerndrup <daor@demant.com>
  • Loading branch information...
daor-oti authored and aescolar committed Jul 18, 2019
1 parent b8af1a6 commit aed9ea79b5917cadd5df383c5b2bcd726268a958
@@ -0,0 +1,14 @@
# SPDX-License-Identifier: Apache-2.0

# Configures binary tools as GNU binutils

find_program(CMAKE_OBJCOPY ${CROSS_COMPILE}objcopy PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_OBJDUMP ${CROSS_COMPILE}objdump PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_AS ${CROSS_COMPILE}as PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_AR ${CROSS_COMPILE}ar PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_RANLIB ${CROSS_COMPILE}ranlib PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_READELF ${CROSS_COMPILE}readelf PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_NM ${CROSS_COMPILE}nm PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)

find_program(CMAKE_GDB ${CROSS_COMPILE}gdb PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_GDB gdb-multiarch PATH ${TOOLCHAIN_HOME} )
@@ -0,0 +1,11 @@
# SPDX-License-Identifier: Apache-2.0

# Configures binary tools as host GNU binutils

find_program(CMAKE_OBJCOPY objcopy)
find_program(CMAKE_OBJDUMP objdump)
find_program(CMAKE_AR ar )
find_program(CMAKE_RANLILB ranlib )
find_program(CMAKE_READELF readelf)

find_program(CMAKE_GDB gdb )
@@ -0,0 +1,15 @@
# SPDX-License-Identifier: Apache-2.0

# Configures binary toos as llvm binary tool set

if(DEFINED TOOLCHAIN_HOME)
set(find_program_clang_args PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
set(find_program_binutils_args PATH ${TOOLCHAIN_HOME})
endif()

find_program(CMAKE_AR llvm-ar ${find_program_clang_args} )
find_program(CMAKE_NM llvm-nm ${find_program_clang_args} )
find_program(CMAKE_OBJDUMP llvm-objdump ${find_program_clang_args} )
find_program(CMAKE_RANLIB llvm-ranlib ${find_program_clang_args} )
find_program(CMAKE_OBJCOPY objcopy ${find_program_binutils_args})
find_program(CMAKE_READELF readelf ${find_program_binutils_args})
@@ -13,20 +13,10 @@ endif()

if(DEFINED TOOLCHAIN_HOME)
set(find_program_clang_args PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
set(find_program_binutils_args PATH ${TOOLCHAIN_HOME})
endif()


find_program(CMAKE_C_COMPILER clang ${find_program_clang_args})
find_program(CMAKE_CXX_COMPILER clang++ ${find_program_clang_args})
find_program(CMAKE_AR llvm-ar ${find_program_clang_args})
find_program(CMAKE_LINKER llvm-link ${find_program_clang_args})
find_program(CMAKE_NM llvm-nm ${find_program_clang_args})
find_program(CMAKE_OBJDUMP llvm-objdump ${find_program_clang_args})
find_program(CMAKE_RANLIB llvm-ranlib ${find_program_clang_args})

find_program(CMAKE_OBJCOPY objcopy ${find_program_binutils_args})
find_program(CMAKE_READELF readelf ${find_program_binutils_args})
find_program(CMAKE_C_COMPILER clang ${find_program_clang_args})
find_program(CMAKE_CXX_COMPILER clang++ ${find_program_clang_args})

if(NOT "${ARCH}" STREQUAL "posix")

@@ -5,16 +5,7 @@ set_ifndef(C++ g++)
# Configures CMake for using GCC, this script is re-used by several
# GCC-based toolchains

find_program(CMAKE_C_COMPILER ${CROSS_COMPILE}${CC} PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_OBJCOPY ${CROSS_COMPILE}objcopy PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_OBJDUMP ${CROSS_COMPILE}objdump PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_AS ${CROSS_COMPILE}as PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_AR ${CROSS_COMPILE}ar PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_RANLIB ${CROSS_COMPILE}ranlib PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_READELF ${CROSS_COMPILE}readelf PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_GDB ${CROSS_COMPILE}gdb PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_GDB gdb-multiarch PATH ${TOOLCHAIN_HOME} )
find_program(CMAKE_NM ${CROSS_COMPILE}nm PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_C_COMPILER ${CROSS_COMPILE}${CC} PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)

if(CONFIG_CPLUSPLUS)
set(cplusplus_compiler ${CROSS_COMPILE}${C++})
@@ -2,14 +2,7 @@

# Configures CMake for using GCC

find_program(CMAKE_C_COMPILER gcc )
find_program(CMAKE_OBJCOPY objcopy)
find_program(CMAKE_OBJDUMP objdump)
#find_program(CMAKE_LINKER ld ) # Not in use yet
find_program(CMAKE_AR ar )
find_program(CMAKE_RANLILB ranlib )
find_program(CMAKE_READELF readelf)
find_program(CMAKE_GDB gdb )
find_program(CMAKE_C_COMPILER gcc)

# -march={pentium,lakemont,...} do not automagically imply -m32, so
# adding it here.
@@ -5,17 +5,7 @@ set_ifndef(C++ g++)
# Configures CMake for using GCC, this script is re-used by several
# GCC-based toolchains

find_program(CMAKE_C_COMPILER ${CROSS_COMPILE}${CC} PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_OBJCOPY ${CROSS_COMPILE}objcopy PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_OBJDUMP ${CROSS_COMPILE}objdump PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_AS ${CROSS_COMPILE}as PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_LINKER ${CROSS_COMPILE}ld PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_AR ${CROSS_COMPILE}ar PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_RANLIB ${CROSS_COMPILE}ranlib PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_READELF ${CROSS_COMPILE}readelf PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_GDB ${CROSS_COMPILE}gdb PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_GDB gdb-multiarch PATH ${TOOLCHAIN_HOME} )
find_program(CMAKE_NM ${CROSS_COMPILE}nm PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_C_COMPILER ${CROSS_COMPILE}${CC} PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)

if(CONFIG_CPLUSPLUS)
set(cplusplus_compiler ${CROSS_COMPILE}${C++})
@@ -67,3 +67,4 @@ include(${TOOLCHAIN_ROOT}/cmake/toolchain/${ZEPHYR_TOOLCHAIN_VARIANT}/generic.cm
# (gcc, host-gcc etc.)
include(${TOOLCHAIN_ROOT}/cmake/compiler/${COMPILER}/generic.cmake OPTIONAL)
include(${TOOLCHAIN_ROOT}/cmake/linker/${LINKER}/generic.cmake OPTIONAL)
include(${TOOLCHAIN_ROOT}/cmake/bintools/${BINTOOLS}/generic.cmake OPTIONAL)
@@ -48,6 +48,7 @@ unset(CMAKE_C_COMPILER CACHE)
# E.g. toolchain/llvm may pick {clang, ld} or {clang, lld}.
include(${TOOLCHAIN_ROOT}/cmake/compiler/${COMPILER}/target.cmake OPTIONAL)
include(${TOOLCHAIN_ROOT}/cmake/linker/${LINKER}/target.cmake OPTIONAL)
include(${TOOLCHAIN_ROOT}/cmake/bintools/${BINTOOLS}/target.cmake OPTIONAL)

# Uniquely identify the toolchain wrt. it's capabilities.
#
@@ -26,3 +26,4 @@ assert(CROSS_COMPILE "CROSS_COMPILE is not set")

set(COMPILER gcc)
set(LINKER ld)
set(BINTOOLS gnu)
@@ -8,6 +8,7 @@ set(TOOLCHAIN_HOME ${ESPRESSIF_TOOLCHAIN_PATH})

set(COMPILER gcc)
set(LINKER ld)
set(BINTOOLS gnu)

set(CROSS_COMPILE_TARGET xtensa-esp32-elf)
set(SYSROOT_TARGET xtensa-esp32-elf)
@@ -20,6 +20,7 @@ set(TOOLCHAIN_HOME ${GNUARMEMB_TOOLCHAIN_PATH})

set(COMPILER gcc)
set(LINKER ld)
set(BINTOOLS gnu)

set(CROSS_COMPILE_TARGET arm-none-eabi)
set(SYSROOT_TARGET arm-none-eabi)
@@ -2,4 +2,6 @@

set(COMPILER host-gcc)
set(LINKER ld)
set(BINTOOLS host-gnu)

set(TOOLCHAIN_HAS_NEWLIB OFF CACHE BOOL "True if toolchain supports newlib")
@@ -14,6 +14,7 @@ endif()

set(COMPILER clang)
set(LINKER ld) # TODO: Use lld eventually rather than GNU ld
set(BINTOOLS llvm)

if("${ARCH}" STREQUAL "arm")
set(triple arm-none-eabi)
@@ -12,6 +12,7 @@ set(TOOLCHAIN_HOME ${XTENSA_TOOLCHAIN_PATH}/XtDevTools/install/tools/$ENV{TOOLCH

set(COMPILER xcc)
set(LINKER ld)
set(BINTOOLS gnu)

set(CROSS_COMPILE_TARGET xt)
set(SYSROOT_TARGET xtensa-elf)
@@ -8,6 +8,7 @@ set(TOOLCHAIN_HOME ${XTOOLS_TOOLCHAIN_PATH})

set(COMPILER gcc)
set(LINKER ld)
set(BINTOOLS gnu)

# Choose one of the toolchains in 'TOOLCHAIN_HOME' at random to use as
# a 'generic' toolchain until we know for sure which toolchain we
@@ -4,6 +4,7 @@ set(TOOLCHAIN_HOME ${ZEPHYR_SDK_INSTALL_DIR})

set(COMPILER gcc)
set(LINKER ld)
set(BINTOOLS gnu)

set(CROSS_COMPILE_TARGET i586-${TOOLCHAIN_VENDOR}-elf)
set(SYSROOT_TARGET i586-${TOOLCHAIN_VENDOR}-elf)
@@ -4,6 +4,7 @@ set(TOOLCHAIN_HOME ${ZEPHYR_SDK_INSTALL_DIR})

set(COMPILER gcc)
set(LINKER ld)
set(BINTOOLS gnu)

set(CROSS_COMPILE_TARGET i586-${TOOLCHAIN_VENDOR}-elf)
set(SYSROOT_TARGET i586-${TOOLCHAIN_VENDOR}-elf)

0 comments on commit aed9ea7

Please sign in to comment.
You can’t perform that action at this time.