-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathbuild_sketch.cmake
69 lines (52 loc) · 2.22 KB
/
build_sketch.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
65
66
67
68
69
cmake_minimum_required(VERSION 3.21)
# Only want the variant and library targets to be defined once
include_guard(GLOBAL)
include(sketch_preprocess_sources)
include(convert_file)
include(set_base_arduino_config)
add_subdirectory(${BUILD_VARIANT_PATH} ./variant)
add_subdirectory(${BUILD_CORE_PATH} ./cores/arduino)
add_subdirectory(${BUILD_LIB_PATH} ./libraries)
function(build_sketch)
cmake_parse_arguments(PARSE_ARGV 0 SKBD "" "TARGET" "SOURCES;DEPENDS")
if(DEFINED SKBD_UNPARSED_ARGUMENTS OR DEFINED SKBD_KEYWORDS_MISSING_VALUES)
message(SEND_ERROR "Invalid call to build_sketch(); some arguments went unparsed")
endif()
if(NOT DEFINED SKBD_TARGET)
message(SEND_ERROR "Invalid call to build_sketch(); please specify a TARGET")
return()
elseif(NOT DEFINED SKBD_SOURCES)
message(SEND_ERROR "Invalid call to build_sketch(); please specify some SOURCES")
return()
endif()
add_executable(${SKBD_TARGET})
target_include_directories(base_config BEFORE INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
foreach(SRCS IN LISTS SKBD_SOURCES)
sketch_preprocess_sources(OUTPUT_VARIABLE SRCS SOURCES ${SRCS})
target_sources(${SKBD_TARGET} PRIVATE ${SRCS})
endforeach()
target_link_libraries(${SKBD_TARGET} PRIVATE stm32_runtime)
if(DEFINED SKBD_DEPENDS)
target_link_libraries(${SKBD_TARGET} PRIVATE ${SKBD_DEPENDS})
endif()
get_target_property(OUTDIR ${SKBD_TARGET} BINARY_DIR)
set(MAPFILE ${OUTDIR}/${SKBD_TARGET}.map)
target_link_options(${SKBD_TARGET} PRIVATE
LINKER:-Map,${MAPFILE}
)
# this is here to make CMake et al. aware that the map file
# is generated along with the binary
add_custom_command(TARGET ${SKBD_TARGET} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E true # essentially a no-op
BYPRODUCTS ${MAPFILE}
)
if(EXISTS ${Python3_EXECUTABLE})
add_custom_command(TARGET ${SKBD_TARGET} POST_BUILD
COMMAND ${Python3_EXECUTABLE} ${SCRIPTS_FOLDER}/sizereport.py -x ${CMAKE_SIZE} -f $<TARGET_FILE:${SKBD_TARGET}> --progmem ${BOARD_MAXSIZE} --datamem ${BOARD_MAXDATASIZE}
)
else() # STREQUAL "PYTHON3-NOTFOUND"
message(WARNING "python3 not found; the final size report will not be displayed")
endif()
elf2bin(${SKBD_TARGET})
elf2hex(${SKBD_TARGET})
endfunction()