forked from Elemecca/cmake-microchip
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathAVRObj2Hex.cmake
64 lines (54 loc) · 1.99 KB
/
AVRObj2Hex.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#=============================================================================
# Copyright 2016 Sam Hanes
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file COPYING.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake-Microchip,
# substitute the full License text for the above reference.)
function(avr_obj2hex target)
find_program(AVR_OBJ2HEX
NAMES ${_CMAKE_TOOLCHAIN_PREFIX}avr-objcopy avr-objcopy
HINTS ${_CMAKE_TOOLCHAIN_LOCATION}
)
if(NOT AVR_OBJ2HEX)
message(SEND_ERROR "No avr-objcopy program was found")
endif()
function(get_target_property_fallback var target)
set(result NOTFOUND)
foreach(property ${ARGN})
get_target_property(result ${target} ${property})
if(result)
break()
endif()
endforeach()
set(${var} ${result} PARENT_SCOPE)
endfunction()
get_target_property_fallback(in_f ${target}
RUNTIME_OUTPUT_NAME
OUTPUT_NAME
NAME
)
get_target_property_fallback(dir ${target}
RUNTIME_OUTPUT_DIRECTORY
BINARY_DIR
)
get_filename_component(out_f ${in_f} NAME_WE)
set(out_f "${out_f}$<$<CONFIG:DEBUG>:${CMAKE_DEBUG_POSTFIX}>.hex")
add_custom_command(
TARGET ${target} POST_BUILD
WORKING_DIRECTORY ${dir}/$<CONFIG>
COMMAND "${AVR_OBJ2HEX}" -O ihex ${ARGN} "${in_f}$<$<CONFIG:DEBUG>:${CMAKE_DEBUG_POSTFIX}>.elf" "${out_f}"
BYPRODUCTS ${dir}/$<CONFIG>/${out_f}
VERBATIM
)
set_property(DIRECTORY APPEND
PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
${dir}/$<CONFIG>/${out_f}
)
install(FILES ${dir}/$<CONFIG>/${out_f} TYPE BIN)
endfunction()