Skip to content

Commit 87a9726

Browse files
committed
added cmake files
1 parent 4721e2d commit 87a9726

File tree

3 files changed

+188
-0
lines changed

3 files changed

+188
-0
lines changed

RTEMSConfig.cmake

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
########################################
2+
# General RTEMS configuration
3+
########################################
4+
5+
# This function performs the generic RTEMS configuration. It expects
6+
# following arguments:
7+
# 1. Target/executable name
8+
# 2. RTEMS installation prefix, path where the RTEMS toolchain is installed
9+
# 3. RTEMS BSP, which consists generally has the format <Architecture>/<BSP>
10+
11+
function(rtems_general_config TARGET_NAME RTEMS_INST RTEMS_BSP)
12+
13+
include(RTEMSGeneric.cmake)
14+
rtems_generic_config(${TARGET_NAME} ${RTEMS_INST} ${RTEMS_BSP})
15+
16+
# Not an ideal solution but it will do for now because the number of
17+
# variables which need to be propagated to the upper most CMakeLists.txt
18+
# should not become too high.
19+
if(NOT ${CMAKE_SYSTEM_PROCESSOR} STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR})
20+
set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR} PARENT_SCOPE)
21+
endif()
22+
set(CMAKE_C_COMPILER ${CMAKE_C_COMPILER} PARENT_SCOPE)
23+
set(CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER} PARENT_SCOPE)
24+
set(CMAKE_ASM_COMPILER ${CMAKE_ASM_COMPILER} PARENT_SCOPE)
25+
set(CMAKE_LINKER ${CMAKE_LINKER} PARENT_SCOPE)
26+
27+
include(RTEMSHardware.cmake)
28+
rtems_hw_config(${TARGET_NAME} ${RTEMS_INST} ${RTEMS_BSP})
29+
30+
# No propagation necessary here because we can use target specific settings.
31+
32+
endfunction()

RTEMSGeneric.cmake

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
################################################################################
2+
# Generic RTEMS configuration
3+
################################################################################
4+
5+
# This function performs the generic RTEMS configuration. It expects
6+
# following arguments:
7+
# 1. Target/executable name
8+
# 2. RTEMS installation prefix, path where the RTEMS toolchain is installed
9+
# 3. RTEMS BSP, which consists generally has the format <Architecture>/<BSP>
10+
function(rtems_generic_config TARGET_NAME RTEMS_INST RTEMS_BSP)
11+
12+
set(RTEMS_VERSION "" CACHE STRING "RTEMS version")
13+
14+
message(STATUS "Setting up and checking RTEMS cross compile configuration..")
15+
if (RTEMS_INST STREQUAL "")
16+
message(FATAL_ERROR "RTEMS toolchain path has to be specified!")
17+
endif()
18+
19+
if(RTEMS_VERSION STREQUAL "")
20+
message(STATUS "No RTEMS_VERSION supplied.")
21+
message(STATUS "Autodetermining version from prefix ${RTEMS_INST} ..")
22+
string(REGEX MATCH [0-9]+$ RTEMS_VERSION "${RTEMS_INST}")
23+
message(STATUS "Version ${RTEMS_VERSION} found")
24+
endif()
25+
26+
string(REPLACE "/" ";" RTEMS_BSP_LIST_SEPARATED ${RTEMS_BSP})
27+
list(LENGTH RTEMS_BSP_LIST_SEPARATED BSP_LIST_SIZE)
28+
29+
if(NOT ${BSP_LIST_SIZE} EQUAL 2)
30+
message(FATAL_ERROR "Supplied RTEMS_BSP variable invalid. Make sure to provide a slash separated string")
31+
endif()
32+
33+
list(GET RTEMS_BSP_LIST_SEPARATED 0 RTEMS_ARCH_NAME)
34+
list(GET RTEMS_BSP_LIST_SEPARATED 1 RTEMS_BSP_NAME)
35+
36+
set(RTEMS_ARCH_TOOLS "${RTEMS_ARCH_NAME}-rtems${RTEMS_VERSION}")
37+
38+
if(IS_DIRECTORY "${RTEMS_INST}/${RTEMS_ARCH_TOOLS}")
39+
set(RTEMS_BSP_LIB_PATH "${RTEMS_INST}/${RTEMS_ARCH_TOOLS}/${RTEMS_BSP_NAME}/lib")
40+
if(NOT IS_DIRECTORY "${RTEMS_BSP_LIB_PATH}")
41+
message(FATAL_ERROR "RTEMS BSP lib folder not found at ${RTEMS_BSP_LIB_PATH}")
42+
endif()
43+
set(RTEMS_BSP_INC_PATH "${RTEMS_BSP_LIB_PATH}/include")
44+
if(NOT IS_DIRECTORY "${RTEMS_BSP_INC_PATH}")
45+
message(FATAL_ERROR "RTEMS BSP include folder not found at ${RTEMS_BSP_INC_PATH}")
46+
endif()
47+
else()
48+
message(FATAL_ERROR "RTEMS Architecure folder not found at ${RTEMS_INST}/${RTEMS_ARCH_TOOLS}")
49+
endif()
50+
51+
################################################################################
52+
# Checking the toolchain
53+
################################################################################
54+
55+
message(STATUS "Checking for RTEMS binaries folder..")
56+
set(RTEMS_BIN_PATH "${RTEMS_INST}/bin")
57+
if(NOT IS_DIRECTORY "${RTEMS_BIN_PATH}")
58+
message(FATAL_ERROR "RTEMS binaries folder not found at ${RTEMS_INST}/bin")
59+
endif()
60+
61+
message(STATUS "Checking for RTEMS gcc..")
62+
set(RTEMS_GCC "${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-gcc")
63+
if(NOT EXISTS "${RTEMS_GCC}")
64+
message(FATAL_ERROR "RTEMS gcc compiler not found at ${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-gcc")
65+
endif()
66+
67+
message(STATUS "Checking for RTEMS g++..")
68+
set(RTEMS_GXX "${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-g++")
69+
if(NOT EXISTS "${RTEMS_GXX}")
70+
message(FATAL_ERROR "RTEMS g++ compiler not found at ${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-g++")
71+
endif()
72+
73+
message(STATUS "Checking for RTEMS assembler..")
74+
set(RTEMS_ASM "${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-as")
75+
if(NOT EXISTS "${RTEMS_GXX}")
76+
message(FATAL_ERROR "RTEMS as compiler not found at ${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-as")
77+
endif()
78+
79+
message(STATUS "Checking for RTEMS linker..")
80+
set(RTEMS_LINKER "${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-ld")
81+
if(NOT EXISTS "${RTEMS_LINKER}")
82+
message(FATAL_ERROR "RTEMS ld linker not found at ${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-ld")
83+
endif()
84+
85+
message(STATUS "Checking done")
86+
87+
############################################
88+
# Info output
89+
###########################################
90+
91+
message(STATUS "RTEMS Version: ${RTEMS_VERSION}")
92+
message(STATUS "RTEMS installation path: ${RTEMS_INST}")
93+
message(STATUS "RTEMS Architecture tools path: ${RTEMS_ARCH_TOOLS}")
94+
message(STATUS "RTEMS BSP: ${RTEMS_BSP}")
95+
message(STATUS "RTEMS BSP LIB path: ${RTEMS_BSP_LIB_PATH}")
96+
message(STATUS "RTEMS BSP INC path: ${RTEMS_BSP_INC_PATH}")
97+
98+
message(STATUS "RTEMS gcc compiler: ${RTEMS_GCC}")
99+
message(STATUS "RTEMS g++ compiler: ${RTEMS_GXX}")
100+
message(STATUS "RTEMS assembler: ${RTEMS_ASM}")
101+
message(STATUS "RTEMS linker: ${RTEMS_LINKER}")
102+
103+
if(${RTEMS_ARCH_NAME} STREQUAL "arm")
104+
set(CMAKE_SYSTEM_PROCESSOR arm PARENT_SCOPE)
105+
endif()
106+
107+
target_link_directories(${TARGET_NAME} PUBLIC
108+
${RTEMS_BSP_LIB_PATH})
109+
target_include_directories(${TARGET_NAME} PUBLIC
110+
${RTEMS_BSP_INC_PATH})
111+
112+
###############################################################################
113+
# Setting variables in upper scope (only the upper scope!)
114+
###############################################################################
115+
116+
set(CMAKE_C_COMPILER ${RTEMS_GCC} PARENT_SCOPE)
117+
set(CMAKE_CXX_COMPILER ${RTEMS_GXX} PARENT_SCOPE)
118+
set(CMAKE_ASM_COMPILER ${RTEMS_ASM} PARENT_SCOPE)
119+
set(CMAKE_LINKER ${RTEMS_LINKER} PARENT_SCOPE)
120+
121+
endfunction()

RTEMSHardware.cmake

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
########################################
2+
# Hardware dependent configuration
3+
########################################
4+
5+
# This function performs the hardware dependant RTEMS configuration. It expects
6+
# following arguments:
7+
# 1. Target/executable name
8+
# 2. RTEMS installation prefix, path where the RTEMS toolchain is installed
9+
# 3. RTEMS BSP, which consists generally has the format <Architecture>/<BSP>
10+
function(rtems_hw_config TARGET_NAME RTEMS_INST RTEMS_BSP)
11+
12+
if(RTEMS_BSP STREQUAL "arm/stm32h7")
13+
target_compile_options(${TARGET_NAME} PUBLIC
14+
-mthumb
15+
-mcpu=cortex-m7
16+
-mfpu=fpv5-d16
17+
-mfloat-abi=hard
18+
)
19+
20+
target_link_options(${TARGET_NAME} BEFORE PUBLIC
21+
-mthumb
22+
-mcpu=cortex-m7
23+
-mfpu=fpv5-d16
24+
-mfloat-abi=hard
25+
)
26+
27+
target_link_options(${TARGET_NAME} PUBLIC
28+
-Wl,--gc-sections
29+
-Wl,-Bstatic
30+
-Wl,-Bdynamic
31+
-qrtems
32+
)
33+
34+
endif()
35+
endfunction()

0 commit comments

Comments
 (0)