Skip to content

Commit b96bcc1

Browse files
authored
Merge pull request #1 from rmspacefish/develop
Interface aligned to RTEMS now, several bugfixes
2 parents ae09e36 + 484fe3a commit b96bcc1

File tree

4 files changed

+438
-112
lines changed

4 files changed

+438
-112
lines changed

RTEMSConfig.cmake

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,59 @@
1-
########################################
2-
# General RTEMS configuration
3-
########################################
1+
################################################################################
2+
# RTEMS configuration
3+
################################################################################
44

5-
# This function performs the generic RTEMS configuration. It expects
6-
# following arguments:
5+
# This function performs RTEMS configuration. Following function
6+
# arguments are mandatory:
7+
#
78
# 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>
9+
# 2. RTEMS prefix. This is generally the path where the RTEMS tools and BSPs
10+
# are installed. More experienced users can use multiple prefixes.
11+
# This value will be cached inside the RTEMS_PREFIX variable.
12+
# 3. RTEMS BSP pair name, which consists generally has the
13+
# format <Architecture>/<BSP>. This variable will be cached inside
14+
# the RTEMS_BSP variable.
15+
#
16+
# Other variables which can be provided by the developer via command line
17+
# as well:
18+
#
19+
# 1. RTEMS_VERSION:
20+
# The user can supply RTEMS_VERSION to specify the RTEMS version
21+
# manually. This is required to determine the toolchains to use. If no
22+
# RTEMS_VERSION is supplied, this CMake file will try to autodetermine the
23+
# RTEMS version from the supplied tools path.
24+
# 2. RTEMS_TOOLS:
25+
# The user can provide this filepath variable if the RTEMS tools path is
26+
# not equal to the RTEMS prefix.
27+
# 3. RTEMS_PATH:
28+
# The user can provide this filepath variable if the RTEMS path (containg
29+
# the BSPs) is not equal to the RTEMS prefix.
30+
#
31+
# Any additional arguments will be passed on to the subfunctions here.
1032

11-
function(rtems_general_config TARGET_NAME RTEMS_INST RTEMS_BSP)
33+
function(rtems_general_config TARGET_NAME RTEMS_PREFIX RTEMS_BSP_PAIR)
1234

13-
set(RTEMS_BSP_LIB_PATH CACHE INTERNAL "")
14-
set(RTEMS_BSP_INC_PATH CACHE INTERNAL "")
15-
set(RTEMS_ARCH_LIB_PATH CACHE INTERNAL "")
16-
1735
include(${RTEMS_CONFIG_DIRECTORY}/RTEMSGeneric.cmake)
18-
rtems_generic_config(${TARGET_NAME} ${RTEMS_INST} ${RTEMS_BSP})
36+
rtems_generic_config(${TARGET_NAME} ${RTEMS_PREFIX} ${RTEMS_BSP_PAIR} ${ARGN})
1937

2038
# Not an ideal solution but it will do for now because the number of
2139
# variables which need to be propagated to the upper most CMakeLists.txt
2240
# should not become too high.
23-
if(NOT ${CMAKE_SYSTEM_PROCESSOR} STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR})
24-
set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR} PARENT_SCOPE)
25-
endif()
41+
# We could also use CMAKE_TOOLCHAIN_FILE but this way works as well and we
42+
# dont have to supply the file each time, we can set the location in
43+
# the uppermost CMakeLists.txt once.
44+
2645
set(CMAKE_C_COMPILER ${CMAKE_C_COMPILER} PARENT_SCOPE)
2746
set(CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER} PARENT_SCOPE)
2847
set(CMAKE_ASM_COMPILER ${CMAKE_ASM_COMPILER} PARENT_SCOPE)
2948
set(CMAKE_LINKER ${CMAKE_LINKER} PARENT_SCOPE)
49+
50+
# I don't know what this is used for yet, but it might become handy
51+
if(NOT ${CMAKE_SYSTEM_PROCESSOR} STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR})
52+
set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR} PARENT_SCOPE)
53+
endif()
3054

3155
include(${RTEMS_CONFIG_DIRECTORY}/RTEMSHardware.cmake)
32-
rtems_hw_config(${TARGET_NAME} ${RTEMS_INST} ${RTEMS_BSP})
56+
rtems_hw_config(${TARGET_NAME} ${RTEMS_PREFIX} ${RTEMS_BSP_PAIR} ${ARGN})
3357

3458
# No propagation necessary here because we can use target specific settings.
3559

RTEMSGeneric.cmake

Lines changed: 136 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,87 +2,172 @@
22
# Generic RTEMS configuration
33
################################################################################
44

5-
# This function performs the generic RTEMS configuration. It expects
6-
# following arguments:
5+
# This function performs the generic RTEMS configuration. Following function
6+
# arguments are mandatory:
7+
#
78
# 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)
9+
# 2. RTEMS prefix. This is generally the path where the RTEMS tools and BSPs
10+
# are installed. More experienced users can use multiple prefixes.
11+
# This value will be cached inside the RTEMS_PREFIX variable.
12+
# 3. RTEMS BSP pair name, which consists generally has the
13+
# format <Architecture>/<BSP>. This variable will be cached inside
14+
# the RTEMS_BSP variable.
15+
#
16+
# Other variables which can be provided by the developer via command line
17+
# as well:
18+
#
19+
# 1. RTEMS_VERSION:
20+
# The user can supply RTEMS_VERSION to specify the RTEMS version
21+
# manually. This is required to determine the toolchains to use. If no
22+
# RTEMS_VERSION is supplied, this CMake file will try to autodetermine the
23+
# RTEMS version from the supplied tools path.
24+
# 2. RTEMS_TOOLS:
25+
# The user can provide this filepath variable if the RTEMS tools path is
26+
# not equal to the RTEMS prefix.
27+
# 3. RTEMS_PATH:
28+
# The user can provide this filepath variable if the RTEMS path (containig
29+
# the BSPs) is not equal to the RTEMS prefix.
30+
31+
function(rtems_generic_config TARGET_NAME RTEMS_PREFIX RTEMS_BSP_PAIR)
32+
33+
set (EXTRA_RTEMS_ARGS ${ARGN})
34+
list(LENGTH EXTRA_RTEMS_ARGS NUM_EXTRA_RTEMS_ARGS)
35+
36+
if (${NUM_EXTRA_RTEMS_ARGS} EQUAL 1)
37+
# This only works for one optional arguments! Need to write list to
38+
# single variables if this is extended.
39+
set(RTEMS_PATH ${EXTRA_RTEMS_ARGS})
40+
endif()
1141

12-
set(RTEMS_VERSION "" CACHE STRING "RTEMS version")
42+
set(RTEMS_PREFIX ${RTEMS_PREFIX} CACHE FILEPATH "RTEMS prefix")
43+
set(RTEMS_BSP ${RTEMS_BSP} CACHE STRING "RTEMS BSP pair")
1344

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}")
45+
set(RTEMS_INSTALL
46+
${CMAKE_INSTALL_PREFIX}
47+
CACHE FILEPATH "RTEMS install destination"
48+
)
49+
50+
if(NOT RTEMS_PATH)
51+
message(STATUS
52+
"RTEMS path was not specified and was set to RTEMS prefix."
53+
)
54+
set(RTEMS_PATH ${RTEMS_PREFIX} CACHE FILEPATH "RTEMS folder")
55+
else()
56+
set(RTEMS_TOOLS ${RTEMS_PATH} CACHE FILEPATH "RTEMS path folder")
57+
endif()
58+
59+
if(NOT RTEMS_TOOLS)
60+
message(STATUS
61+
"RTEMS toolchain path was not specified and was set to RTEMS prefix."
62+
)
63+
set(RTEMS_TOOLS ${RTEMS_PREFIX} CACHE FILEPATH "RTEMS tools folder")
64+
else()
65+
set(RTEMS_TOOLS ${RTEMS_TOOLS} CACHE FILEPATH "RTEMS tools folder")
66+
endif()
67+
68+
if(NOT RTEMS_VERSION)
69+
message(STATUS "No RTEMS_VERSION supplied.")
70+
message(STATUS "Autodetermining version from tools path ${RTEMS_TOOLS} ..")
71+
string(REGEX MATCH [0-9]+$ RTEMS_VERSION "${RTEMS_TOOLS}")
2372
message(STATUS "Version ${RTEMS_VERSION} found")
2473
endif()
2574

26-
string(REPLACE "/" ";" RTEMS_BSP_LIST_SEPARATED ${RTEMS_BSP})
75+
set(RTEMS_VERSION "${RTEMS_VERSION}" CACHE STRING "RTEMS version")
76+
77+
message(STATUS "Setting up and checking RTEMS cross compile configuration..")
78+
79+
string(REPLACE "/" ";" RTEMS_BSP_LIST_SEPARATED ${RTEMS_BSP_PAIR})
2780
list(LENGTH RTEMS_BSP_LIST_SEPARATED BSP_LIST_SIZE)
2881

2982
if(NOT ${BSP_LIST_SIZE} EQUAL 2)
30-
message(FATAL_ERROR "Supplied RTEMS_BSP variable invalid. Make sure to provide a slash separated string")
83+
message(FATAL_ERROR
84+
"Supplied RTEMS_BSP variable invalid. "
85+
"Make sure to provide a slash separated string"
86+
)
3187
endif()
3288

3389
list(GET RTEMS_BSP_LIST_SEPARATED 0 RTEMS_ARCH_NAME)
3490
list(GET RTEMS_BSP_LIST_SEPARATED 1 RTEMS_BSP_NAME)
3591

3692
set(RTEMS_ARCH_TOOLS "${RTEMS_ARCH_NAME}-rtems${RTEMS_VERSION}")
3793

38-
if(IS_DIRECTORY "${RTEMS_INST}/${RTEMS_ARCH_TOOLS}")
39-
if(IS_DIRECTORY "${RTEMS_INST}/${RTEMS_ARCH_TOOLS}/lib")
40-
set(RTEMS_ARCH_LIB_PATH "${RTEMS_INST}/${RTEMS_ARCH_TOOLS}/lib" PARENT_SCOPE)
41-
endif()
42-
set(RTEMS_BSP_LIB_PATH "${RTEMS_INST}/${RTEMS_ARCH_TOOLS}/${RTEMS_BSP_NAME}/lib")
43-
if(NOT IS_DIRECTORY "${RTEMS_BSP_LIB_PATH}")
44-
message(FATAL_ERROR "RTEMS BSP lib folder not found at ${RTEMS_BSP_LIB_PATH}")
45-
endif()
46-
set(RTEMS_BSP_INC_PATH "${RTEMS_BSP_LIB_PATH}/include")
47-
if(NOT IS_DIRECTORY "${RTEMS_BSP_INC_PATH}")
48-
message(FATAL_ERROR "RTEMS BSP include folder not found at ${RTEMS_BSP_INC_PATH}")
49-
endif()
50-
else()
51-
message(FATAL_ERROR "RTEMS Architecure folder not found at ${RTEMS_INST}/${RTEMS_ARCH_TOOLS}")
94+
if(NOT IS_DIRECTORY "${RTEMS_PATH}/${RTEMS_ARCH_TOOLS}")
95+
message(FATAL_ERROR
96+
"RTEMS architecure folder not found at "
97+
"${RTEMS_PATH}/${RTEMS_ARCH_TOOLS}"
98+
)
99+
endif()
100+
101+
set(RTEMS_BSP_PATH "${RTEMS_PATH}/${RTEMS_ARCH_TOOLS}/${RTEMS_BSP_NAME}")
102+
if(NOT IS_DIRECTORY ${RTEMS_BSP_PATH})
103+
message(STATUS
104+
"Supplied or autodetermined BSP path "
105+
"${RTEMS_BSP_PATH} is invalid!"
106+
)
107+
message(FATAL_ERROR
108+
"Please check the BSP path or make sure "
109+
"the BSP is installed."
110+
)
52111
endif()
53112

113+
set(RTEMS_BSP_LIB_PATH "${RTEMS_BSP_PATH}/lib")
114+
if(NOT IS_DIRECTORY "${RTEMS_BSP_LIB_PATH}")
115+
message(FATAL_ERROR
116+
"RTEMS BSP lib folder not found at "
117+
"${RTEMS_BSP_LIB_PATH}"
118+
)
119+
endif()
120+
set(RTEMS_BSP_INC_PATH "${RTEMS_BSP_LIB_PATH}/include")
121+
if(NOT IS_DIRECTORY "${RTEMS_BSP_INC_PATH}")
122+
message(FATAL_ERROR
123+
"RTEMS BSP include folder not found at "
124+
"${RTEMS_BSP_INC_PATH}"
125+
)
126+
endif()
127+
128+
54129
################################################################################
55130
# Checking the toolchain
56131
################################################################################
57132

58133
message(STATUS "Checking for RTEMS binaries folder..")
59-
set(RTEMS_BIN_PATH "${RTEMS_INST}/bin")
134+
set(RTEMS_BIN_PATH "${RTEMS_TOOLS}/bin")
60135
if(NOT IS_DIRECTORY "${RTEMS_BIN_PATH}")
61-
message(FATAL_ERROR "RTEMS binaries folder not found at ${RTEMS_INST}/bin")
136+
message(FATAL_ERROR "RTEMS binaries folder not found at ${RTEMS_TOOLS}/bin")
62137
endif()
63138

64139
message(STATUS "Checking for RTEMS gcc..")
65140
set(RTEMS_GCC "${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-gcc")
66141
if(NOT EXISTS "${RTEMS_GCC}")
67-
message(FATAL_ERROR "RTEMS gcc compiler not found at ${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-gcc")
142+
message(FATAL_ERROR
143+
"RTEMS gcc compiler not found at "
144+
"${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-gcc"
145+
)
68146
endif()
69147

70148
message(STATUS "Checking for RTEMS g++..")
71149
set(RTEMS_GXX "${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-g++")
72150
if(NOT EXISTS "${RTEMS_GXX}")
73-
message(FATAL_ERROR "RTEMS g++ compiler not found at ${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-g++")
151+
message(FATAL_ERROR
152+
"RTEMS g++ compiler not found at "
153+
"${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-g++"
154+
)
74155
endif()
75156

76157
message(STATUS "Checking for RTEMS assembler..")
77158
set(RTEMS_ASM "${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-as")
78159
if(NOT EXISTS "${RTEMS_GXX}")
79-
message(FATAL_ERROR "RTEMS as compiler not found at ${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-as")
160+
message(FATAL_ERROR
161+
"RTEMS as compiler not found at "
162+
"${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-as")
80163
endif()
81164

82165
message(STATUS "Checking for RTEMS linker..")
83166
set(RTEMS_LINKER "${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-ld")
84167
if(NOT EXISTS "${RTEMS_LINKER}")
85-
message(FATAL_ERROR "RTEMS ld linker not found at ${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-ld")
168+
message(FATAL_ERROR
169+
"RTEMS ld linker not found at "
170+
"${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-ld")
86171
endif()
87172

88173
message(STATUS "Checking done")
@@ -91,12 +176,15 @@ message(STATUS "Checking done")
91176
# Info output
92177
###########################################
93178

94-
message(STATUS "RTEMS Version: ${RTEMS_VERSION}")
95-
message(STATUS "RTEMS installation path: ${RTEMS_INST}")
96-
message(STATUS "RTEMS Architecture tools path: ${RTEMS_ARCH_TOOLS}")
97-
message(STATUS "RTEMS BSP: ${RTEMS_BSP}")
98-
message(STATUS "RTEMS BSP LIB path: ${RTEMS_BSP_LIB_PATH}")
99-
message(STATUS "RTEMS BSP INC path: ${RTEMS_BSP_INC_PATH}")
179+
message(STATUS "RTEMS version: ${RTEMS_VERSION}")
180+
message(STATUS "RTEMS prefix: ${RTEMS_PREFIX}")
181+
message(STATUS "RTEMS tools path: ${RTEMS_TOOLS}")
182+
message(STATUS "RTEMS BSP pair: ${RTEMS_BSP}")
183+
message(STATUS "RTEMS architecture tools path: "
184+
"${RTEMS_PATH}/${RTEMS_ARCH_TOOLS}")
185+
message(STATUS "RTEMS BSP library path: ${RTEMS_BSP_LIB_PATH}")
186+
message(STATUS "RTEMS BSP include path: ${RTEMS_BSP_INC_PATH}")
187+
message(STATUS "RTEMS install target: ${RTEMS_INSTALL}")
100188

101189
message(STATUS "RTEMS gcc compiler: ${RTEMS_GCC}")
102190
message(STATUS "RTEMS g++ compiler: ${RTEMS_GXX}")
@@ -116,7 +204,10 @@ set(CMAKE_CXX_COMPILER ${RTEMS_GXX} PARENT_SCOPE)
116204
set(CMAKE_ASM_COMPILER ${RTEMS_ASM} PARENT_SCOPE)
117205
set(CMAKE_LINKER ${RTEMS_LINKER} PARENT_SCOPE)
118206

119-
set(RTEMS_BSP_LIB_PATH ${RTEMS_BSP_LIB_PATH} PARENT_SCOPE)
120-
set(RTEMS_BSP_INC_PATH ${RTEMS_BSP_INC_PATH} PARENT_SCOPE)
207+
set(RTEMS_BSP_LIB_PATH ${RTEMS_BSP_LIB_PATH} CACHE FILEPATH "BSP library path")
208+
set(RTEMS_BSP_INC_PATH ${RTEMS_BSP_INC_PATH} CACHE FILEPATH "BSP include path")
209+
set(RTEMS_ARCH_LIB_PATH ${RTEMS_BSP_INC_PATH}
210+
CACHE FILEPATH "Architecture library path"
211+
)
121212

122213
endfunction()

0 commit comments

Comments
 (0)