2019-04-06 21:08:09 +08:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2022-08-30 17:11:36 +08:00
|
|
|
# FindTargetTools module for locating a set of tools to use on the host but
|
|
|
|
# targeting a remote target for Zephyr development.
|
|
|
|
#
|
|
|
|
# This module will lookup following target tools for Zephyr development:
|
|
|
|
# +---------------------------------------------------------------+
|
|
|
|
# | Tool | Required | Notes: |
|
|
|
|
# +---------------------------------------------------------------+
|
|
|
|
# | Target C-compiler | Yes | |
|
|
|
|
# | Target Assembler | Yes | |
|
|
|
|
# | Target linker | Yes | |
|
|
|
|
# +---------------------------------------------------------------+
|
|
|
|
#
|
|
|
|
# The module defines the following variables:
|
|
|
|
#
|
|
|
|
# 'CMAKE_C_COMPILER'
|
|
|
|
# Path to target C compiler.
|
|
|
|
# Set to 'CMAKE_C_COMPILER-NOTFOUND' if no C compiler was found.
|
|
|
|
#
|
|
|
|
# 'TargetTools_FOUND', 'TARGETTOOLS_FOUND'
|
|
|
|
# True if all required host tools were found.
|
|
|
|
|
|
|
|
find_package(HostTools)
|
|
|
|
|
|
|
|
if(TargetTools_FOUND)
|
|
|
|
return()
|
|
|
|
endif()
|
2021-12-17 00:13:54 +08:00
|
|
|
|
2021-12-16 17:05:20 +08:00
|
|
|
# Prevent CMake from testing the toolchain
|
|
|
|
set(CMAKE_C_COMPILER_FORCED 1)
|
|
|
|
set(CMAKE_CXX_COMPILER_FORCED 1)
|
|
|
|
|
2024-03-18 23:01:51 +08:00
|
|
|
# https://cmake.org/cmake/help/latest/variable/CMAKE_SYSTEM_NAME.html:
|
|
|
|
# The name of the operating system for which CMake is to build.
|
2018-12-19 23:01:05 +08:00
|
|
|
#
|
|
|
|
# https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/CrossCompiling:
|
|
|
|
# CMAKE_SYSTEM_NAME : this one is mandatory, it is the name of the target
|
|
|
|
# system, i.e. the same as CMAKE_SYSTEM_NAME would have if CMake would run
|
|
|
|
# on the target system. Typical examples are "Linux" and "Windows". This
|
|
|
|
# variable is used for constructing the file names of the platform files
|
|
|
|
# like Linux.cmake or Windows-gcc.cmake. If your target is an embedded
|
|
|
|
# system without OS set CMAKE_SYSTEM_NAME to "Generic".
|
2024-04-25 20:47:10 +08:00
|
|
|
set(CMAKE_SYSTEM_NAME Generic)
|
2018-12-19 23:01:05 +08:00
|
|
|
|
|
|
|
# https://cmake.org/cmake/help/latest/variable/CMAKE_SYSTEM_PROCESSOR.html:
|
|
|
|
# The name of the CPU CMake is building for.
|
|
|
|
#
|
|
|
|
# https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/CrossCompiling:
|
|
|
|
# CMAKE_SYSTEM_PROCESSOR : optional, processor (or hardware) of the
|
|
|
|
# target system. This variable is not used very much except for one
|
|
|
|
# purpose, it is used to load a
|
|
|
|
# CMAKE_SYSTEM_NAME-compiler-CMAKE_SYSTEM_PROCESSOR.cmake file,
|
|
|
|
# which can be used to modify settings like compiler flags etc. for
|
|
|
|
# the target
|
2018-12-13 23:32:07 +08:00
|
|
|
set(CMAKE_SYSTEM_PROCESSOR ${ARCH})
|
|
|
|
|
2018-12-19 23:01:05 +08:00
|
|
|
# https://cmake.org/cmake/help/latest/variable/CMAKE_SYSTEM_VERSION.html:
|
|
|
|
# When the CMAKE_SYSTEM_NAME variable is set explicitly to enable cross
|
|
|
|
# compiling then the value of CMAKE_SYSTEM_VERSION must also be set
|
|
|
|
# explicitly to specify the target system version.
|
|
|
|
set(CMAKE_SYSTEM_VERSION ${PROJECT_VERSION})
|
|
|
|
|
2022-09-26 20:09:39 +08:00
|
|
|
# https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_BYTE_ORDER.html
|
|
|
|
# Byte order of <LANG> compiler target architecture, if known.
|
|
|
|
#
|
|
|
|
# Zephyr Kconfig defines BIG_ENDIAN according to arch, SoC, Board, so propagate
|
|
|
|
# this setting to allow users to read the standard CMake variable or use
|
|
|
|
# 'test_big_endian()' function.
|
|
|
|
if(CONFIG_BIG_ENDIAN)
|
|
|
|
set(CMAKE_C_BYTE_ORDER BIG_ENDIAN)
|
|
|
|
set(CMAKE_CXX_BYTE_ORDER BIG_ENDIAN)
|
|
|
|
else()
|
|
|
|
set(CMAKE_C_BYTE_ORDER LITTLE_ENDIAN)
|
|
|
|
set(CMAKE_CXX_BYTE_ORDER LITTLE_ENDIAN)
|
|
|
|
endif()
|
|
|
|
|
2024-03-18 23:01:51 +08:00
|
|
|
# Do not build dynamically loadable libraries by default
|
2018-12-13 23:32:07 +08:00
|
|
|
set(BUILD_SHARED_LIBS OFF)
|
|
|
|
|
2021-05-22 03:34:58 +08:00
|
|
|
# Custom targets for compiler and linker flags.
|
|
|
|
add_custom_target(asm)
|
|
|
|
add_custom_target(compiler)
|
|
|
|
add_custom_target(compiler-cpp)
|
|
|
|
add_custom_target(linker)
|
|
|
|
|
2018-12-13 23:32:07 +08:00
|
|
|
if(NOT (COMPILER STREQUAL "host-gcc"))
|
|
|
|
include(${TOOLCHAIN_ROOT}/cmake/toolchain/${ZEPHYR_TOOLCHAIN_VARIANT}/target.cmake)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# The 'generic' compiler and the 'target' compiler might be different,
|
|
|
|
# so we unset the 'generic' one and thereby force the 'target' to
|
|
|
|
# re-set it.
|
|
|
|
unset(CMAKE_C_COMPILER)
|
|
|
|
unset(CMAKE_C_COMPILER CACHE)
|
|
|
|
|
2019-04-25 21:46:11 +08:00
|
|
|
# A toolchain consist of a compiler and a linker.
|
|
|
|
# In Zephyr, toolchains require a port under cmake/toolchain/.
|
|
|
|
# Each toolchain port must set COMPILER and LINKER.
|
|
|
|
# E.g. toolchain/llvm may pick {clang, ld} or {clang, lld}.
|
2020-08-18 20:47:53 +08:00
|
|
|
add_custom_target(bintools)
|
|
|
|
|
2019-07-03 16:09:09 +08:00
|
|
|
include(${TOOLCHAIN_ROOT}/cmake/compiler/${COMPILER}/target.cmake OPTIONAL)
|
|
|
|
include(${TOOLCHAIN_ROOT}/cmake/linker/${LINKER}/target.cmake OPTIONAL)
|
2021-12-17 00:13:54 +08:00
|
|
|
include(${ZEPHYR_BASE}/cmake/bintools/bintools_template.cmake)
|
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>
2019-07-18 21:06:51 +08:00
|
|
|
include(${TOOLCHAIN_ROOT}/cmake/bintools/${BINTOOLS}/target.cmake OPTIONAL)
|
2022-08-30 17:11:36 +08:00
|
|
|
|
cmake: improve Zephyr link phase
Zephyr is a bare metal build where standard libs are disabled.
This means that c and runtime libraries must manually be linked in.
This has generally been handled by using CMake's link libraries handling
but the issue with that is both de-duplication but also library link
order.
Standard libraries must be linked at last location to ensure symbols
are always available, however this is not optimal with
target_link_libraries() because this would ultimately require every
library to know the c library to link with, which is not desired.
Therefore, setup standard C and runtime library linking in linker
CMake files for toolchains where this is required.
This commit expands the principle introduced with toolchain abstraction,
see PR#24851.
This means that a toolchain implementation may specify standard C,
runtime, C++, etc libraries, as well as their link order.
Because a property approach is used, then Zephyr modules, such as the
Picolibc module can adjust such properties.
An optional `zephyr_linker_finalize()` macro is called at the end of
Zephyr's CMakeList process and can be used by the toolchain
implementation to define the final linker invocation.
This aligns the linker handling flow to the principle introduced in
PR#24851 and improves the flexibility and robustness of Zephyr build
system.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-08-06 16:13:31 +08:00
|
|
|
include(${TOOLCHAIN_ROOT}/cmake/linker/target_template.cmake)
|
|
|
|
|
2022-08-30 17:11:36 +08:00
|
|
|
set(TargetTools_FOUND TRUE)
|
|
|
|
set(TARGETTOOLS_FOUND TRUE)
|