+
+ set(GENERATOR_PATH ${CMAKE_BINARY_DIR}/nanopb/generator)
+
+ set(NANOPB_GENERATOR_EXECUTABLE ${GENERATOR_PATH}/nanopb_generator.py)
+
+ set(GENERATOR_CORE_DIR ${GENERATOR_PATH}/proto)
+ set(GENERATOR_CORE_SRC
+ ${GENERATOR_CORE_DIR}/nanopb.proto
+ ${GENERATOR_CORE_DIR}/plugin.proto)
+
+ # Treat the source diretory as immutable.
+ #
+ # Copy the generator directory to the build directory before
+ # compiling python and proto files. Fixes issues when using the
+ # same build directory with different python/protobuf versions
+ # as the binary build directory is discarded across builds.
+ #
+ add_custom_command(
+ OUTPUT ${NANOPB_GENERATOR_EXECUTABLE} ${GENERATOR_CORE_SRC}
+ COMMAND ${CMAKE_COMMAND} -E copy_directory
+ ARGS ${NANOPB_GENERATOR_SOURCE_DIR} ${GENERATOR_PATH}
+ VERBATIM)
+
+ set(GENERATOR_CORE_PYTHON_SRC)
+ foreach(FIL ${GENERATOR_CORE_SRC})
+ get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
+ get_filename_component(FIL_WE ${FIL} NAME_WE)
+
+ set(output "${GENERATOR_CORE_DIR}/${FIL_WE}_pb2.py")
+ set(GENERATOR_CORE_PYTHON_SRC ${GENERATOR_CORE_PYTHON_SRC} ${output})
+ add_custom_command(
+ OUTPUT ${output}
+ COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
+ ARGS -I${GENERATOR_PATH}/proto
+ --python_out=${GENERATOR_CORE_DIR} ${ABS_FIL}
+ DEPENDS ${ABS_FIL}
+ VERBATIM)
+ endforeach()