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