1# include targets for all for PICO on device
2
3enable_language(ASM)
4
5function(pico_add_hex_output TARGET)
6    add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${TARGET}> $<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.hex
7        VERBATIM)
8endfunction()
9
10function(pico_add_bin_output TARGET)
11    add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${TARGET}> $<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.bin
12        VERBATIM)
13endfunction()
14
15function(pico_add_dis_output TARGET)
16    add_custom_command(TARGET ${TARGET} POST_BUILD
17            COMMAND ${CMAKE_OBJDUMP} -h $<TARGET_FILE:${TARGET}> > $<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.dis
18            COMMAND ${CMAKE_OBJDUMP} -d $<TARGET_FILE:${TARGET}> >> $<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.dis
19            VERBATIM)
20endfunction()
21
22function(pico_add_extra_outputs TARGET)
23    pico_add_hex_output(${TARGET})
24    pico_add_bin_output(${TARGET})
25    pico_add_dis_output(${TARGET})
26
27    # PICO_CMAKE_CONFIG: PICO_NO_TARGET_NAME, Don't define PICO_TARGET_NAME, type=bool, default=0, group=build
28    # PICO_BUILD_DEFINE: PICO_TARGET_NAME, The name of the build target being compiled (unless PICO_NO_TARGET_NAME set in build), type=string, default=target name, group=build
29    if (NOT PICO_NO_TARGET_NAME)
30        target_compile_definitions(${TARGET} PRIVATE
31                PICO_TARGET_NAME="${TARGET}"
32                )
33    endif()
34
35    if (PICO_SYMLINK_ELF_AS_FILENAME)
36        add_custom_target(${TARGET}_symlinked)
37        add_dependencies(${TARGET}_symlinked ${TARGET})
38
39        add_custom_command(TARGET ${TARGET}_symlinked POST_BUILD
40                COMMAND rm -f "${PICO_SYMLINK_ELF_AS_FILENAME}"
41                COMMAND ln -s -r $<TARGET_FILE:${TARGET}> "${PICO_SYMLINK_ELF_AS_FILENAME}"
42                COMMENT "Symlinking from ${PICO_SYMLINK_ELF_AS_FILENAME} to ${TARGET}"
43                )
44    endif ()
45    # PICO_CMAKE_CONFIG: PICO_NO_UF2, Disable UF2 output, type=bool, default=0, group=build
46    if (NOT PICO_NO_UF2)
47        pico_add_uf2_output(${TARGET})
48    endif()
49endfunction()
50
51add_subdirectory(common)
52add_subdirectory(rp2_common)
53
54# PICO_CMAKE_CONFIG: PICO_NO_HARDWARE, OPTION: Whether the build is not targeting an RP2040 device, type=bool, default=1 when PICO_PLATFORM is host, 0 otherwise, group=build
55# PICO_BUILD_DEFINE: PICO_NO_HARDWARE, Whether the build is not targeting an RP2040 device, type=bool, default=1 when PICO_PLATFORM is host, 0 otherwise, group=build
56set(PICO_NO_HARDWARE "0" CACHE INTERNAL "")
57# PICO_CMAKE_CONFIG: PICO_ON_DEVICE, OPTION: Whether the build is targeting an RP2040 device, type=bool, default=0 when PICO_PLATFORM is host, 1 otherwise, group=build
58# PICO_BUILD_DEFINE: PICO_ON_DEVICE, Whether the build is targeting an RP2040 device, type=bool, default=0 when PICO_PLATFORM is host, 1 otherwise, group=build
59set(PICO_ON_DEVICE "1" CACHE INTERNAL "")
60
61set(CMAKE_EXECUTABLE_SUFFIX .elf PARENT_SCOPE)
62