pico_btstack: allow pico_btstack_make_gatt_header to be called more than once per target#2951
Open
anoshyn wants to merge 1 commit into
Open
Conversation
… target can consume multiple .gatt files
pico_btstack_make_gatt_header() built its internal custom-target name as
"${TARGET_LIB}_gatt_header", which collides on the second call with the
same TARGET_LIB. Configure fails with:
add_custom_target cannot create target "${TARGET_LIB}_gatt_header"
because another target with the same name already exists.
This prevents a single executable / library from owning more than one
.gatt file - exactly the use case in raspberrypi#2829.
Disambiguate the per-invocation target name by including the .gatt
file's base name (already extracted into GATT_NAME a few lines above).
GATT_BINARY_DIR and the include directory added via
target_include_directories are derived from TARGET_GATT, so each .gatt
file also gets its own output directory.
Verified by an out-of-tree consumer that calls
pico_btstack_make_gatt_header(target PRIVATE a.gatt) and again with
b.gatt. On origin/develop, configure fails with the duplicate-target
message above; on this branch, both gatt_double_a_gatt_header and
gatt_double_b_gatt_header build successfully and produce distinct
test.h files containing the respective .gatt content.
Fixes raspberrypi#2829.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2829.
pico_btstack_make_gatt_header()(insrc/rp2_common/pico_btstack/CMakeLists.txt) builds its internal custom-target name as"${TARGET_LIB}_gatt_header", which collides on the second call with the sameTARGET_LIB. Configure fails with:This prevents a single executable / library from owning more than one
.gattfile. The reporter even proposed the one-line fix - disambiguate the target name with the.gattfile's base name (already extracted intoGATT_NAMEa few lines above):GATT_BINARY_DIRand the include directory added viatarget_include_directoriesare derived fromTARGET_GATT, so each.gattfile also gets its own output directory automatically.End-to-end verification
Out-of-tree consumer (rp2350 / pico2_w) that calls the function twice on a single executable target:
origin/develop(no fix)gatt_double_a_gatt_headerandgatt_double_b_gatt_headerrunscompile_gatt.pytwice, producinggenerated/gatt_double_a_gatt_header/a.handgenerated/gatt_double_b_gatt_header/b.hwith the respective.gattcontentsCompatibility
The custom-target name and its derived
GATT_BINARY_DIRchange shape, but neither is part of the public API - they're internal to the function and only consumed bytarget_include_directoriesandadd_dependenciesinside the same function body. The generated header name (${GATT_NAME}.h) is unchanged, so#include \"foo.h\"continues to work the same way.Test plan
origin/developwith an out-of-tree consumer that calls the function twice (got the duplicate-target error)._gatt_headersub-targets build, producing two distinct*.hfiles.cmake --build buildforPICO_PLATFORM=rp2040 PICO_BOARD=pico(no in-tree consumer of this function, so this confirms there is no syntax regression).