Skip to content

Commit

Permalink
Merge pull request #1 from rmspacefish/develop
Browse files Browse the repository at this point in the history
Interface aligned to RTEMS now, several bugfixes
  • Loading branch information
robamu authored Dec 11, 2020
2 parents ae09e36 + 484fe3a commit b96bcc1
Show file tree
Hide file tree
Showing 4 changed files with 438 additions and 112 deletions.
58 changes: 41 additions & 17 deletions RTEMSConfig.cmake
Original file line number Diff line number Diff line change
@@ -1,35 +1,59 @@
########################################
# General RTEMS configuration
########################################
################################################################################
# RTEMS configuration
################################################################################

# This function performs the generic RTEMS configuration. It expects
# following arguments:
# This function performs RTEMS configuration. Following function
# arguments are mandatory:
#
# 1. Target/executable name
# 2. RTEMS installation prefix, path where the RTEMS toolchain is installed
# 3. RTEMS BSP, which consists generally has the format <Architecture>/<BSP>
# 2. RTEMS prefix. This is generally the path where the RTEMS tools and BSPs
# are installed. More experienced users can use multiple prefixes.
# This value will be cached inside the RTEMS_PREFIX variable.
# 3. RTEMS BSP pair name, which consists generally has the
# format <Architecture>/<BSP>. This variable will be cached inside
# the RTEMS_BSP variable.
#
# Other variables which can be provided by the developer via command line
# as well:
#
# 1. RTEMS_VERSION:
# The user can supply RTEMS_VERSION to specify the RTEMS version
# manually. This is required to determine the toolchains to use. If no
# RTEMS_VERSION is supplied, this CMake file will try to autodetermine the
# RTEMS version from the supplied tools path.
# 2. RTEMS_TOOLS:
# The user can provide this filepath variable if the RTEMS tools path is
# not equal to the RTEMS prefix.
# 3. RTEMS_PATH:
# The user can provide this filepath variable if the RTEMS path (containg
# the BSPs) is not equal to the RTEMS prefix.
#
# Any additional arguments will be passed on to the subfunctions here.

function(rtems_general_config TARGET_NAME RTEMS_INST RTEMS_BSP)
function(rtems_general_config TARGET_NAME RTEMS_PREFIX RTEMS_BSP_PAIR)

set(RTEMS_BSP_LIB_PATH CACHE INTERNAL "")
set(RTEMS_BSP_INC_PATH CACHE INTERNAL "")
set(RTEMS_ARCH_LIB_PATH CACHE INTERNAL "")

include(${RTEMS_CONFIG_DIRECTORY}/RTEMSGeneric.cmake)
rtems_generic_config(${TARGET_NAME} ${RTEMS_INST} ${RTEMS_BSP})
rtems_generic_config(${TARGET_NAME} ${RTEMS_PREFIX} ${RTEMS_BSP_PAIR} ${ARGN})

# Not an ideal solution but it will do for now because the number of
# variables which need to be propagated to the upper most CMakeLists.txt
# should not become too high.
if(NOT ${CMAKE_SYSTEM_PROCESSOR} STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR})
set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR} PARENT_SCOPE)
endif()
# We could also use CMAKE_TOOLCHAIN_FILE but this way works as well and we
# dont have to supply the file each time, we can set the location in
# the uppermost CMakeLists.txt once.

set(CMAKE_C_COMPILER ${CMAKE_C_COMPILER} PARENT_SCOPE)
set(CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER} PARENT_SCOPE)
set(CMAKE_ASM_COMPILER ${CMAKE_ASM_COMPILER} PARENT_SCOPE)
set(CMAKE_LINKER ${CMAKE_LINKER} PARENT_SCOPE)

# I don't know what this is used for yet, but it might become handy
if(NOT ${CMAKE_SYSTEM_PROCESSOR} STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR})
set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR} PARENT_SCOPE)
endif()

include(${RTEMS_CONFIG_DIRECTORY}/RTEMSHardware.cmake)
rtems_hw_config(${TARGET_NAME} ${RTEMS_INST} ${RTEMS_BSP})
rtems_hw_config(${TARGET_NAME} ${RTEMS_PREFIX} ${RTEMS_BSP_PAIR} ${ARGN})

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

Expand Down
181 changes: 136 additions & 45 deletions RTEMSGeneric.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,87 +2,172 @@
# Generic RTEMS configuration
################################################################################

# This function performs the generic RTEMS configuration. It expects
# following arguments:
# This function performs the generic RTEMS configuration. Following function
# arguments are mandatory:
#
# 1. Target/executable name
# 2. RTEMS installation prefix, path where the RTEMS toolchain is installed
# 3. RTEMS BSP, which consists generally has the format <Architecture>/<BSP>
function(rtems_generic_config TARGET_NAME RTEMS_INST RTEMS_BSP)
# 2. RTEMS prefix. This is generally the path where the RTEMS tools and BSPs
# are installed. More experienced users can use multiple prefixes.
# This value will be cached inside the RTEMS_PREFIX variable.
# 3. RTEMS BSP pair name, which consists generally has the
# format <Architecture>/<BSP>. This variable will be cached inside
# the RTEMS_BSP variable.
#
# Other variables which can be provided by the developer via command line
# as well:
#
# 1. RTEMS_VERSION:
# The user can supply RTEMS_VERSION to specify the RTEMS version
# manually. This is required to determine the toolchains to use. If no
# RTEMS_VERSION is supplied, this CMake file will try to autodetermine the
# RTEMS version from the supplied tools path.
# 2. RTEMS_TOOLS:
# The user can provide this filepath variable if the RTEMS tools path is
# not equal to the RTEMS prefix.
# 3. RTEMS_PATH:
# The user can provide this filepath variable if the RTEMS path (containig
# the BSPs) is not equal to the RTEMS prefix.

function(rtems_generic_config TARGET_NAME RTEMS_PREFIX RTEMS_BSP_PAIR)

set (EXTRA_RTEMS_ARGS ${ARGN})
list(LENGTH EXTRA_RTEMS_ARGS NUM_EXTRA_RTEMS_ARGS)

if (${NUM_EXTRA_RTEMS_ARGS} EQUAL 1)
# This only works for one optional arguments! Need to write list to
# single variables if this is extended.
set(RTEMS_PATH ${EXTRA_RTEMS_ARGS})
endif()

set(RTEMS_VERSION "" CACHE STRING "RTEMS version")
set(RTEMS_PREFIX ${RTEMS_PREFIX} CACHE FILEPATH "RTEMS prefix")
set(RTEMS_BSP ${RTEMS_BSP} CACHE STRING "RTEMS BSP pair")

message(STATUS "Setting up and checking RTEMS cross compile configuration..")
if (RTEMS_INST STREQUAL "")
message(FATAL_ERROR "RTEMS toolchain path has to be specified!")
endif()

if(RTEMS_VERSION STREQUAL "")
message(STATUS "No RTEMS_VERSION supplied.")
message(STATUS "Autodetermining version from prefix ${RTEMS_INST} ..")
string(REGEX MATCH [0-9]+$ RTEMS_VERSION "${RTEMS_INST}")
set(RTEMS_INSTALL
${CMAKE_INSTALL_PREFIX}
CACHE FILEPATH "RTEMS install destination"
)

if(NOT RTEMS_PATH)
message(STATUS
"RTEMS path was not specified and was set to RTEMS prefix."
)
set(RTEMS_PATH ${RTEMS_PREFIX} CACHE FILEPATH "RTEMS folder")
else()
set(RTEMS_TOOLS ${RTEMS_PATH} CACHE FILEPATH "RTEMS path folder")
endif()

if(NOT RTEMS_TOOLS)
message(STATUS
"RTEMS toolchain path was not specified and was set to RTEMS prefix."
)
set(RTEMS_TOOLS ${RTEMS_PREFIX} CACHE FILEPATH "RTEMS tools folder")
else()
set(RTEMS_TOOLS ${RTEMS_TOOLS} CACHE FILEPATH "RTEMS tools folder")
endif()

if(NOT RTEMS_VERSION)
message(STATUS "No RTEMS_VERSION supplied.")
message(STATUS "Autodetermining version from tools path ${RTEMS_TOOLS} ..")
string(REGEX MATCH [0-9]+$ RTEMS_VERSION "${RTEMS_TOOLS}")
message(STATUS "Version ${RTEMS_VERSION} found")
endif()

string(REPLACE "/" ";" RTEMS_BSP_LIST_SEPARATED ${RTEMS_BSP})
set(RTEMS_VERSION "${RTEMS_VERSION}" CACHE STRING "RTEMS version")

message(STATUS "Setting up and checking RTEMS cross compile configuration..")

string(REPLACE "/" ";" RTEMS_BSP_LIST_SEPARATED ${RTEMS_BSP_PAIR})
list(LENGTH RTEMS_BSP_LIST_SEPARATED BSP_LIST_SIZE)

if(NOT ${BSP_LIST_SIZE} EQUAL 2)
message(FATAL_ERROR "Supplied RTEMS_BSP variable invalid. Make sure to provide a slash separated string")
message(FATAL_ERROR
"Supplied RTEMS_BSP variable invalid. "
"Make sure to provide a slash separated string"
)
endif()

list(GET RTEMS_BSP_LIST_SEPARATED 0 RTEMS_ARCH_NAME)
list(GET RTEMS_BSP_LIST_SEPARATED 1 RTEMS_BSP_NAME)

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

if(IS_DIRECTORY "${RTEMS_INST}/${RTEMS_ARCH_TOOLS}")
if(IS_DIRECTORY "${RTEMS_INST}/${RTEMS_ARCH_TOOLS}/lib")
set(RTEMS_ARCH_LIB_PATH "${RTEMS_INST}/${RTEMS_ARCH_TOOLS}/lib" PARENT_SCOPE)
endif()
set(RTEMS_BSP_LIB_PATH "${RTEMS_INST}/${RTEMS_ARCH_TOOLS}/${RTEMS_BSP_NAME}/lib")
if(NOT IS_DIRECTORY "${RTEMS_BSP_LIB_PATH}")
message(FATAL_ERROR "RTEMS BSP lib folder not found at ${RTEMS_BSP_LIB_PATH}")
endif()
set(RTEMS_BSP_INC_PATH "${RTEMS_BSP_LIB_PATH}/include")
if(NOT IS_DIRECTORY "${RTEMS_BSP_INC_PATH}")
message(FATAL_ERROR "RTEMS BSP include folder not found at ${RTEMS_BSP_INC_PATH}")
endif()
else()
message(FATAL_ERROR "RTEMS Architecure folder not found at ${RTEMS_INST}/${RTEMS_ARCH_TOOLS}")
if(NOT IS_DIRECTORY "${RTEMS_PATH}/${RTEMS_ARCH_TOOLS}")
message(FATAL_ERROR
"RTEMS architecure folder not found at "
"${RTEMS_PATH}/${RTEMS_ARCH_TOOLS}"
)
endif()

set(RTEMS_BSP_PATH "${RTEMS_PATH}/${RTEMS_ARCH_TOOLS}/${RTEMS_BSP_NAME}")
if(NOT IS_DIRECTORY ${RTEMS_BSP_PATH})
message(STATUS
"Supplied or autodetermined BSP path "
"${RTEMS_BSP_PATH} is invalid!"
)
message(FATAL_ERROR
"Please check the BSP path or make sure "
"the BSP is installed."
)
endif()

set(RTEMS_BSP_LIB_PATH "${RTEMS_BSP_PATH}/lib")
if(NOT IS_DIRECTORY "${RTEMS_BSP_LIB_PATH}")
message(FATAL_ERROR
"RTEMS BSP lib folder not found at "
"${RTEMS_BSP_LIB_PATH}"
)
endif()
set(RTEMS_BSP_INC_PATH "${RTEMS_BSP_LIB_PATH}/include")
if(NOT IS_DIRECTORY "${RTEMS_BSP_INC_PATH}")
message(FATAL_ERROR
"RTEMS BSP include folder not found at "
"${RTEMS_BSP_INC_PATH}"
)
endif()


################################################################################
# Checking the toolchain
################################################################################

message(STATUS "Checking for RTEMS binaries folder..")
set(RTEMS_BIN_PATH "${RTEMS_INST}/bin")
set(RTEMS_BIN_PATH "${RTEMS_TOOLS}/bin")
if(NOT IS_DIRECTORY "${RTEMS_BIN_PATH}")
message(FATAL_ERROR "RTEMS binaries folder not found at ${RTEMS_INST}/bin")
message(FATAL_ERROR "RTEMS binaries folder not found at ${RTEMS_TOOLS}/bin")
endif()

message(STATUS "Checking for RTEMS gcc..")
set(RTEMS_GCC "${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-gcc")
if(NOT EXISTS "${RTEMS_GCC}")
message(FATAL_ERROR "RTEMS gcc compiler not found at ${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-gcc")
message(FATAL_ERROR
"RTEMS gcc compiler not found at "
"${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-gcc"
)
endif()

message(STATUS "Checking for RTEMS g++..")
set(RTEMS_GXX "${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-g++")
if(NOT EXISTS "${RTEMS_GXX}")
message(FATAL_ERROR "RTEMS g++ compiler not found at ${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-g++")
message(FATAL_ERROR
"RTEMS g++ compiler not found at "
"${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-g++"
)
endif()

message(STATUS "Checking for RTEMS assembler..")
set(RTEMS_ASM "${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-as")
if(NOT EXISTS "${RTEMS_GXX}")
message(FATAL_ERROR "RTEMS as compiler not found at ${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-as")
message(FATAL_ERROR
"RTEMS as compiler not found at "
"${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-as")
endif()

message(STATUS "Checking for RTEMS linker..")
set(RTEMS_LINKER "${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-ld")
if(NOT EXISTS "${RTEMS_LINKER}")
message(FATAL_ERROR "RTEMS ld linker not found at ${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-ld")
message(FATAL_ERROR
"RTEMS ld linker not found at "
"${RTEMS_BIN_PATH}/${RTEMS_ARCH_TOOLS}-ld")
endif()

message(STATUS "Checking done")
Expand All @@ -91,12 +176,15 @@ message(STATUS "Checking done")
# Info output
###########################################

message(STATUS "RTEMS Version: ${RTEMS_VERSION}")
message(STATUS "RTEMS installation path: ${RTEMS_INST}")
message(STATUS "RTEMS Architecture tools path: ${RTEMS_ARCH_TOOLS}")
message(STATUS "RTEMS BSP: ${RTEMS_BSP}")
message(STATUS "RTEMS BSP LIB path: ${RTEMS_BSP_LIB_PATH}")
message(STATUS "RTEMS BSP INC path: ${RTEMS_BSP_INC_PATH}")
message(STATUS "RTEMS version: ${RTEMS_VERSION}")
message(STATUS "RTEMS prefix: ${RTEMS_PREFIX}")
message(STATUS "RTEMS tools path: ${RTEMS_TOOLS}")
message(STATUS "RTEMS BSP pair: ${RTEMS_BSP}")
message(STATUS "RTEMS architecture tools path: "
"${RTEMS_PATH}/${RTEMS_ARCH_TOOLS}")
message(STATUS "RTEMS BSP library path: ${RTEMS_BSP_LIB_PATH}")
message(STATUS "RTEMS BSP include path: ${RTEMS_BSP_INC_PATH}")
message(STATUS "RTEMS install target: ${RTEMS_INSTALL}")

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

set(RTEMS_BSP_LIB_PATH ${RTEMS_BSP_LIB_PATH} PARENT_SCOPE)
set(RTEMS_BSP_INC_PATH ${RTEMS_BSP_INC_PATH} PARENT_SCOPE)
set(RTEMS_BSP_LIB_PATH ${RTEMS_BSP_LIB_PATH} CACHE FILEPATH "BSP library path")
set(RTEMS_BSP_INC_PATH ${RTEMS_BSP_INC_PATH} CACHE FILEPATH "BSP include path")
set(RTEMS_ARCH_LIB_PATH ${RTEMS_BSP_INC_PATH}
CACHE FILEPATH "Architecture library path"
)

endfunction()
Loading

0 comments on commit b96bcc1

Please sign in to comment.