Skip to content

Commit c61a06d

Browse files
committed
Thow FATAL_ERROR when using post-processing functions after pico_add_extra_outputs
1 parent 89691ed commit c61a06d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tools/CMakeLists.txt

+25
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ define_property(TARGET
7171
BRIEF_DOCS "Extra arguments to pass to uf2 conversion"
7272
FULL_DOCS "Extra arguments to pass to uf2 conversion"
7373
)
74+
define_property(TARGET
75+
PROPERTY PICOTOOL_PROCESSING_DONE
76+
INHERITED
77+
BRIEF_DOCS "Set once post-processing has been completed in CMake"
78+
FULL_DOCS "Set once post-processing has been completed in CMake"
79+
)
7480

7581
# Check pioasm is installed, or build it if not installed
7682
function(pico_init_pioasm)
@@ -146,6 +152,13 @@ function(pico_init_picotool)
146152
endif()
147153
endfunction()
148154

155+
function(picotool_check_not_done TARGET)
156+
get_target_property(done ${TARGET} PICOTOOL_PROCESSING_DONE)
157+
if (done)
158+
message(FATAL_ERROR "All picotool post-processing functions for \"${TARGET}\" must come before pico_add_extra_outputs(${TARGET})")
159+
endif()
160+
endfunction()
161+
149162
# Generate pio header and include it in the build
150163
# PICO_CMAKE_CONFIG: PICO_DEFAULT_PIOASM_OUTPUT_FORMAT, Default output format used by pioasm when using pico_generate_pio_header, type=string, default=c-sdk, group=build
151164
function(pico_generate_pio_header TARGET PIO)
@@ -198,6 +211,7 @@ endfunction()
198211
# dropping, and it will be copied to SRAM by the bootrom before execution.
199212
# This sets PICOTOOL_UF2_PACKAGE_ADDR to PACKADDR.
200213
function(pico_package_uf2_output TARGET PACKADDR)
214+
picotool_check_not_done(${TARGET})
201215
set_target_properties(${TARGET} PROPERTIES
202216
PICOTOOL_UF2_PACKAGE_ADDR ${PACKADDR}
203217
)
@@ -207,6 +221,7 @@ endfunction()
207221
# Output the public key hash and other necessary rows to an otp JSON file.
208222
# This sets PICOTOOL_OTP_FILE to OTPFILE.
209223
function(pico_set_otp_key_output_file TARGET OTPFILE)
224+
picotool_check_not_done(${TARGET})
210225
set_target_properties(${TARGET} PROPERTIES
211226
PICOTOOL_OTP_FILE ${OTPFILE}
212227
)
@@ -217,6 +232,7 @@ endfunction()
217232
# before loading the binary. This appends the `--clear` argument
218233
# to PICOTOOL_EXTRA_PROCESS_ARGS.
219234
function(pico_load_map_clear_sram TARGET)
235+
picotool_check_not_done(${TARGET})
220236
# get and set, to inherit list
221237
get_target_property(extra_args ${TARGET} PICOTOOL_EXTRA_PROCESS_ARGS)
222238
if (extra_args)
@@ -234,6 +250,7 @@ endfunction()
234250
# to PICOTOOL_EXTRA_PROCESS_ARGS if setting the rollback version, or set as compile
235251
# definitions if only setting the major/minor versions.
236252
function(pico_set_binary_version TARGET)
253+
picotool_check_not_done(${TARGET})
237254
set(oneValueArgs MAJOR MINOR ROLLBACK)
238255
set(multiValueArgs ROWS)
239256
cmake_parse_arguments(PARSE_ARGV 1 SV "" "${oneValueArgs}" "${multiValueArgs}")
@@ -283,6 +300,7 @@ endfunction()
283300
# Set the UF2 family to use when creating the UF2.
284301
# This sets PICOTOOL_UF2_FAMILY to FAMILY.
285302
function(pico_set_uf2_family TARGET FAMILY)
303+
picotool_check_not_done(${TARGET})
286304
set_target_properties(${TARGET} PROPERTIES
287305
PICOTOOL_UF2_FAMILY ${FAMILY}
288306
)
@@ -295,6 +313,7 @@ endfunction()
295313
# specify a common SIGFILE for multiple targets, the SIGFILE property can be
296314
# set for a given scope, and then the SIGFILE argument is optional.
297315
function(pico_sign_binary TARGET)
316+
picotool_check_not_done(${TARGET})
298317
# Enforce signing through target properties
299318
set_target_properties(${TARGET} PROPERTIES
300319
PICOTOOL_SIGN_OUTPUT true
@@ -320,6 +339,7 @@ endfunction()
320339
# pico_hash_binary(TARGET)
321340
# Hash the target binary. This sets PICOTOOL_HASH_OUTPUT to true.
322341
function(pico_hash_binary TARGET)
342+
picotool_check_not_done(${TARGET})
323343
# Enforce hashing through target properties
324344
set_target_properties(${TARGET} PROPERTIES
325345
PICOTOOL_HASH_OUTPUT true
@@ -330,6 +350,7 @@ endfunction()
330350
# Create the specified partition table from JSON, and embed it in the
331351
# block loop. This sets PICOTOOL_EMBED_PT to PTFILE.
332352
function(pico_embed_pt_in_binary TARGET PTFILE)
353+
picotool_check_not_done(${TARGET})
333354
set_target_properties(${TARGET} PROPERTIES
334355
PICOTOOL_EMBED_PT ${PTFILE}
335356
)
@@ -341,6 +362,7 @@ endfunction()
341362
# This sets PICOTOOL_AESFILE to AESFILE, and PICOTOOL_ENC_SIGFILE to SIGFILE
342363
# if present, else PICOTOOL_SIGFILE.
343364
function(pico_encrypt_binary TARGET AESFILE)
365+
picotool_check_not_done(${TARGET})
344366
set_target_properties(${TARGET} PROPERTIES
345367
PICOTOOL_AESFILE ${AESFILE}
346368
)
@@ -422,6 +444,9 @@ endfunction()
422444
# Run picotool post-processing on the binary - must be called after
423445
# all required properties have been set
424446
function(picotool_postprocess_binary TARGET)
447+
set_target_properties(${TARGET} PROPERTIES
448+
PICOTOOL_PROCESSING_DONE true
449+
)
425450
# Read target properties
426451
get_target_property(picotool_sign_output ${TARGET} PICOTOOL_SIGN_OUTPUT)
427452
if (picotool_sign_output)

0 commit comments

Comments
 (0)