Code Generation fails within PlatformIO

sans-ltd
Posts: 1
Joined: Thu Jan 11, 2024 1:04 pm

Code Generation fails within PlatformIO

Postby sans-ltd » Thu Jan 11, 2024 1:17 pm

Hello,

we are currently trying to get the code generation for some proto files working in our project.
We followed https://docs.espressif.com/projects/esp ... generation and added the following lines into out component CMakeLists.txt:

Code: Select all

idf_component_register(SRCS 
    "main.cpp"
    "protocol.pb.cc"
)

message(WARNING "COMPONENT_LIB '${COMPONENT_LIB}'")

add_custom_command(
    WORKING_DIRECTORY ${COMPONENT_DIR}
    DEPENDS protocol.proto
    COMMAND echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    COMMAND protoc --proto_path=${COMPONENT_DIR} --cpp_out=${COMPONENT_DIR} protocol.proto
    OUTPUT ${COMPONENT_DIR}/protocol.pb.cc ${COMPONENT_DIR}/protocol.pb.h
)

add_custom_target(
    generate_protobuf
    DEPENDS ${COMPONENT_DIR}/protocol.pb.cc ${COMPONENT_DIR}/protocol.pb.h
)

add_dependencies(
    ${COMPONENT_LIB} generate_protobuf
)

set_property(DIRECTORY "${COMPONENT_DIR}" APPEND PROPERTY
     ADDITIONAL_MAKE_CLEAN_FILES protocol.pb.h protocol.pb.cc)
The used versions are:

Code: Select all

PACKAGES: 
 - framework-arduinoespressif32 @ 3.20005.220925 (2.0.5) 
 - framework-espidf @ 3.40402.0 (4.4.2) 
 - tool-cmake @ 3.16.4 
 - tool-esptoolpy @ 1.40201.0 (4.2.1) 
 - tool-ninja @ 1.7.1 
 - toolchain-esp32ulp @ 1.22851.191205 (2.28.51) 
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch3
When we try to build it, we get the following issues:

Code: Select all

*** [.pio/build/esp32dev/src/protocol.pb.o] Source `src/protocol.pb.cc' not found, needed by target `.pio/build/esp32dev/src/protocol.pb.o'.
The .pb.cc and pb.h files are not generated.
We had a look into the generated build.ninja file and could not find a dependency between __idf_src and generate_protobuf, as if the add_dependencies was ignored.

What is wrong here?

Thanks in advance
Florian

User avatar
egionet
Posts: 39
Joined: Thu Sep 26, 2024 4:34 am
Location: Atlantic Canada

Re: Code Generation fails within PlatformIO

Postby egionet » Sat Mar 29, 2025 11:32 am

I am having a similar problem with add_custom_command and add_custom_target, they aren't triggering for me either in PlatformIO.

Did you figure out what was causing your problem with PlatformIO?
Regards,

Eric Gionet P.Tech.(Eng.), CIOTP, SMIEEE

Who is online

Users browsing this forum: PerplexityBot, Qwantbot and 1 guest