
# Specify the .proto file
set(PROTO_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../proto)
set(PROTO_FILE 
${PROTO_SRC_DIR}/firmware.proto
${PROTO_SRC_DIR}/light.proto
${PROTO_SRC_DIR}/usb.proto
${PROTO_SRC_DIR}/cls_device.proto
)

# Specify where you want to generate the python code
set(PYTHON_OUT_DIR ${CMAKE_CURRENT_SOURCE_DIR})

# Specify the include directory
set(PROTO_INC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../lib/nanopb/generator/proto)

# Add the command to generate the python code
add_custom_command(
    OUTPUT ${PYTHON_OUT_DIR}/firmware_pb2.py
    COMMAND protoc --python_out=${PYTHON_OUT_DIR} --proto_path=${PROTO_SRC_DIR}:${PROTO_INC_DIR} ${PROTO_FILE} ${PROTO_INC_DIR}/nanopb.proto
    DEPENDS ${PROTO_FILE}
)

# Add the generated python code to a custom target
add_custom_target(GeneratePythonProtobufCode ALL DEPENDS ${PYTHON_OUT_DIR}/firmware_pb2.py)