-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
297 lines (253 loc) · 11.9 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
######################################################################
#
# CMAKE build recipe for Operating System Abstraction Layer (OSAL)
#
######################################################################
#
# This defines the following static library target(s):
#
# osal : The main library containing the OSAL binary code
# This is based off the OSAL_SYSTEM_OSTYPE selection
#
# osal_bsp : The board support library containing the system-
# specific entry point function (e.g. main) and the
# file system volume table for the target board.
# This is based off the OSAL_SYSTEM_BSPTYPE selection
#
# ut_assert : The unit test support library. This implements
# an application entry point (OS_Application_Startup)
# that contains a unit test subsystem. This uses
# the OSAL BSP to provide system-specific entry point.
# Linking with this library also links with osal_bsp,
# but not necessarily the osal library itself.
#
# Additionally the following target is defined if ENABLE_UNIT_TESTS
# is set TRUE:
#
# ut_osapi_stubs : Stub library correlating to the OSAL public API
# This is for unit testing OSAL-based applications
# It operates in conjunction with the ut_assert library.
#
# This also exports the following variables:
#
# OSAL_BSP_STAGING_INSTALL_DIR : the location of the staging directory
# for the selected OSAL BSP. This can be used in
# post-build rules or "install()" commands to stage
# binary or data files for execution.
#
# UT_COVERAGE_COMPILE_FLAGS : Compiler flags that must be used to
# instrument code for coverage testing
# UT_COVERAGE_LINK_FLAGS : Linker flags that must be used to
# instrument code for coverage testing
#
# The ENABLE_UNIT_TESTS option also builds a set of test applications from
# that demonstrate the usage and validate the runtime behavior of various
# OSAL resources.
#
######################################################################
cmake_minimum_required(VERSION 2.8.12)
project(OSAL C)
# 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
"${OSAL_SOURCE_DIR}/src/os/inc"
"${CMAKE_BINARY_DIR}/inc"
${OSAL_INCLUDEDIR}
)
include_directories(${OSAL_API_INCLUDE_DIRECTORIES})
# In case the OSAL_USER_C_FLAGS was specified, use them
add_definitions(${OSAL_USER_C_FLAGS})
#
# Build UT assert -
# the basic ut_assert library target is always defined regardless of "ENABLE_UNIT_TESTS",
# but flagged using "EXCLUDE_FROM_ALL" so they won't be built unless actually used. This
# is because the library is usable with functional tests, not just unit (coverage) tests.
# 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.
#
# The Implementation-Specific BSP subdirectory should define
# an OBJECT target named "osal_${OSAL_SYSTEM_BSPTYPE}_impl"
add_subdirectory(src/bsp/${OSAL_SYSTEM_BSPTYPE} ${OSAL_SYSTEM_BSPTYPE}_impl)
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.
get_directory_property(OSAL_BASE_COMPILE_DEFINITIONS COMPILE_DEFINITIONS)
get_target_property(OSAL_BSP_COMPILE_DEFINITIONS osal_${OSAL_SYSTEM_BSPTYPE}_impl INTERFACE_COMPILE_DEFINITIONS)
set(OSAL_COMPILE_DEFINITIONS)
if (OSAL_BASE_COMPILE_DEFINITIONS)
list(APPEND OSAL_COMPILE_DEFINITIONS ${OSAL_BASE_COMPILE_DEFINITIONS})
endif (OSAL_BASE_COMPILE_DEFINITIONS)
if (OSAL_BSP_COMPILE_DEFINITIONS)
list(APPEND OSAL_COMPILE_DEFINITIONS ${OSAL_BSP_COMPILE_DEFINITIONS})
endif (OSAL_BSP_COMPILE_DEFINITIONS)
set_directory_properties(PROPERTIES COMPILE_DEFINITIONS "${OSAL_COMPILE_DEFINITIONS}")
message(STATUS "OSAL Compile Definitions: ${OSAL_COMPILE_DEFINITIONS}")
# The include directories is simpler, as the include_directories() function
# appends to the directory property
get_target_property(OSAL_BSP_INCLUDE_DIRECTORIES osal_${OSAL_SYSTEM_BSPTYPE}_impl INTERFACE_INCLUDE_DIRECTORIES)
if (OSAL_BSP_INCLUDE_DIRECTORIES)
include_directories(${OSAL_BSP_INCLUDE_DIRECTORIES})
endif (OSAL_BSP_INCLUDE_DIRECTORIES)
# Define the external "osal_bsp" static library target
add_library(osal_bsp STATIC
src/bsp/shared/osapi-bsp.c
src/bsp/shared/bsp_default_app_run.c
src/bsp/shared/bsp_default_app_startup.c
src/bsp/shared/bsp_default_symtab.c
$<TARGET_OBJECTS:osal_${OSAL_SYSTEM_BSPTYPE}_impl>
)
target_include_directories(osal_bsp INTERFACE
${OSAL_API_INCLUDE_DIRECTORIES}
)
#
# 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)
# The "shared" directory contains internal components which
# are referenced in implementation OSAL modules, but should _NOT_
# be referenced outside the OSAL code
target_include_directories(osal_${OSAL_SYSTEM_OSTYPE}_impl PRIVATE
${OSAL_SOURCE_DIR}/src/os/shared
${OSAL_SOURCE_DIR}/src/bsp/shared
)
# Define the external "osal" static library target
# This is a combination of the generic parts with the low level
# system-specific parts
add_library(osal STATIC
src/os/shared/osapi-binsem.c
src/os/shared/osapi-clock.c
src/os/shared/osapi-common.c
src/os/shared/osapi-countsem.c
src/os/shared/osapi-dir.c
src/os/shared/osapi-errors.c
src/os/shared/osapi-file.c
src/os/shared/osapi-filesys.c
src/os/shared/osapi-fpu.c
src/os/shared/osapi-heap.c
src/os/shared/osapi-idmap.c
src/os/shared/osapi-interrupts.c
src/os/shared/osapi-module.c
src/os/shared/osapi-mutex.c
src/os/shared/osapi-network.c
src/os/shared/osapi-printf.c
src/os/shared/osapi-queue.c
src/os/shared/osapi-select.c
src/os/shared/osapi-sockets.c
src/os/shared/osapi-task.c
src/os/shared/osapi-timebase.c
src/os/shared/osapi-time.c
$<TARGET_OBJECTS:osal_${OSAL_SYSTEM_OSTYPE}_impl>
)
target_include_directories(osal INTERFACE
${OSAL_API_INCLUDE_DIRECTORIES}
)
# Link the OSAL with the BSP
target_link_libraries(osal osal_bsp)
# propagate the BSP-specific compile flags to OSAL external library target, if defined
if (OSAL_BSP_COMPILE_DEFINITIONS)
target_compile_definitions(osal INTERFACE
${OSAL_BSP_COMPILE_DEFINITIONS}
)
endif(OSAL_BSP_COMPILE_DEFINITIONS)
# propagate the BSP-specific include directories OSAL all external library target, if defined
if (OSAL_BSP_INCLUDE_DIRECTORIES)
target_include_directories(osal INTERFACE
${OSAL_BSP_INCLUDE_DIRECTORIES}
)
endif(OSAL_BSP_INCLUDE_DIRECTORIES)
# The "build_options.cmake" file within each component may
# fine-tune the library for this particular build. This is included
# AFTER The basic targets are defined, so it may set properties
# on the defined targets and/or use target-specific commands.
include("${OSAL_SOURCE_DIR}/src/bsp/${OSAL_SYSTEM_BSPTYPE}/build_options.cmake" OPTIONAL)
include("${OSAL_SOURCE_DIR}/src/os/${OSAL_SYSTEM_OSTYPE}/build_options.cmake" OPTIONAL)
#
# UNIT TEST SUPPORT
#
if (ENABLE_UNIT_TESTS)
enable_testing()
# Generic function for consistent definition of a unit testing target
# This is defined here in the top-level OSAL CMakeLists so it can be used
# in both the "tests" and "unit-tests" subdirectories.
function(add_osal_ut_exe TGTNAME)
add_executable(${TGTNAME} ${ARGN})
target_link_libraries(${TGTNAME} ut_assert osal)
add_test(${TGTNAME} ${TGTNAME})
foreach(TGT ${INSTALL_TARGET_LIST})
install(TARGETS ${TGTNAME} DESTINATION ${TGT}/${UT_INSTALL_SUBDIR})
endforeach()
endfunction(add_osal_ut_exe)
# The "ut_osapi_stubs" library contains "stub" functions of the OSAL API calls, used for
# testing other application code built on top of OSAL.
add_subdirectory(src/ut-stubs ut-stubs)
# The "unit-test-coverage" is a white-box line coverage test.
# It re-compiles each source unit for coverage analysis and links
# with stub dependencies and a test sequence designed to execute
# every line of source code within OSAL.
add_subdirectory(src/unit-test-coverage unit-test-coverage)
# The "tests" and "unit-tests" subdirectories implement examples and verification tests
# of the OSAL library. Note that these are both black box tests that link with the full
# OSAL (not a stub/coverage test).
add_subdirectory(src/tests tests)
add_subdirectory(src/unit-tests unit-tests)
endif (ENABLE_UNIT_TESTS)
# If this build is being performed as a subdirectory within a larger project,
# then export the important data regarding compile flags/dirs to that parent
# This is conditional to avoid warnings in a standalone build.
get_directory_property(HAS_PARENT PARENT_DIRECTORY)
if (HAS_PARENT)
# export the "OSAL_BSP_STAGING_INSTALL_DIR" to the parent build, so this can be
# used in "install" commands as necessary for the files needed at runtime
set(OSAL_BSP_STAGING_INSTALL_DIR "${OSAL_BSP_STAGING_INSTALL_DIR}" PARENT_SCOPE)
# Export the UT coverage compiler/linker flags to the parent build.
# These flags are based on the target system type and should be used
# when building code intended for coverage analysis.
set(UT_COVERAGE_COMPILE_FLAGS "${UT_COVERAGE_COMPILE_FLAGS}" PARENT_SCOPE)
set(UT_COVERAGE_LINK_FLAGS "${UT_COVERAGE_LINK_FLAGS}" PARENT_SCOPE)
endif(HAS_PARENT)