2
2
# SPDX-License-Identifier: Apache-2.0
3
3
4
4
# This is the boilerplate for Mbed OS
5
+ project (MbedOS )
5
6
6
7
cmake_minimum_required (VERSION 3.19.0 FATAL_ERROR )
7
8
8
- include (${MBED_CONFIG_PATH} /mbed_config.cmake )
9
+ option (BUILD_TESTING "Run unit tests only." OFF )
10
+
11
+ if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME )
12
+ include (CTest )
13
+ endif ()
14
+
15
+ if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING )
16
+ add_subdirectory (UNITTESTS )
17
+ set (MBED_BUILD_UNITTESTS ON CACHE BOOL "" )
18
+ endif ()
19
+
20
+ if (${CMAKE_CROSSCOMPILING} )
21
+ include (${MBED_CONFIG_PATH} /mbed_config.cmake )
22
+ endif ()
23
+
9
24
include (tools/cmake/set_linker_script.cmake )
10
25
11
26
add_library (mbed-core INTERFACE )
@@ -26,80 +41,83 @@ target_link_libraries(mbed-baremetal
26
41
)
27
42
# Validate selected C library type
28
43
# The C library type selected has to match the library that the target can support
29
- if (${MBED_C_LIB} STREQUAL "small" )
30
- if (NOT "small" IN_LIST MBED_TARGET_SUPPORTED_C_LIBS )
31
- if ("std" IN_LIST MBED_TARGET_SUPPORTED_C_LIBS )
32
- message (WARNING
33
- "We noticed that target.c_lib is set to `${MBED_C_LIB} `."
34
- " As the ${MBED_TARGET} target does not support a small C library for the ${MBED_TOOLCHAIN} toolchain,"
35
- " we are using the standard C library instead."
36
- )
37
- set (MBED_C_LIB "std" CACHE STRING "" )
44
+ if (${CMAKE_CROSSCOMPILING} )
45
+ if (${MBED_C_LIB} STREQUAL "small" )
46
+ if (NOT "small" IN_LIST MBED_TARGET_SUPPORTED_C_LIBS )
47
+ if ("std" IN_LIST MBED_TARGET_SUPPORTED_C_LIBS )
48
+ message (WARNING
49
+ "We noticed that target.c_lib is set to `${MBED_C_LIB} `."
50
+ " As the ${MBED_TARGET} target does not support a small C library for the ${MBED_TOOLCHAIN} toolchain,"
51
+ " we are using the standard C library instead."
52
+ )
53
+ set (MBED_C_LIB "std" CACHE STRING "" )
54
+ endif ()
38
55
endif ()
56
+ elseif (NOT ${MBED_C_LIB} IN_LIST MBED_TARGET_SUPPORTED_C_LIBS )
57
+ message (FATAL_ERROR
58
+ "Invalid `target.c_lib` ('${MBED_C_LIB} ') for '${MBED_TARGET} ' target."
59
+ "\n Possible value(s): ${MBED_TARGET_SUPPORTED_C_LIBS} "
60
+ )
39
61
endif ()
40
- elseif (NOT ${MBED_C_LIB} IN_LIST MBED_TARGET_SUPPORTED_C_LIBS )
41
- message (FATAL_ERROR
42
- "Invalid `target.c_lib` ('${MBED_C_LIB} ') for '${MBED_TARGET} ' target."
43
- "\n Possible value(s): ${MBED_TARGET_SUPPORTED_C_LIBS} "
44
- )
45
- endif ()
46
-
47
- # Validate selected printf library
48
- set (MBED_PRINTF_LIB_TYPES std minimal-printf )
49
- if (NOT ${MBED_PRINTF_LIB} IN_LIST MBED_PRINTF_LIB_TYPES )
50
- message (FATAL_ERROR
51
- "Invalid printf library type '${MBED_PRINTF_LIB} '. Possible values:\n ${MBED_PRINTF_LIB_TYPES} "
52
- )
53
- endif ()
54
62
55
- mbed_set_cpu_core_definitions (mbed-core )
56
- if (${MBED_TOOLCHAIN_FILE_USED} )
57
- mbed_set_profile_options (mbed-core ${MBED_TOOLCHAIN} )
58
- mbed_set_c_lib (mbed-core ${MBED_C_LIB} )
59
- mbed_set_printf_lib (mbed-core ${MBED_PRINTF_LIB} )
60
-
61
- target_compile_features (mbed-core
62
- INTERFACE
63
- c_std_11
64
- cxx_std_14
65
- )
66
-
67
- endif ()
68
-
69
- target_compile_definitions (mbed-core
70
- INTERFACE
71
- ${MBED_TARGET_DEFINITIONS}
72
- ${MBED_CONFIG_DEFINITIONS}
73
- )
63
+ # Validate selected printf library
64
+ set (MBED_PRINTF_LIB_TYPES std minimal-printf )
65
+ if (NOT ${MBED_PRINTF_LIB} IN_LIST MBED_PRINTF_LIB_TYPES )
66
+ message (FATAL_ERROR
67
+ "Invalid printf library type '${MBED_PRINTF_LIB} '. Possible values:\n ${MBED_PRINTF_LIB_TYPES} "
68
+ )
69
+ endif ()
70
+
71
+ mbed_set_cpu_core_definitions (mbed-core )
72
+ if (${MBED_TOOLCHAIN_FILE_USED} )
73
+ message (STATUS ${MBED_TOOLCHAIN} )
74
+ mbed_set_profile_options (mbed-core ${MBED_TOOLCHAIN} )
75
+ mbed_set_c_lib (mbed-core ${MBED_C_LIB} )
76
+ mbed_set_printf_lib (mbed-core ${MBED_PRINTF_LIB} )
77
+
78
+ target_compile_features (mbed-core
79
+ INTERFACE
80
+ c_std_11
81
+ cxx_std_14
82
+ )
83
+
84
+ endif ()
74
85
75
- # We need to generate a "response file" to pass to the C preprocessor when we preprocess the linker
76
- # script, because of path length limitations on Windows. We set the response file and bind the path
77
- # to a global property here. The MBED_TARGET being built queries this global property when it sets
78
- # the linker script.
79
- #
80
- # We must set this global property before the targets subdirectory is added to the project. This is
81
- # required because the MBED_TARGET depends on the response file. If the path to the response file
82
- # is not defined when the target requests it the config definitions will not be passed to CPP.
83
- #
84
- # TODO: Remove this and find a more idiomatic way of passing compile definitions to CPP without
85
- # using response files or global properties.
86
- mbed_generate_options_for_linker (mbed-core RESPONSE_FILE_PATH )
87
- set_property (GLOBAL PROPERTY COMPILE_DEFS_RESPONSE_FILE ${RESPONSE_FILE_PATH} )
88
-
89
- # Add compile definitions for backward compatibility with the toolchain
90
- # supported. New source files should instead check for __GNUC__ and __clang__
91
- # for the GCC_ARM and ARM toolchains respectively.
92
- if (${MBED_TOOLCHAIN} STREQUAL "GCC_ARM" )
93
86
target_compile_definitions (mbed-core
94
87
INTERFACE
95
- TOOLCHAIN_GCC_ARM
96
- TOOLCHAIN_GCC
97
- )
98
- elseif (${MBED_TOOLCHAIN} STREQUAL "ARM" )
99
- target_compile_definitions (mbed-core
100
- INTERFACE
101
- TOOLCHAIN_ARM
88
+ ${MBED_TARGET_DEFINITIONS}
89
+ ${MBED_CONFIG_DEFINITIONS}
102
90
)
91
+
92
+ # We need to generate a "response file" to pass to the C preprocessor when we preprocess the linker
93
+ # script, because of path length limitations on Windows. We set the response file and bind the path
94
+ # to a global property here. The MBED_TARGET being built queries this global property when it sets
95
+ # the linker script.
96
+ #
97
+ # We must set this global property before the targets subdirectory is added to the project. This is
98
+ # required because the MBED_TARGET depends on the response file. If the path to the response file
99
+ # is not defined when the target requests it the config definitions will not be passed to CPP.
100
+ #
101
+ # TODO: Remove this and find a more idiomatic way of passing compile definitions to CPP without
102
+ # using response files or global properties.
103
+ mbed_generate_options_for_linker (mbed-core RESPONSE_FILE_PATH )
104
+ set_property (GLOBAL PROPERTY COMPILE_DEFS_RESPONSE_FILE ${RESPONSE_FILE_PATH} )
105
+
106
+ # Add compile definitions for backward compatibility with the toolchain
107
+ # supported. New source files should instead check for __GNUC__ and __clang__
108
+ # for the GCC_ARM and ARM toolchains respectively.
109
+ if (${MBED_TOOLCHAIN} STREQUAL "GCC_ARM" )
110
+ target_compile_definitions (mbed-core
111
+ INTERFACE
112
+ TOOLCHAIN_GCC_ARM
113
+ TOOLCHAIN_GCC
114
+ )
115
+ elseif (${MBED_TOOLCHAIN} STREQUAL "ARM" )
116
+ target_compile_definitions (mbed-core
117
+ INTERFACE
118
+ TOOLCHAIN_ARM
119
+ )
120
+ endif ()
103
121
endif ()
104
122
105
123
# Include mbed.h and config from generate folder
@@ -122,22 +140,33 @@ add_subdirectory(platform)
122
140
add_subdirectory (rtos )
123
141
add_subdirectory (targets )
124
142
143
+ if (${MBED_BUILD_UNITTESTS} )
144
+ add_subdirectory (connectivity )
145
+ add_subdirectory (storage )
146
+ add_subdirectory (events )
147
+ else ()
148
+ # The directories below contain optional target libraries
149
+ add_subdirectory (connectivity EXCLUDE_FROM_ALL )
150
+ add_subdirectory (storage EXCLUDE_FROM_ALL )
151
+ add_subdirectory (events EXCLUDE_FROM_ALL )
152
+ endif ()
153
+
125
154
# The directories below contain optional target libraries
126
- add_subdirectory (events EXCLUDE_FROM_ALL )
127
- add_subdirectory (connectivity EXCLUDE_FROM_ALL )
128
- add_subdirectory (storage EXCLUDE_FROM_ALL )
129
155
add_subdirectory (drivers/device_key EXCLUDE_FROM_ALL )
130
156
add_subdirectory (drivers/usb EXCLUDE_FROM_ALL )
131
157
add_subdirectory (features EXCLUDE_FROM_ALL )
132
158
add_subdirectory (cmsis/CMSIS_5/CMSIS/RTOS2 EXCLUDE_FROM_ALL )
133
159
add_subdirectory (cmsis/device/rtos EXCLUDE_FROM_ALL )
134
160
135
- # Ensure the words that make up the Mbed target name are separated with a hyphen, lowercase, and with the `mbed-` prefix.
136
- string (TOLOWER ${MBED_TARGET} MBED_TARGET_CONVERTED )
137
- string (REPLACE "_" "-" MBED_TARGET_CONVERTED ${MBED_TARGET_CONVERTED} )
138
- string (PREPEND MBED_TARGET_CONVERTED "mbed-" )
139
161
140
- target_link_libraries (mbed-core INTERFACE ${MBED_TARGET_CONVERTED} )
162
+ if (${CMAKE_CROSSCOMPILING} )
163
+ # Ensure the words that make up the Mbed target name are separated with a hyphen, lowercase, and with the `mbed-` prefix.
164
+ string (TOLOWER ${MBED_TARGET} MBED_TARGET_CONVERTED )
165
+ string (REPLACE "_" "-" MBED_TARGET_CONVERTED ${MBED_TARGET_CONVERTED} )
166
+ string (PREPEND MBED_TARGET_CONVERTED "mbed-" )
167
+
168
+ target_link_libraries (mbed-core INTERFACE ${MBED_TARGET_CONVERTED} )
169
+ endif ()
141
170
142
171
#
143
172
# Converts output file of `target` to binary file and to Intel HEX file.
0 commit comments