Skip to content

Commit 2f67435

Browse files
committed
Fix #432, Infer OSAL_SYSTEM_OSTYPE from OSAL_SYSTEM_BSPTYPE
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.
1 parent c4632ba commit 2f67435

File tree

4 files changed

+56
-23
lines changed

4 files changed

+56
-23
lines changed

CMakeLists.txt

+44-22
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,6 @@
4848
cmake_minimum_required(VERSION 2.8.12)
4949
project(OSAL C)
5050

51-
# OSAL_SYSTEM_OSTYPE and OSAL_SYSTEM_BSPTYPE indicate which of the OS packages
52-
# to build. These are required and must be defined. Confirm that this exists
53-
# and error out now if it does not.
54-
if (NOT DEFINED OSAL_SYSTEM_OSTYPE OR
55-
NOT IS_DIRECTORY "${OSAL_SOURCE_DIR}/src/os/${OSAL_SYSTEM_OSTYPE}")
56-
# It is an error if the indicated OSTYPE does not correspond to a subdirectory
57-
# If this is not caught here then a more obfuscated error will occur later.
58-
message("Error: \"${OSAL_SYSTEM_OSTYPE}\" is not a valid OS type")
59-
message(FATAL_ERROR "OSAL_SYSTEM_OSTYPE must be set to the appropriate OS")
60-
endif ()
61-
if (NOT DEFINED OSAL_SYSTEM_BSPTYPE OR
62-
NOT IS_DIRECTORY "${OSAL_SOURCE_DIR}/src/bsp/${OSAL_SYSTEM_BSPTYPE}")
63-
# It is an error if the indicated BSPTYPE does not correspond to a subdirectory
64-
# If this is not caught here then a more obfuscated error will occur later.
65-
message("Error: \"${OSAL_SYSTEM_BSPTYPE}\" is not a valid BSP type")
66-
message(FATAL_ERROR "OSAL_SYSTEM_BSPTYPE must be set to the appropriate BSP")
67-
endif ()
68-
6951
# Read the default compile-time configuration, and update with
7052
# any mission/project specific options in the OSAL_CONFIGURATION_FILE
7153
include("${OSAL_SOURCE_DIR}/default_config.cmake")
@@ -94,9 +76,6 @@ execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
9476
"${CMAKE_BINARY_DIR}/inc/osconfig.h"
9577
)
9678

97-
message(STATUS "OSAL Selection: ${OSAL_SYSTEM_OSTYPE}")
98-
message(STATUS "BSP Selection: ${OSAL_SYSTEM_BSPTYPE}")
99-
10079
# The initial set of directories that define the OSAL API
10180
# This is used to initialize the interface include directory property of external targets
10281
set(OSAL_API_INCLUDE_DIRECTORIES
@@ -116,11 +95,26 @@ add_definitions(${OSAL_USER_C_FLAGS})
11695
# This is done early, so that other targets may reference UT_ASSERT_SOURCE_DIR if needed
11796
add_subdirectory(ut_assert)
11897

119-
12098
#
12199
# Step 1:
122100
# Build the BSP layer
123101
#
102+
103+
104+
# OSAL_SYSTEM_BSPTYPE indicate which of the BSP packages
105+
# to build. These is required and must be defined. Confirm that this exists
106+
# and error out now if it does not.
107+
if (NOT DEFINED OSAL_SYSTEM_BSPTYPE OR
108+
NOT IS_DIRECTORY "${OSAL_SOURCE_DIR}/src/bsp/${OSAL_SYSTEM_BSPTYPE}")
109+
# It is an error if the indicated BSPTYPE does not correspond to a subdirectory
110+
# If this is not caught here then a more obfuscated error will occur later.
111+
message("Error: \"${OSAL_SYSTEM_BSPTYPE}\" is not a valid BSP type")
112+
message(FATAL_ERROR "OSAL_SYSTEM_BSPTYPE must be set to the appropriate BSP")
113+
endif ()
114+
115+
message(STATUS "BSP Selection: ${OSAL_SYSTEM_BSPTYPE}")
116+
117+
124118
# The BSP library is a separate target from OSAL and can be used
125119
# independently of the OSAL library and/or in combination with
126120
# UT assert and the OSAL stub library for unit testing.
@@ -132,6 +126,19 @@ target_include_directories(osal_${OSAL_SYSTEM_BSPTYPE}_impl PRIVATE
132126
${OSAL_SOURCE_DIR}/src/bsp/shared/inc
133127
)
134128

129+
# Confirm that the selected OS is compatible with the selected BSP.
130+
if (DEFINED OSAL_EXPECTED_OSTYPE)
131+
if (NOT DEFINED OSAL_SYSTEM_OSTYPE)
132+
# In the event that OSAL_SYSTEM_OSTYPE was not specified at all,
133+
# implicitly assume the expected OSTYPE.
134+
set(OSAL_SYSTEM_OSTYPE ${OSAL_EXPECTED_OSTYPE})
135+
elseif(NOT OSAL_SYSTEM_OSTYPE STREQUAL OSAL_EXPECTED_OSTYPE)
136+
# Generate a warning about the OSTYPE not being expected.
137+
# Not calling this a fatal error because it could possibly be intended during development
138+
message(WARNING "Mismatched BSP/OS: ${OSAL_SYSTEM_BSPTYPE} implies ${OSAL_EXPECTED_OSTYPE}, but ${OSAL_SYSTEM_OSTYPE} is configured")
139+
endif(NOT DEFINED OSAL_SYSTEM_OSTYPE)
140+
endif (DEFINED OSAL_EXPECTED_OSTYPE)
141+
135142
# Propagate the BSP-specific compile definitions and include directories
136143
# Apply these to the directory-scope COMPILE_DEFINITIONS and INCLUDE_DIRECTORIES
137144
# Note this needs to append to the directory property, not overwrite it.
@@ -172,10 +179,25 @@ target_include_directories(osal_bsp PRIVATE
172179
${OSAL_SOURCE_DIR}/src/bsp/shared/inc
173180
)
174181

182+
175183
#
176184
# Step 2:
177185
# Build the OSAL layer
178186
#
187+
188+
# OSAL_SYSTEM_OSTYPE and OSAL_SYSTEM_BSPTYPE indicate which of the OS packages
189+
# to build. These are required and must be defined. Confirm that this exists
190+
# and error out now if it does not.
191+
if (NOT DEFINED OSAL_SYSTEM_OSTYPE OR
192+
NOT IS_DIRECTORY "${OSAL_SOURCE_DIR}/src/os/${OSAL_SYSTEM_OSTYPE}")
193+
# It is an error if the indicated OSTYPE does not correspond to a subdirectory
194+
# If this is not caught here then a more obfuscated error will occur later.
195+
message("Error: \"${OSAL_SYSTEM_OSTYPE}\" is not a valid OS type")
196+
message(FATAL_ERROR "OSAL_SYSTEM_OSTYPE must be set to the appropriate OS")
197+
endif ()
198+
199+
message(STATUS "OSAL Selection: ${OSAL_SYSTEM_OSTYPE}")
200+
179201
# The implementation-specific OSAL subdirectory should define
180202
# an OBJECT target named "osal_${OSAL_SYSTEM_OSTYPE}_impl"
181203
add_subdirectory(src/os/${OSAL_SYSTEM_OSTYPE} ${OSAL_SYSTEM_OSTYPE}_impl)

src/bsp/mcp750-vxworks/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ target_compile_definitions(osal_mcp750-vxworks_impl PUBLIC
2323
"MCP750"
2424
)
2525

26-
26+
# This BSP only works with "vxworks" OS layer.
27+
# Confirming this reduces risk of accidental misconfiguration
28+
set(OSAL_EXPECTED_OSTYPE "vxworks" PARENT_SCOPE)

src/bsp/pc-linux/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@ add_library(osal_pc-linux_impl OBJECT
2727
target_compile_definitions(osal_pc-linux_impl PUBLIC
2828
_XOPEN_SOURCE=600
2929
)
30+
31+
32+
# This BSP only works with "posix" OS layer.
33+
# Confirming this reduces risk of accidental misconfiguration
34+
set(OSAL_EXPECTED_OSTYPE "posix" PARENT_SCOPE)

src/bsp/pc-rtems/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ add_library(osal_pc-rtems_impl OBJECT
99
src/bsp_voltab.c
1010
src/bsp_console.c
1111
)
12+
13+
# This BSP only works with "rtems" OS layer.
14+
# Confirming this reduces risk of accidental misconfiguration
15+
set(OSAL_EXPECTED_OSTYPE "rtems" PARENT_SCOPE)

0 commit comments

Comments
 (0)