Browse Source

fix nanopb_generate

ugv_io
Alex Mikhalev 6 years ago
parent
commit
d837a9f40d
  1. 12
      components/nanopb/functions.cmake

12
components/nanopb/functions.cmake

@ -1,19 +1,23 @@ @@ -1,19 +1,23 @@
set(NANOPB_PLUGIN "${CMAKE_CURRENT_LIST_DIR}/nanopb/generator/protoc-gen-nanopb")
function(nanopb_generate PROTO_FILE PB_OUT HDR_VAR SRC_VAR)
get_filename_component(PROTO_FILE_NAME ${PROTO_FILE} NAME_WE)
get_filename_component(PROTO_FILE_PATH ${PROTO_FILE} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
get_filename_component(PROTO_FILE_DIR ${PROTO_FILE_PATH} DIRECTORY)
set(PROTO_HDR "${PB_OUT}/${PROTO_FILE_NAME}.pb.h")
set(PROTO_SRC "${PB_OUT}/${PROTO_FILE_NAME}.pb.c")
list(APPEND "${HDR_VAR}" ${PROTO_HDR})
list(APPEND "${SRC_VAR}" ${PROTO_SRC})
set(${HDR_VAR} ${${HDR_VAR}} ${PROTO_HDR} PARENT_SCOPE)
set(${SRC_VAR} ${${SRC_VAR}} ${PROTO_SRC} PARENT_SCOPE)
if(NOT CMAKE_SCRIPT_MODE_FILE)
add_custom_command(OUTPUT ${PROTO_HDR} ${PROTO_SRC}
COMMAND protoc
--plugin=protoc-gen-nanopb=${CMAKE_CURRENT_LIST_DIR}/nanopb/generator/protoc-gen-nanopb
--plugin=protoc-gen-nanopb=${NANOPB_PLUGIN}
--nanopb_out=${PB_OUT}
--proto_path ${PROTO_FILE_DIR}
${PROTO_FILE_PATH}
DEPENDS ${PROTO_FILE_PATH})
DEPENDS ${PROTO_FILE_PATH}
COMMENT "Generating nanopb sources for ${PROTO_FILE}")
set_property(SOURCE ${PROTO_HDR} ${PROTO_SRC} PROPERTY GENERATED TRUE)
endif()
list(APPEND ADDITIONAL_MAKE_CLEAN_FILES ${PROTO_HDR} ${PROTO_SRC})
endfunction()

Loading…
Cancel
Save