2021-01-20 16:44:27 +00:00
function ( _pico_init_pioasm )
set ( CMAKE_MODULE_PATH ${ CMAKE_MODULE_PATH } ${ PICO_SDK_PATH } /tools )
# todo CMAKE_CURRENT_FUNCTION_LIST_DIR ... what version?
find_package ( Pioasm REQUIRED )
endfunction ( )
2022-08-02 12:28:37 +00:00
# PICO_CMAKE_CONFIG: PICO_DEFAULT_PIOASM_OUTPUT_FORMAT, default output format used by pioasm when using pico_generate_pio_header, default=c-sdk, group=build
2021-01-20 16:44:27 +00:00
function ( pico_generate_pio_header TARGET PIO )
_pico_init_pioasm ( )
2022-05-16 19:20:41 +00:00
cmake_parse_arguments ( pico_generate_pio_header "" "OUTPUT_FORMAT;OUTPUT_DIR" "" ${ ARGN } )
if ( pico_generate_pio_header_OUTPUT_FORMAT )
set ( OUTPUT_FORMAT "${pico_generate_pio_header_OUTPUT_FORMAT}" )
elseif ( DEFINED PICO_DEFAULT_PIOASM_OUTPUT_FORMAT )
set ( OUTPUT_FORMAT "${PICO_DEFAULT_PIOASM_OUTPUT_FORMAT}" )
else ( )
set ( OUTPUT_FORMAT "c-sdk" )
endif ( )
2021-01-20 16:44:27 +00:00
if ( pico_generate_pio_header_OUTPUT_DIR )
get_filename_component ( HEADER_DIR ${ pico_generate_pio_header_OUTPUT_DIR } ABSOLUTE )
else ( )
set ( HEADER_DIR "${CMAKE_CURRENT_BINARY_DIR}" )
endif ( )
get_filename_component ( PIO_NAME ${ PIO } NAME )
set ( HEADER "${HEADER_DIR}/${PIO_NAME}.h" )
#message("Will generate ${HEADER}")
get_filename_component ( HEADER_GEN_TARGET ${ PIO } NAME_WE )
set ( HEADER_GEN_TARGET "${TARGET}_${HEADER_GEN_TARGET}_pio_h" )
2021-01-29 19:46:23 +00:00
add_custom_target ( ${ HEADER_GEN_TARGET } DEPENDS ${ HEADER } )
2021-01-20 16:44:27 +00:00
add_custom_command ( OUTPUT ${ HEADER }
D E P E N D S $ { P I O }
2022-05-16 19:20:41 +00:00
C O M M A N D P i o a s m - o $ { O U T P U T _ F O R M A T } $ { P I O } $ { H E A D E R }
2021-01-20 16:44:27 +00:00
)
add_dependencies ( ${ TARGET } ${ HEADER_GEN_TARGET } )
get_target_property ( target_type ${ TARGET } TYPE )
2021-06-28 21:53:38 +00:00
if ( "INTERFACE_LIBRARY" STREQUAL "${target_type}" )
2021-01-20 16:44:27 +00:00
target_include_directories ( ${ TARGET } INTERFACE ${ HEADER_DIR } )
2021-06-28 21:53:38 +00:00
else ( )
target_include_directories ( ${ TARGET } PUBLIC ${ HEADER_DIR } )
2021-01-20 16:44:27 +00:00
endif ( )
endfunction ( )
function ( pico_add_uf2_output TARGET )
2022-10-21 14:01:55 +00:00
get_target_property ( ${ TARGET } _archive_directory ${ TARGET } ARCHIVE_OUTPUT_DIRECTORY )
if ( ${ TARGET } _archive_directory )
get_filename_component ( output_path "${${TARGET}_archive_directory}"
R E A L P A T H B A S E _ D I R " $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } " )
file ( MAKE_DIRECTORY "${output_path}" )
set ( output_path "${output_path}/" )
else ( )
set ( output_path "" )
endif ( )
2021-01-20 16:44:27 +00:00
if ( NOT ELF2UF2_FOUND )
set ( CMAKE_MODULE_PATH ${ CMAKE_MODULE_PATH } ${ PICO_SDK_PATH } /tools )
find_package ( ELF2UF2 )
endif ( )
if ( ELF2UF2_FOUND )
add_custom_command ( TARGET ${ TARGET } POST_BUILD
2022-10-21 14:01:55 +00:00
C O M M A N D E L F 2 U F 2 $ < T A R G E T _ F I L E : $ { T A R G E T } > $ { o u t p u t _ p a t h } $ < I F : $ < B O O L : $ < T A R G E T _ P R O P E R T Y : $ { T A R G E T } , O U T P U T _ N A M E > > , $ < T A R G E T _ P R O P E R T Y : $ { T A R G E T } , O U T P U T _ N A M E > , $ < T A R G E T _ P R O P E R T Y : $ { T A R G E T } , N A M E > > . u f 2 )
2021-01-20 16:44:27 +00:00
endif ( )
endfunction ( )