Skip to content

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
raspberrypi:developfrom
anoshyn:fix-btstack-make-gatt-header-multiple
Open

pico_btstack: allow pico_btstack_make_gatt_header to be called more than once per target#2951
anoshyn wants to merge 1 commit into
raspberrypi:developfrom
anoshyn:fix-btstack-make-gatt-header-multiple

Conversation

@anoshyn
Copy link
Copy Markdown

@anoshyn anoshyn commented May 16, 2026

Summary

Fixes #2829. pico_btstack_make_gatt_header() (in src/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 same TARGET_LIB. Configure fails with:

CMake Error at .../pico_btstack/CMakeLists.txt:336 (add_custom_target):
  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. The reporter even proposed the one-line fix - disambiguate the target name with the .gatt file's base name (already extracted into GATT_NAME a few lines above):

-set(TARGET_GATT "${TARGET_LIB}_gatt_header")
+set(TARGET_GATT "${TARGET_LIB}_${GATT_NAME}_gatt_header")

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 automatically.

End-to-end verification

Out-of-tree consumer (rp2350 / pico2_w) that calls the function twice on a single executable target:

add_executable(gatt_double main.c)
target_link_libraries(gatt_double PRIVATE pico_stdlib)
pico_btstack_make_gatt_header(gatt_double PRIVATE a.gatt)
pico_btstack_make_gatt_header(gatt_double PRIVATE b.gatt)
Result
origin/develop (no fix) configure fails with the duplicate-target error above
this branch (fix) configure succeeds; building gatt_double_a_gatt_header and gatt_double_b_gatt_header runs compile_gatt.py twice, producing generated/gatt_double_a_gatt_header/a.h and generated/gatt_double_b_gatt_header/b.h with the respective .gatt contents

Compatibility

The custom-target name and its derived GATT_BINARY_DIR change shape, but neither is part of the public API - they're internal to the function and only consumed by target_include_directories and add_dependencies inside 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

  • Repro the failure on origin/develop with an out-of-tree consumer that calls the function twice (got the duplicate-target error).
  • Apply the fix; same consumer configures cleanly and both _gatt_header sub-targets build, producing two distinct *.h files.
  • Full SDK build clean: cmake --build build for PICO_PLATFORM=rp2040 PICO_BOARD=pico (no in-tree consumer of this function, so this confirms there is no syntax regression).
  • CI to confirm broader configurations.

… 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant