-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRTEMSToolchain.cmake
83 lines (65 loc) · 3.01 KB
/
RTEMSToolchain.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
###############################################################################
# CMake RTEMS support toolchain file.
#
# This file is the intended way in CMake to set up CMake for cross-compilation.
# Following environmental variables need to be set by user or by upper
# CMakeLists.txt:
#
# 1. RTEMS_TOOLS: Location of the RTEMS tools
# 2. RTEMS_ARCH_VERSION_NAME: Identifier with the format <ARCH>-rtems<VERSION>
#
# The toolchain file will determine and try to find the compilers based
# on these environmental variables.
# Environmental variables can be set in a CMakeLists.txt with the following
# command (do this before calling project()!)
#
# set(ENV{RTEMS_TOOLS} "<PATH_TO_TOOLS>")
#
###############################################################################
# Finding compilers by using environment variables.
###############################################################################
set(CMAKE_CROSSCOMPILING TRUE)
set(CMAKE_SYSTEM_NAME Generic)
if(NOT DEFINED ENV{RTEMS_ARCH_VERSION_NAME})
message(FATAL_ERROR "RTEMS_ARCH_VERSION_NAME variable not set!")
endif()
if(NOT DEFINED ENV{RTEMS_TOOLS})
message(FATAL_ERROR "RTEMS_TOOLS variable not set!")
endif()
if(NOT DEFINED ENV{CMAKE_ONLY_PRINT_ONCE_HACK})
message(STATUS "Checking for RTEMS binaries folder..")
endif()
set(RTEMS_BIN_PATH "$ENV{RTEMS_TOOLS}/bin")
if(NOT IS_DIRECTORY "${RTEMS_BIN_PATH}")
message(FATAL_ERROR "RTEMS binaries folder not found at ${RTEMS_BIN_PATH}")
endif()
list(APPEND CMAKE_PREFIX_PATH "${RTEMS_TOOLS}")
set(CROSS_COMPILE_CC "${RTEMS_BIN_PATH}/$ENV{RTEMS_ARCH_VERSION_NAME}-gcc")
set(CROSS_COMPILE_CXX "${RTEMS_BIN_PATH}/$ENV{RTEMS_ARCH_VERSION_NAME}-g++")
set(CROSS_COMPILE_SIZE "${RTEMS_BIN_PATH}/$ENV{RTEMS_ARCH_VERSION_NAME}-size")
# Check that compilers are available.
find_program(RTEMS_GCC "${CROSS_COMPILE_CC}" REQUIRED)
find_program(RTEMS_GXX "${CROSS_COMPILE_CXX}" REQUIRED)
# Size utility optional.
find_program (CMAKE_SIZE ${CROSS_COMPILE_SIZE})
if($ENV{RTEMS_ARCH_NAME} STREQUAL "arm")
set(CMAKE_SYSTEM_PROCESSOR arm)
elseif ($ENV{RTEMS_ARCH_NAME} STREQUAL "sparc")
set(CMAKE_SYSTEM_PROCESSOR sparc)
endif()
###############################################################################
# Setting compiler and flags
###############################################################################
set(CMAKE_C_COMPILER ${RTEMS_GCC})
set(CMAKE_CXX_COMPILER ${RTEMS_GXX})
string (REPLACE ";" " " RTEMS_BSP_CONFIG_CFLAGS "${RTEMS_BSP_CONFIG_CFLAGS}")
string (REPLACE ";" " " RTEMS_BSP_CONFIG_LDFLAGS "${RTEMS_BSP_CONFIG_LDFLAGS}")
set(CMAKE_C_FLAGS ${RTEMS_BSP_CONFIG_CFLAGS})
set(CMAKE_CXX_FLAGS ${CMAKE_C_FLAGS})
# This does not work and I don't know why. Need to set this after project
# definition or the linker test will fail.
set(CMAKE_EXE_LINKER_FLAGS_INIT ${RTEMS_BSP_CONFIG_LDFLAGS})
# https://cmake.org/cmake/help/latest/variable/CMAKE_TRY_COMPILE_TARGET_TYPE.html
# This prevents the issue of the linker not able to link a test program.
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
set(ENV{CMAKE_ONLY_PRINT_ONCE_HACK} TRUE)