- cmake_minimum_required(VERSION 3.5)
- set(PROTO_COMPILER "protoc")
- set(PROTO_C_COMPILER "protoc-c")
- set(C_OUT_PATH "${CMAKE_CURRENT_LIST_DIR}/proto-c")
- set(PROTO_SRCS "${CMAKE_CURRENT_LIST_DIR}/proto/Device.proto"
- "${CMAKE_CURRENT_LIST_DIR}/proto/Output.proto")
- set(pb_csrcs
- "proto-c/Device.pb-c.c"
- "proto-c/Output.pb-c.c")
- if(NOT CMAKE_BUILD_EARLY_EXPANSION)
- add_custom_command(OUTPUT ${pb_csrcs}
- COMMAND ${PROTO_C_COMPILER} --c_out=${C_OUT_PATH} -I . ${PROTO_SRCS}
- DEPENDS ${PROTO_SRCS}
- VERBATIM)
- endif()
- idf_component_register(SRCS "${pb_csrcs}"
- INCLUDE_DIRS "proto-c"
- REQUIRES protobuf-c)
I have a bunch of .proto files that I want to compile with protobuf-c whenever the project is built. I want to make a component from it. I tried adding the following to my CMakeLists.txt:
- -- Configuring done
- CMake Error at /Users/cc/esp/esp-idf/tools/cmake/component.cmake:468 (add_library):
- Cannot find source file:
- /Users/cc/Documents/myproject/components/LEDBridgeProto/proto-c/Device.pb-c.c
- Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
- .hpp .hxx .in .txx
Anybody has a good practice for compiling proto files during project build?
Thanks,
--
Szabi