pw_protobuf_compiler: Ensure nanopb_pb2.py is generated

Import the Nanopb Python package to ensure that nanopb_pb2.py is
generated prior generating any Nanopb protos. This prevents race
conditions in clean builds.

Change-Id: I4b07ceb5665c49d0bd73a35759af18ec275094ed
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/43741
Commit-Queue: Wyatt Hepler <hepler@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
diff --git a/pw_protobuf_compiler/proto.cmake b/pw_protobuf_compiler/proto.cmake
index d05b960..2410c5d 100644
--- a/pw_protobuf_compiler/proto.cmake
+++ b/pw_protobuf_compiler/proto.cmake
@@ -246,6 +246,11 @@
         "${INPUTS}"
         "${DEPS}"
     )
+
+    # Ensure that nanopb_pb2.py is generated to avoid race conditions.
+    add_dependencies("${NAME}._generate.nanopb"
+        pw_third_party.nanopb.generate_proto
+    )
   endif()
 
   # Create the library with the generated source files.