Skip to content

Commit dfc102c

Browse files
authored
Merge pull request #2 from rmspacefish/develop
Develop
2 parents b96bcc1 + 0905fd4 commit dfc102c

File tree

4 files changed

+220
-105
lines changed

4 files changed

+220
-105
lines changed

RTEMSConfig.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
# 3. RTEMS_PATH:
2828
# The user can provide this filepath variable if the RTEMS path (containg
2929
# the BSPs) is not equal to the RTEMS prefix.
30+
# 4. RTEMS_VERBOSE:
31+
# Verbose debug output for the CMake handling.
32+
# 5. RTEMS_SCAN_PKG_CONFIG:
33+
# CMake will try to scan the pkgconfig file for the specified Architecture-
34+
# Version-BSP combination to find the compiler and linker flags.
3035
#
3136
# Any additional arguments will be passed on to the subfunctions here.
3237

RTEMSGeneric.cmake

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ endif()
4141

4242
set(RTEMS_PREFIX ${RTEMS_PREFIX} CACHE FILEPATH "RTEMS prefix")
4343
set(RTEMS_BSP ${RTEMS_BSP} CACHE STRING "RTEMS BSP pair")
44+
option(RTEMS_VERBOSE "Verbose output for the RTEMS CMake support" FALSE)
4445

4546
set(RTEMS_INSTALL
4647
${CMAKE_INSTALL_PREFIX}
@@ -52,17 +53,17 @@ if(NOT RTEMS_PATH)
5253
"RTEMS path was not specified and was set to RTEMS prefix."
5354
)
5455
set(RTEMS_PATH ${RTEMS_PREFIX} CACHE FILEPATH "RTEMS folder")
55-
else()
56-
set(RTEMS_TOOLS ${RTEMS_PATH} CACHE FILEPATH "RTEMS path folder")
56+
#else()
57+
# set(RTEMS_PATH ${RTEMS_PATH} CACHE FILEPATH "RTEMS path folder")
5758
endif()
5859

5960
if(NOT RTEMS_TOOLS)
6061
message(STATUS
6162
"RTEMS toolchain path was not specified and was set to RTEMS prefix."
6263
)
6364
set(RTEMS_TOOLS ${RTEMS_PREFIX} CACHE FILEPATH "RTEMS tools folder")
64-
else()
65-
set(RTEMS_TOOLS ${RTEMS_TOOLS} CACHE FILEPATH "RTEMS tools folder")
65+
#else()
66+
# set(RTEMS_TOOLS ${RTEMS_TOOLS} CACHE FILEPATH "RTEMS tools folder")
6667
endif()
6768

6869
if(NOT RTEMS_VERSION)
@@ -89,16 +90,19 @@ endif()
8990
list(GET RTEMS_BSP_LIST_SEPARATED 0 RTEMS_ARCH_NAME)
9091
list(GET RTEMS_BSP_LIST_SEPARATED 1 RTEMS_BSP_NAME)
9192

92-
set(RTEMS_ARCH_TOOLS "${RTEMS_ARCH_NAME}-rtems${RTEMS_VERSION}")
93+
set(RTEMS_ARCH_VERSION_NAME "${RTEMS_ARCH_NAME}-rtems${RTEMS_VERSION}")
9394

94-
if(NOT IS_DIRECTORY "${RTEMS_PATH}/${RTEMS_ARCH_TOOLS}")
95+
if(NOT IS_DIRECTORY "${RTEMS_TOOLS}/${RTEMS_ARCH_VERSION_NAME}")
9596
message(FATAL_ERROR
9697
"RTEMS architecure folder not found at "
97-
"${RTEMS_PATH}/${RTEMS_ARCH_TOOLS}"
98+
"${RTEMS_TOOLS}/${RTEMS_ARCH_VERSION_NAME}"
9899
)
99100
endif()
100101

101-
set(RTEMS_BSP_PATH "${RTEMS_PATH}/${RTEMS_ARCH_TOOLS}/${RTEMS_BSP_NAME}")
102+
set(RTEMS_ARCH_LIB_PATH "${RTEMS_TOOLS}/${RTEMS_ARCH_VERSION_NAME}/lib")
103+
set(RTEMS_TOOLS_LIB_PATH "${RTEMS_TOOLS}/lib")
104+
105+
set(RTEMS_BSP_PATH "${RTEMS_PATH}/${RTEMS_ARCH_VERSION_NAME}/${RTEMS_BSP_NAME}")
102106
if(NOT IS_DIRECTORY ${RTEMS_BSP_PATH})
103107
message(STATUS
104108
"Supplied or autodetermined BSP path "
@@ -137,37 +141,37 @@ if(NOT IS_DIRECTORY "${RTEMS_BIN_PATH}")
137141
endif()
138142

139143
message(STATUS "Checking for RTEMS gcc..")
140-
set(RTEMS_GCC "${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-gcc")
144+
set(RTEMS_GCC "${RTEMS_BIN_PATH}/${RTEMS_ARCH_VERSION_NAME}-gcc")
141145
if(NOT EXISTS "${RTEMS_GCC}")
142146
message(FATAL_ERROR
143147
"RTEMS gcc compiler not found at "
144-
"${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-gcc"
148+
"${RTEMS_BIN_PATH}/${RTEMS_ARCH_VERSION_NAME}-gcc"
145149
)
146150
endif()
147151

148152
message(STATUS "Checking for RTEMS g++..")
149-
set(RTEMS_GXX "${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-g++")
153+
set(RTEMS_GXX "${RTEMS_BIN_PATH}/${RTEMS_ARCH_VERSION_NAME}-g++")
150154
if(NOT EXISTS "${RTEMS_GXX}")
151155
message(FATAL_ERROR
152156
"RTEMS g++ compiler not found at "
153-
"${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-g++"
157+
"${RTEMS_BIN_PATH}/${RTEMS_ARCH_VERSION_NAME}-g++"
154158
)
155159
endif()
156160

157161
message(STATUS "Checking for RTEMS assembler..")
158-
set(RTEMS_ASM "${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-as")
162+
set(RTEMS_ASM "${RTEMS_BIN_PATH}/${RTEMS_ARCH_VERSION_NAME}-as")
159163
if(NOT EXISTS "${RTEMS_GXX}")
160164
message(FATAL_ERROR
161165
"RTEMS as compiler not found at "
162-
"${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-as")
166+
"${RTEMS_BIN_PATH}/${RTEMS_ARCH_VERSION_NAME}-as")
163167
endif()
164168

165169
message(STATUS "Checking for RTEMS linker..")
166-
set(RTEMS_LINKER "${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-ld")
170+
set(RTEMS_LINKER "${RTEMS_BIN_PATH}/${RTEMS_ARCH_VERSION_NAME}-ld")
167171
if(NOT EXISTS "${RTEMS_LINKER}")
168172
message(FATAL_ERROR
169173
"RTEMS ld linker not found at "
170-
"${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-ld")
174+
"${RTEMS_BIN_PATH}/${RTEMS_ARCH_VERSION_NAME}-ld")
171175
endif()
172176

173177
message(STATUS "Checking done")
@@ -181,7 +185,7 @@ message(STATUS "RTEMS prefix: ${RTEMS_PREFIX}")
181185
message(STATUS "RTEMS tools path: ${RTEMS_TOOLS}")
182186
message(STATUS "RTEMS BSP pair: ${RTEMS_BSP}")
183187
message(STATUS "RTEMS architecture tools path: "
184-
"${RTEMS_PATH}/${RTEMS_ARCH_TOOLS}")
188+
"${RTEMS_PATH}/${RTEMS_ARCH_VERSION_NAME}")
185189
message(STATUS "RTEMS BSP library path: ${RTEMS_BSP_LIB_PATH}")
186190
message(STATUS "RTEMS BSP include path: ${RTEMS_BSP_INC_PATH}")
187191
message(STATUS "RTEMS install target: ${RTEMS_INSTALL}")
@@ -204,10 +208,26 @@ set(CMAKE_CXX_COMPILER ${RTEMS_GXX} PARENT_SCOPE)
204208
set(CMAKE_ASM_COMPILER ${RTEMS_ASM} PARENT_SCOPE)
205209
set(CMAKE_LINKER ${RTEMS_LINKER} PARENT_SCOPE)
206210

211+
# Variables set in the cache so they can be used everywhere.
212+
set(RTEMS_ARCH_NAME ${RTEMS_ARCH_NAME} CACHE FILEPATH "Architecture name")
213+
set(RTEMS_BSP_NAME ${RTEMS_BSP_NAME} CACHE FILEPATH "BSP name")
214+
set(RTEMS_TOOLS_LIB_PATH ${RTEMS_TOOLS_LIB_PATH}
215+
CACHE FILEPATH "Tools library path"
216+
)
207217
set(RTEMS_BSP_LIB_PATH ${RTEMS_BSP_LIB_PATH} CACHE FILEPATH "BSP library path")
208218
set(RTEMS_BSP_INC_PATH ${RTEMS_BSP_INC_PATH} CACHE FILEPATH "BSP include path")
209-
set(RTEMS_ARCH_LIB_PATH ${RTEMS_BSP_INC_PATH}
219+
set(RTEMS_ARCH_LIB_PATH ${RTEMS_ARCH_LIB_PATH}
210220
CACHE FILEPATH "Architecture library path"
211221
)
222+
set(RTEMS_ARCH_VERSION_NAME ${RTEMS_ARCH_VERSION_NAME}
223+
CACHE FILEPATH "Unique architecture-version identifier"
224+
)
225+
226+
list(APPEND CMAKE_PREFIX_PATH ${RTEMS_BSP_LIB_PATH})
227+
list(APPEND CMAKE_PREFIX_PATH ${RTEMS_BSP_INC_PATH})
228+
list(APPEND CMAKE_PREFIX_PATH ${RTEMS_ARCH_LIB_PATH})
229+
list(APPEND CMAKE_PREFIX_PATH ${RTEMS_TOOLS_LIB_PATH})
230+
231+
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} PARENT_SCOPE)
212232

213233
endfunction()

RTEMSHardware.cmake

Lines changed: 138 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -10,93 +10,166 @@
1010
#
1111
# The following paths should have been set and cached previously:
1212
#
13-
# 1. RTEMS_ARCH_LIB_PATH: Library path for the architecture
14-
# 2. RTEMS_BSP_LIB_PATH: Library path for the BSP
15-
# 3. RTEMS_BSP_INC_PATH: Include path for the BSP
13+
# 1. RTEMS_TOOLS: Path for the RTEMS tools
14+
# 2. RTEMS_PATH: Path for the RTEMS BSPs
15+
# 3. RTEMS_ARCH_LIB_PATH: Library path for the architecture
16+
# 4. RTEMS_BSP_LIB_PATH: Library path for the BSP
17+
# 5. RTEMS_BSP_INC_PATH: Include path for the BSP
18+
#
19+
# Following variables change the behaviour of this function
20+
#
21+
# 1. RTEMS_SCAN_PKG_CONFIG: Default to TRUE (1). Attempt to scan pkg-config
22+
# file to determine compiler and linker flags.
23+
# 2. RTEMS_VERBOSE: Default to FALSE (0) .
24+
# Verbose debug output for the CMake handling.
1625
#
1726
# TODO: Maybe CMake can read the pkgconfig .pc files automatically?
1827

1928
function(rtems_hw_config TARGET_NAME RTEMS_PREFIX RTEMS_BSP)
2029

21-
if(RTEMS_BSP STREQUAL "arm/stm32h7")
30+
option(RTEMS_SCAN_PKG_CONFIG
31+
"Attempt to scan PKG config file for compiler and linker flags" TRUE
32+
)
2233

23-
set(ABI_FLAGS
24-
-mthumb
25-
-mcpu=cortex-m7
26-
-mfpu=fpv5-d16
27-
-mfloat-abi=hard
28-
)
29-
30-
target_compile_options(${TARGET_NAME} PUBLIC
31-
"${ABI_FLAGS}"
32-
)
33-
34-
target_include_directories(${TARGET_NAME} PUBLIC
35-
${RTEMS_BSP_INC_PATH}
36-
)
34+
if(${RTEMS_SCAN_PKG_CONFIG})
35+
36+
message(STATUS "Trying to load PkgConfig module..")
37+
find_package(PkgConfig)
38+
39+
set(RTEMS_PKG_MODULE_NAME "${RTEMS_ARCH_VERSION_NAME}-${RTEMS_BSP_NAME}")
40+
set(RTEMS_PKG_MODULE_FILE_NAME "${RTEMS_PKG_MODULE_NAME}.pc")
41+
set(RTEMS_PKG_FILE_PATH "${RTEMS_TOOLS_LIB_PATH}/pkgconfig")
42+
43+
if(IS_DIRECTORY "${RTEMS_PKG_FILE_PATH}")
44+
list(APPEND CMAKE_PREFIX_PATH "${RTEMS_PKG_FILE_PATH}")
45+
if(EXISTS "${RTEMS_PKG_FILE_PATH}/${RTEMS_PKG_MODULE_FILE_NAME}")
46+
message(STATUS "PKG configuration file for given "
47+
"architecture-version-BSP combination found.."
48+
)
49+
endif()
50+
endif()
3751

38-
target_link_options(${TARGET_NAME} BEFORE PUBLIC
39-
"${ABI_FLAGS}"
40-
)
52+
# Known bug: https://gitlab.kitware.com/cmake/cmake/-/issues/18150
53+
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:${RTEMS_PKG_FILE_PATH}")
54+
pkg_check_modules(RTEMS_BSP_CONFIG "${RTEMS_PKG_MODULE_NAME}")
55+
56+
if(${RTEMS_VERBOSE})
57+
message(STATUS "PKG configuration file found: ${RTEMS_BSP_CONFIG_FOUND}")
58+
message(STATUS "Libraries: ${RTEMS_BSP_CONFIG_LIBRARIES}")
59+
message(STATUS "Link libraries: ${_RTEMS_BSP_CONFIGLINK_LIBRARIES}")
60+
message(STATUS "Library directories: ${RTEMS_BSP_CONFIG_LIBRARY_DIRS}")
61+
message(STATUS "LD flags: ${RTEMS_BSP_CONFIG_LDFLAGS}")
62+
message(STATUS "LD flags (other): ${RTEMS_BSP_CONFIG_LDFLAGS_OTHER}")
63+
message(STATUS "Include directories: ${RTEMS_BSP_CONFIG_INCLUDE_DIRS}")
64+
message(STATUS "CFlags: ${RTEMS_BSP_CONFIG_CFLAGS}")
65+
message(STATUS "CFlags (other): ${RTEMS_BSP_CONFIG_CFLAGS_OTHER}")
66+
endif()
4167

42-
target_link_options(${TARGET_NAME} PUBLIC
43-
-Wl,--gc-sections
44-
-Wl,-Bstatic
45-
-Wl,-Bdynamic
46-
-qrtems
47-
-B${RTEMS_BSP_LIB_PATH}
48-
)
68+
else()
69+
70+
set(RTEMS_BSP_CONFIG_FOUND FALSE)
4971

50-
elseif(RTEMS_BSP STREQUAL "sparc/erc32")
72+
endif()
5173

52-
# The options for RSB builds and RTEMS source build are different..
53-
# This one is for the RSB build
54-
if(EXISTS "${RTEMS_BSP_LIB_PATH}/bsp_specs")
74+
# Set flags from PKG files
75+
if(${RTEMS_BSP_CONFIG_FOUND})
76+
message(STATUS "Configuring build flags from pkgconfig file..")
5577

5678
target_compile_options(${TARGET_NAME} PUBLIC
57-
-qrtems
58-
-B${RTEMS_ARCH_LIB_PATH}
59-
-B${RTEMS_BSP_LIB_PATH}
60-
--specs bsp_specs
61-
-mcpu=cypress
62-
-ffunction-sections
63-
-fdata-sections
79+
${RTEMS_BSP_CONFIG_CFLAGS}
6480
)
65-
81+
6682
target_link_options(${TARGET_NAME} PUBLIC
67-
-B${RTEMS_ARCH_LIB_PATH}
68-
-B${RTEMS_BSP_LIB_PATH}
69-
-qrtems
70-
--specs bsp_specs
71-
-Wl,--gc-sections
72-
-Wl,-Bstatic
73-
-Wl,-Bdynamic
83+
${RTEMS_BSP_CONFIG_CFLAGS}
84+
${RTEMS_BSP_CONFIG_LDFLAGS}
7485
)
7586

76-
else()
87+
# TODO: Maybe remove this section or export to separate file?
88+
else()
89+
message(STATUS "Configuring build flags manually..")
7790

78-
target_compile_options(${TARGET_NAME} PUBLIC
79-
-mcpu=cypress
80-
)
91+
# Set flags manually
92+
if(RTEMS_BSP STREQUAL "arm/stm32h7")
93+
94+
set(ABI_FLAGS
95+
-mthumb
96+
-mcpu=cortex-m7
97+
-mfpu=fpv5-d16
98+
-mfloat-abi=hard
99+
)
81100

82-
target_include_directories(${TARGET_NAME} PUBLIC
83-
${RTEMS_BSP_INC_PATH}
84-
)
101+
target_compile_options(${TARGET_NAME} PUBLIC
102+
"${ABI_FLAGS}"
103+
)
85104

86-
target_link_options(${TARGET_NAME} PUBLIC
87-
-qrtems
88-
-B${RTEMS_BSP_LIB_PATH}
89-
-Wl,--gc-sections
90-
)
105+
target_include_directories(${TARGET_NAME} PUBLIC
106+
${RTEMS_BSP_INC_PATH}
107+
)
108+
109+
target_link_options(${TARGET_NAME} BEFORE PUBLIC
110+
"${ABI_FLAGS}"
111+
)
112+
113+
target_link_options(${TARGET_NAME} PUBLIC
114+
-Wl,--gc-sections
115+
-Wl,-Bstatic
116+
-Wl,-Bdynamic
117+
-qrtems
118+
-B${RTEMS_BSP_LIB_PATH}
119+
)
91120

92-
endif()
121+
elseif(RTEMS_BSP STREQUAL "sparc/erc32")
93122

94-
else()
123+
# The options for RSB builds and RTEMS source build are different..
124+
# This one is for the RSB build
125+
if(EXISTS "${RTEMS_BSP_LIB_PATH}/bsp_specs")
95126

96-
status(WARNING
97-
"The pkgconfig for this BSP still needs to be set up"
98-
"transferred to RTEMSHardware.cmake!"
99-
)
127+
target_compile_options(${TARGET_NAME} PUBLIC
128+
-qrtems
129+
-B${RTEMS_ARCH_LIB_PATH}
130+
-B${RTEMS_BSP_LIB_PATH}
131+
--specs bsp_specs
132+
-mcpu=cypress
133+
-ffunction-sections
134+
-fdata-sections
135+
)
136+
137+
target_link_options(${TARGET_NAME} PUBLIC
138+
-B${RTEMS_ARCH_LIB_PATH}
139+
-B${RTEMS_BSP_LIB_PATH}
140+
-qrtems
141+
--specs bsp_specs
142+
-Wl,--gc-sections
143+
-Wl,-Bstatic
144+
-Wl,-Bdynamic
145+
)
146+
147+
else()
148+
149+
target_compile_options(${TARGET_NAME} PUBLIC
150+
-mcpu=cypress
151+
)
152+
153+
target_include_directories(${TARGET_NAME} PUBLIC
154+
${RTEMS_BSP_INC_PATH}
155+
)
156+
157+
target_link_options(${TARGET_NAME} PUBLIC
158+
-qrtems
159+
-B${RTEMS_BSP_LIB_PATH}
160+
-Wl,--gc-sections
161+
)
162+
163+
endif()
164+
165+
else()
166+
167+
status(WARNING
168+
"The pkgconfig for this BSP still needs to be set up"
169+
"transferred to RTEMSHardware.cmake!"
170+
)
171+
172+
endif()
100173

101174
endif()
102175

0 commit comments

Comments
 (0)