forked from eclipse-threadx/getting-started
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilities.cmake
40 lines (36 loc) · 1.63 KB
/
utilities.cmake
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
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
function(post_build TARGET)
if(CMAKE_C_COMPILER_ID STREQUAL "IAR")
add_custom_target(${TARGET}.bin ALL
DEPENDS ${TARGET}
COMMAND ${CMAKE_IAR_ELFTOOL} --bin ${TARGET}.elf ${TARGET}.bin)
elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU")
add_custom_target(${TARGET}.bin ALL
DEPENDS ${TARGET}
COMMAND ${CMAKE_OBJCOPY} -Obinary ${TARGET}.elf ${TARGET}.bin
COMMAND ${CMAKE_OBJCOPY} -Oihex ${TARGET}.elf ${TARGET}.hex)
else()
message(FATAL_ERROR "Unknown CMAKE_C_COMPILER_ID ${CMAKE_C_COMPILER_ID}")
endif()
endfunction()
function(set_target_linker TARGET LINKER_SCRIPT)
if(CMAKE_C_COMPILER_ID STREQUAL "IAR")
target_link_options(${TARGET} PRIVATE --config ${LINKER_SCRIPT})
target_link_options(${TARGET} PRIVATE --map=${TARGET}.map)
elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_link_options(${TARGET} PRIVATE -T${LINKER_SCRIPT})
target_link_options(${TARGET} PRIVATE -Wl,-Map=${TARGET}.map)
set_target_properties(${TARGET} PROPERTIES SUFFIX ".elf")
else()
message(FATAL_ERROR "Unknown CMAKE_C_COMPILER_ID ${CMAKE_C_COMPILER_ID}")
endif()
endfunction()
macro(print_all_variables)
message(STATUS "print_all_variables------------------------------------------{")
get_cmake_property(_variableNames VARIABLES)
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
message(STATUS "print_all_variables------------------------------------------}")
endmacro()