@@ -144,12 +144,16 @@ target_include_directories(mbed-core
144
144
add_library (mbed-device_key INTERFACE )
145
145
add_library (mbed-rtos INTERFACE )
146
146
147
+ # Include targets/ first, because any post-build hook needs to be defined
148
+ # before other parts of Mbed OS can add greentea tests which require
149
+ # mbed_set_post_build().
150
+ add_subdirectory (targets )
151
+
147
152
add_subdirectory (cmsis )
148
153
add_subdirectory (drivers )
149
154
add_subdirectory (hal )
150
155
add_subdirectory (platform )
151
156
add_subdirectory (rtos )
152
- add_subdirectory (targets )
153
157
add_subdirectory (storage )
154
158
add_subdirectory (events )
155
159
add_subdirectory (connectivity )
@@ -171,122 +175,6 @@ if(${CMAKE_CROSSCOMPILING})
171
175
target_link_libraries (mbed-core INTERFACE ${MBED_TARGET_CONVERTED} )
172
176
endif ()
173
177
174
- #
175
- # Converts output file of `target` to binary file and to Intel HEX file.
176
- #
177
- function (mbed_generate_bin_hex target )
178
- get_property (elf_to_bin GLOBAL PROPERTY ELF2BIN )
179
- if (MBED_TOOLCHAIN STREQUAL "GCC_ARM" )
180
- # The first condition is quoted in case MBED_OUTPUT_EXT is unset
181
- if ("${MBED_OUTPUT_EXT} " STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "bin" )
182
- list (APPEND CMAKE_POST_BUILD_COMMAND
183
- COMMAND ${elf_to_bin} -O binary $< TARGET_FILE:${target} > ${CMAKE_CURRENT_BINARY_DIR} /${target}.bin
184
- COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR} /${target} .bin"
185
- )
186
- endif ()
187
- if ("${MBED_OUTPUT_EXT} " STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "hex" )
188
- list (APPEND CMAKE_POST_BUILD_COMMAND
189
- COMMAND ${elf_to_bin} -O ihex $< TARGET_FILE:${target} > ${CMAKE_CURRENT_BINARY_DIR} /${target}.hex
190
- COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR} /${target} .hex"
191
- )
192
- endif ()
193
- elseif (MBED_TOOLCHAIN STREQUAL "ARM" )
194
- get_property (mbed_studio_arm_compiler GLOBAL PROPERTY MBED_STUDIO_ARM_COMPILER )
195
- if ("${MBED_OUTPUT_EXT} " STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "bin" )
196
- list (APPEND CMAKE_POST_BUILD_COMMAND
197
- COMMAND ${elf_to_bin} ${mbed_studio_arm_compiler} --bin -o ${CMAKE_CURRENT_BINARY_DIR} /${target}.bin $< TARGET_FILE:${target} >
198
- COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR} /${target} .bin"
199
- )
200
- endif ()
201
- if ("${MBED_OUTPUT_EXT} " STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "hex" )
202
- list (APPEND CMAKE_POST_BUILD_COMMAND
203
- COMMAND ${elf_to_bin} ${mbed_studio_arm_compiler} --i32combined -o ${CMAKE_CURRENT_BINARY_DIR} /${target}.hex $< TARGET_FILE:${target} >
204
- COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR} /${target} .hex"
205
- )
206
- endif ()
207
- endif ()
208
- add_custom_command (
209
- TARGET
210
- ${target}
211
- POST_BUILD
212
- ${CMAKE_POST_BUILD_COMMAND}
213
- COMMENT
214
- "executable:"
215
- VERBATIM
216
- )
217
-
218
- if (TARGET mbed-post-build-bin-${MBED_TARGET} )
219
- # Remove the .elf file to force regenerate the application binaries
220
- # (including .bin and .hex). This ensures that the post-build script runs
221
- # on a raw application instead of a previous build that already went
222
- # through the post-build process once.
223
- file (REMOVE ${CMAKE_CURRENT_BINARY_DIR} /${target}.elf )
224
-
225
- # Pass the application's name to the Mbed target's post build operation
226
- set_target_properties (mbed-post-build-bin-${MBED_TARGET}
227
- PROPERTIES
228
- application ${target}
229
- )
230
-
231
- # The artefacts must be created before they can be further manipulated
232
- add_dependencies (mbed-post-build-bin-${MBED_TARGET} ${target} )
233
-
234
- # Add a post-build hook to the top-level CMake target in the form of a
235
- # CMake custom target. The hook depends on Mbed target specific
236
- # post-build CMake target which has a custom command attached to it.
237
- add_custom_target (mbed-post-build ALL DEPENDS mbed-post-build-bin-${MBED_TARGET} )
238
- endif ()
239
- endfunction ()
240
-
241
- #
242
- # Parse toolchain generated map file of `target` and display a readable table format.
243
- #
244
- function (mbed_generate_map_file target )
245
- add_custom_command (
246
- TARGET
247
- ${target}
248
- POST_BUILD
249
- COMMAND ${Python3_EXECUTABLE} ${mbed-os_SOURCE_DIR}/tools/memap.py -t ${MBED_TOOLCHAIN} ${CMAKE_CURRENT_BINARY_DIR} /${target}${CMAKE_EXECUTABLE_SUFFIX}.map
250
- WORKING_DIRECTORY
251
- ${CMAKE_CURRENT_BINARY_DIR}
252
- COMMENT
253
- "Displaying memory map for ${target} "
254
- )
255
- endfunction ()
256
-
257
- #
258
- # Validate selected application profile.
259
- #
260
- function (mbed_validate_application_profile target )
261
- get_target_property (app_link_libraries ${target} LINK_LIBRARIES )
262
- string (FIND "${app_link_libraries} " "mbed-baremetal" string_found_position )
263
- if (${string_found_position} GREATER_EQUAL 0 )
264
- if (NOT "bare-metal" IN_LIST MBED_TARGET_SUPPORTED_APPLICATION_PROFILES )
265
- message (FATAL_ERROR
266
- "Use full profile as baremetal profile is not supported for this Mbed target" )
267
- endif ()
268
- elseif (NOT "full" IN_LIST MBED_TARGET_SUPPORTED_APPLICATION_PROFILES )
269
- message (FATAL_ERROR
270
- "The full profile is not supported for this Mbed target" )
271
- endif ()
272
- endfunction ()
273
-
274
- #
275
- # Set post build operations
276
- #
277
- function (mbed_set_post_build target )
278
- # The mapfile name includes the top-level target name and the
279
- # executable suffix for all toolchains as CMake hardcodes the name of the
280
- # diagnostic output file for some toolchains.
281
- mbed_configure_memory_map (${target} "${CMAKE_CURRENT_BINARY_DIR} /${target}${CMAKE_EXECUTABLE_SUFFIX} .map" )
282
- mbed_validate_application_profile (${target} )
283
- mbed_generate_bin_hex (${target} )
284
-
285
- if (HAVE_MEMAP_DEPS )
286
- mbed_generate_map_file (${target} )
287
- endif ()
288
- endfunction ()
289
-
290
178
# Ninja requires to be forced for response files
291
179
if ("${CMAKE_GENERATOR} " MATCHES "Ninja" )
292
180
# known issue ARMClang and Ninja with response files for windows
0 commit comments