Skip to content

Commit

Permalink
Merge pull request #436 from jphickey/fix-432-infer-ostype-from-bsp
Browse files Browse the repository at this point in the history
Fix #432, Infer OSAL_SYSTEM_OSTYPE from OSAL_SYSTEM_BSPTYPE
  • Loading branch information
astrogeco authored Apr 24, 2020
2 parents 9ffab35 + 1adaf6b commit ea042c9
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 22 deletions.
63 changes: 42 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +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 ()

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
Expand All @@ -89,11 +69,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 @@ -105,6 +100,19 @@ target_include_directories(osal_${OSAL_SYSTEM_BSPTYPE}_impl PRIVATE
${OSAL_SOURCE_DIR}/src/bsp/shared
)

# 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 @@ -145,6 +153,19 @@ target_include_directories(osal_bsp INTERFACE
# Step 2:
# Build the OSAL layer
#

# OSAL_SYSTEM_OSTYPE indicates which of the OS packages
# to build. If not defined, this may be inferred by the BSP type.
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 ea042c9

Please sign in to comment.