Skip to content

Commit 3708111

Browse files
committed
Merge branch 'main' of https://github.com/rmspacefish/rtems-cmake into main
2 parents f5c097a + fdfdf5b commit 3708111

File tree

5 files changed

+667
-90
lines changed

5 files changed

+667
-90
lines changed

README.md

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,82 @@
1-
# rtems-cmake
1+
# RTEMS CMake Build Support
22

3-
This repostiory contains the first version of a possible RTEMS CMake build aupport. The intention is to export the RTEMS specific configuration of the cross compiler toolchain and the flags to external `*.cmake` files so the application `CMakeLists.txt` can stay clean, similarly to the `rtems_waf` support.
3+
This repostiory contains the first version of a possible RTEMS CMake build aupport. The intention is to provide most CMake configuration to perform cross-compiling of RTEMS applications and provide a decent starting point for developers which would like to use RTEMS. The support has been written as generic as possible.
4+
5+
This is still a prototype. Simple applications have been tested, but it has not been attempted to link an additional library for an application yet.
6+
7+
## How to use
8+
9+
Clone this repository. This does not necesarilly have to be in the application root path, but the RTEMS configuration path (the folder containing the `*.cmake` files) needs to be specified in this case.
10+
11+
```sh
12+
git clone https://github.com/rmspacefish/rtems-cmake.git
13+
```
14+
15+
After that, it is recommended to set the path to the RTEMS CMake support with the
16+
following line in the application `CMakeLists.txt`
17+
18+
```sh
19+
set(RTEMS_CONFIG_DIR
20+
"<Path to RTEMS CMake support folder>"
21+
CACHE FILEPATH "Directory containing the RTEMS *.cmake files"
22+
)
23+
```
24+
25+
It is also recommended to add the following lines before the `project()` call in
26+
the application `CMakeLists.txt`:
27+
28+
```sh
29+
set(CMAKE_SYSTEM_NAME Generic)
30+
set(CMAKE_C_COMPILER_WORKS 1)
31+
set(CMAKE_CXX_COMPILER_WORKS 1)
32+
set(CMAKE_CROSSCOMPILING 1)
33+
```
34+
35+
This will disable the compiler checks for the standard C/C++ compiler.
36+
37+
38+
If this repository was cloned inside the application root, the path can be
39+
set to `${CMAKE_CURRENT_SOURCE_DIRECTORY}`.
40+
41+
After that, include the general configuration file with the following line:
42+
43+
```sh
44+
include("${RTEMS_CONFIG_DIR}/RTEMSConfig.cmake")
45+
```
46+
47+
And then call the configuration function:
48+
49+
```sh
50+
rtems_general_config(${CMAKE_PROJECT_NAME} ${RTEMS_PREFIX} ${RTEMS_BSP})
51+
```
52+
53+
This function will call the the `rtems_generic_config` function internally to set up the cross-compiler, using the provided RTEMS prefix and the BSP name,
54+
and the RTEMS BSP (e.g. sparc/erc32) to this function.
55+
56+
After that, it will call the the function `rtems_hw_config` which will assign necessary compiler and linker flags to the provided target.
57+
58+
## Optional configuration of the CMake support
59+
60+
The RTEMS CMake build support can be configured either by passing configuration options prepended with `-D` to the build command or by setting these build variables in the application `CMakeLists.txt` before calling the build support. Following options are available
61+
62+
- `RTEMS_VERSION`: Can be specified manually. If this is not specified, the CMake build support will attempt to extract the version number from the RTEMS prefix (last letter of path). This variable needs to be valid for the RTEMS support to work!
63+
- `RTEMS_VERBOSE`: Enable additional diagnostic output.
64+
- `RTEMS_SCAN_PKG_CONFIG`: The RTEMS CMake support will try to read the pkgconfig files to extract compile and link flag options.
65+
- `RTEMS_TOOLS`: Can be specified if the RTEMS tools folder. Can be different from the prefix but will be equal to the prefix for most users.
66+
- `RTEMS_PATH`: Folder containing the RTEMS installation (BSPs). Can be different from the prefix but will be equal to the prefix for most users.
67+
68+
## Extending the build system support
69+
70+
It is possible to read the pkfconfig files now, so extending the manual build configuration might not be necessary in the future.
71+
72+
Extending the build support is relatively easy:
73+
74+
Extract the necessary compiler and linker flags for the RTEMS build from the pkgconfig file
75+
for the specific BSP. This file will generally be located inside the `lib/pkgconfig` folder of the RTEMS tools folder. Add these flags in the `RTEMSHardware.cmake` file for your specific BSP.
76+
77+
When building with CMake, `-v` can be added to verify the flags.
78+
79+
## Example
80+
81+
See https://github.com/rmspacefish/rtems-demo/tree/master/applications/hello for an example. This is the Hello World project taken from the RTEMS quick start guide,
82+
but compiled using RTEMS. The repository also contains instructions on how to build the RTEMS tools if required and all specific steps to build with CMake.

RTEMSConfig.cmake

Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,79 @@
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+
# or in the application CMake file as well:
18+
#
19+
# 1. RTEMS_CONFIG_DIR: The application will assume that all other configuration
20+
# files are located in this path or relative to this path. If this is not set
21+
# it will be set to the ${CMAKE_CURRENT_SOURCE_DIR}/rtems-cmake
22+
# 2. RTEMS_VERSION:
23+
# The user can supply RTEMS_VERSION to specify the RTEMS version
24+
# manually. This is required to determine the toolchains to use. If no
25+
# RTEMS_VERSION is supplied, this CMake file will try to autodetermine the
26+
# RTEMS version from the supplied tools path.
27+
# 3. RTEMS_TOOLS:
28+
# The user can provide this filepath variable if the RTEMS tools path is
29+
# not equal to the RTEMS prefix.
30+
# 4. RTEMS_PATH:
31+
# The user can provide this filepath variable if the RTEMS path (containg
32+
# the BSPs) is not equal to the RTEMS prefix.
33+
# 5. RTEMS_VERBOSE:
34+
# Verbose debug output for the CMake handling.
35+
# 6. RTEMS_SCAN_PKG_CONFIG:
36+
# CMake will try to scan the pkgconfig file for the specified Architecture-
37+
# Version-BSP combination to find the compiler and linker flags.
38+
#
39+
# Any additional arguments will be passed on to the subfunctions here.
1040

11-
function(rtems_general_config TARGET_NAME RTEMS_INST RTEMS_BSP)
41+
function(rtems_general_config TARGET_NAME RTEMS_PREFIX RTEMS_BSP_PAIR)
1242

13-
include(RTEMSGeneric.cmake)
14-
rtems_generic_config(${TARGET_NAME} ${RTEMS_INST} ${RTEMS_BSP})
43+
message(STATUS ${RTEMS_CONFIG_DIR})
44+
if(NOT RTEMS_CONFIG_DIR)
45+
message(STATUS
46+
"RTEMS_CONFIG_DIR not set. Assuming the CMake support was "
47+
"cloned in the application source directory.."
48+
)
49+
set(RTEMS_CONFIG_DIR ${CMAKE_CURRENT_SOURCE_DIR}/rtems-cmake)
50+
endif()
51+
52+
include(${RTEMS_CONFIG_DIR}/RTEMSGeneric.cmake)
53+
rtems_generic_config(${TARGET_NAME} ${RTEMS_PREFIX} ${RTEMS_BSP_PAIR} ${ARGN})
1554

1655
# Not an ideal solution but it will do for now because the number of
1756
# variables which need to be propagated to the upper most CMakeLists.txt
1857
# 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()
58+
# We could also use CMAKE_TOOLCHAIN_FILE but this way works as well and we
59+
# dont have to supply the file each time, we can set the location in
60+
# the uppermost CMakeLists.txt once.
61+
2262
set(CMAKE_C_COMPILER ${CMAKE_C_COMPILER} PARENT_SCOPE)
2363
set(CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER} PARENT_SCOPE)
2464
set(CMAKE_ASM_COMPILER ${CMAKE_ASM_COMPILER} PARENT_SCOPE)
2565
set(CMAKE_LINKER ${CMAKE_LINKER} PARENT_SCOPE)
2666
message(STATUS ${RTEMS_OBJCOPY})
2767
set(RTEMS_OBJCOPY ${RTEMS_OBJCOPY} PARENT_SCOPE)
68+
69+
# I don't know what this is used for yet, but it might become handy
70+
if(NOT ${CMAKE_SYSTEM_PROCESSOR} STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR})
71+
set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR} PARENT_SCOPE)
72+
endif()
2873

29-
include(RTEMSHardware.cmake)
30-
rtems_hw_config(${TARGET_NAME} ${RTEMS_INST} ${RTEMS_BSP})
74+
include(${RTEMS_CONFIG_DIR}/RTEMSHardware.cmake)
75+
rtems_hw_config(${TARGET_NAME} ${RTEMS_PREFIX} ${RTEMS_BSP_PAIR} ${ARGN})
3176

3277
# No propagation necessary here because we can use target specific settings.
3378

34-
endfunction()
79+
endfunction()

0 commit comments

Comments
 (0)