Skip to content

Commit

Permalink
Fix #432, Infer OSAL_SYSTEM_OSTYPE from OSAL_SYSTEM_BSPTYPE
Browse files Browse the repository at this point in the history
The OSAL_SYSTEM_BSPTYPE specification by itself is enough to
build OSAL, as it implies a specific OS layer.

However, if OSAL_SYSTEM_OSTYPE is explicitly specified, it is used,
but will generate a warning if it is different than the OS layer
implied by the BSP, as there could be reasons for doing this
during development.
  • Loading branch information
jphickey committed Apr 21, 2020
1 parent 12946f9 commit 88690d7
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 23 deletions.
66 changes: 44 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,6 @@
cmake_minimum_required(VERSION 2.8.12)
project(OSAL C)

# OSAL_SYSTEM_OSTYPE and OSAL_SYSTEM_BSPTYPE indicate which of the OS packages
# to build. These are required and must be defined. Confirm that this exists
# and error out now if it does not.
if (NOT DEFINED OSAL_SYSTEM_OSTYPE OR
NOT IS_DIRECTORY "${OSAL_SOURCE_DIR}/src/os/${OSAL_SYSTEM_OSTYPE}")
# It is an error if the indicated OSTYPE does not correspond to a subdirectory
# If this is not caught here then a more obfuscated error will occur later.
message("Error: \"${OSAL_SYSTEM_OSTYPE}\" is not a valid OS type")
message(FATAL_ERROR "OSAL_SYSTEM_OSTYPE must be set to the appropriate OS")
endif ()
if (NOT DEFINED OSAL_SYSTEM_BSPTYPE OR
NOT IS_DIRECTORY "${OSAL_SOURCE_DIR}/src/bsp/${OSAL_SYSTEM_BSPTYPE}")
# It is an error if the indicated BSPTYPE does not correspond to a subdirectory
# If this is not caught here then a more obfuscated error will occur later.
message("Error: \"${OSAL_SYSTEM_BSPTYPE}\" is not a valid BSP type")
message(FATAL_ERROR "OSAL_SYSTEM_BSPTYPE must be set to the appropriate BSP")
endif ()

# Read the default compile-time configuration, and update with
# any mission/project specific options in the OSAL_CONFIGURATION_FILE
include("${OSAL_SOURCE_DIR}/default_config.cmake")
Expand Down Expand Up @@ -94,9 +76,6 @@ execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_BINARY_DIR}/inc/osconfig.h"
)

message(STATUS "OSAL Selection: ${OSAL_SYSTEM_OSTYPE}")
message(STATUS "BSP Selection: ${OSAL_SYSTEM_BSPTYPE}")

# The initial set of directories that define the OSAL API
# This is used to initialize the interface include directory property of external targets
set(OSAL_API_INCLUDE_DIRECTORIES
Expand All @@ -116,11 +95,26 @@ add_definitions(${OSAL_USER_C_FLAGS})
# This is done early, so that other targets may reference UT_ASSERT_SOURCE_DIR if needed
add_subdirectory(ut_assert)


#
# Step 1:
# Build the BSP layer
#


# OSAL_SYSTEM_BSPTYPE indicate which of the BSP packages
# to build. These is required and must be defined. Confirm that this exists
# and error out now if it does not.
if (NOT DEFINED OSAL_SYSTEM_BSPTYPE OR
NOT IS_DIRECTORY "${OSAL_SOURCE_DIR}/src/bsp/${OSAL_SYSTEM_BSPTYPE}")
# It is an error if the indicated BSPTYPE does not correspond to a subdirectory
# If this is not caught here then a more obfuscated error will occur later.
message("Error: \"${OSAL_SYSTEM_BSPTYPE}\" is not a valid BSP type")
message(FATAL_ERROR "OSAL_SYSTEM_BSPTYPE must be set to the appropriate BSP")
endif ()

message(STATUS "BSP Selection: ${OSAL_SYSTEM_BSPTYPE}")


# The BSP library is a separate target from OSAL and can be used
# independently of the OSAL library and/or in combination with
# UT assert and the OSAL stub library for unit testing.
Expand All @@ -132,6 +126,19 @@ target_include_directories(osal_${OSAL_SYSTEM_BSPTYPE}_impl PRIVATE
${OSAL_SOURCE_DIR}/src/bsp/shared/inc
)

# Confirm that the selected OS is compatible with the selected BSP.
if (DEFINED OSAL_EXPECTED_OSTYPE)
if (NOT DEFINED OSAL_SYSTEM_OSTYPE)
# In the event that OSAL_SYSTEM_OSTYPE was not specified at all,
# implicitly assume the expected OSTYPE.
set(OSAL_SYSTEM_OSTYPE ${OSAL_EXPECTED_OSTYPE})
elseif(NOT OSAL_SYSTEM_OSTYPE STREQUAL OSAL_EXPECTED_OSTYPE)
# Generate a warning about the OSTYPE not being expected.
# Not calling this a fatal error because it could possibly be intended during development
message(WARNING "Mismatched BSP/OS: ${OSAL_SYSTEM_BSPTYPE} implies ${OSAL_EXPECTED_OSTYPE}, but ${OSAL_SYSTEM_OSTYPE} is configured")
endif(NOT DEFINED OSAL_SYSTEM_OSTYPE)
endif (DEFINED OSAL_EXPECTED_OSTYPE)

# Propagate the BSP-specific compile definitions and include directories
# Apply these to the directory-scope COMPILE_DEFINITIONS and INCLUDE_DIRECTORIES
# Note this needs to append to the directory property, not overwrite it.
Expand Down Expand Up @@ -172,10 +179,25 @@ target_include_directories(osal_bsp PRIVATE
${OSAL_SOURCE_DIR}/src/bsp/shared/inc
)


#
# Step 2:
# Build the OSAL layer
#

# OSAL_SYSTEM_OSTYPE and OSAL_SYSTEM_BSPTYPE indicate which of the OS packages
# to build. These are required and must be defined. Confirm that this exists
# and error out now if it does not.
if (NOT DEFINED OSAL_SYSTEM_OSTYPE OR
NOT IS_DIRECTORY "${OSAL_SOURCE_DIR}/src/os/${OSAL_SYSTEM_OSTYPE}")
# It is an error if the indicated OSTYPE does not correspond to a subdirectory
# If this is not caught here then a more obfuscated error will occur later.
message("Error: \"${OSAL_SYSTEM_OSTYPE}\" is not a valid OS type")
message(FATAL_ERROR "OSAL_SYSTEM_OSTYPE must be set to the appropriate OS")
endif ()

message(STATUS "OSAL Selection: ${OSAL_SYSTEM_OSTYPE}")

# The implementation-specific OSAL subdirectory should define
# an OBJECT target named "osal_${OSAL_SYSTEM_OSTYPE}_impl"
add_subdirectory(src/os/${OSAL_SYSTEM_OSTYPE} ${OSAL_SYSTEM_OSTYPE}_impl)
Expand Down
4 changes: 3 additions & 1 deletion src/bsp/mcp750-vxworks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ target_compile_definitions(osal_mcp750-vxworks_impl PUBLIC
"MCP750"
)


# This BSP only works with "vxworks" OS layer.
# Confirming this reduces risk of accidental misconfiguration
set(OSAL_EXPECTED_OSTYPE "vxworks" PARENT_SCOPE)
5 changes: 5 additions & 0 deletions src/bsp/pc-linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ add_library(osal_pc-linux_impl OBJECT
target_compile_definitions(osal_pc-linux_impl PUBLIC
_XOPEN_SOURCE=600
)


# This BSP only works with "posix" OS layer.
# Confirming this reduces risk of accidental misconfiguration
set(OSAL_EXPECTED_OSTYPE "posix" PARENT_SCOPE)
4 changes: 4 additions & 0 deletions src/bsp/pc-rtems/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ add_library(osal_pc-rtems_impl OBJECT
src/bsp_voltab.c
src/bsp_console.c
)

# This BSP only works with "rtems" OS layer.
# Confirming this reduces risk of accidental misconfiguration
set(OSAL_EXPECTED_OSTYPE "rtems" PARENT_SCOPE)

0 comments on commit 88690d7

Please sign in to comment.