pw_protobuf_compiler: Add missing dep in CMake

Previously, pw_proto_library was missing a dependency on the
${NAME}._sources target. Proto builds would work if the ._sources target
had been run previously, but a clean build would fail.

Change-Id: I163ab1a5d765845abdcec6ec1cbcc984c1f146a8
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/47361
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
diff --git a/pw_protobuf_compiler/proto.cmake b/pw_protobuf_compiler/proto.cmake
index b7a466b..911ba3a 100644
--- a/pw_protobuf_compiler/proto.cmake
+++ b/pw_protobuf_compiler/proto.cmake
@@ -165,14 +165,15 @@
     OUTPUT
       ${outputs}
   )
-  add_custom_target("${TARGET}" DEPENDS ${outputs})
+  add_custom_target("${TARGET}._generate.${LANGUAGE}" DEPENDS ${outputs})
+  add_dependencies("${TARGET}._generate.${LANGUAGE}" "${TARGET}._sources")
 endfunction(_pw_generate_protos)
 
 # Internal function that creates a pwpb proto library.
 function(_pw_pwpb_library NAME SOURCES INPUTS DEPS INCLUDE_FILE OUT_DIR)
   list(TRANSFORM DEPS APPEND .pwpb)
 
-  _pw_generate_protos("${NAME}._generate.pwpb"
+  _pw_generate_protos("${NAME}"
       pwpb
       "$ENV{PW_ROOT}/pw_protobuf/py/pw_protobuf/plugin.py"
       ".pwpb.h"
@@ -194,7 +195,7 @@
 function(_pw_raw_rpc_library NAME SOURCES INPUTS DEPS INCLUDE_FILE OUT_DIR)
   list(TRANSFORM DEPS APPEND .raw_rpc)
 
-  _pw_generate_protos("${NAME}._generate.raw_rpc"
+  _pw_generate_protos("${NAME}"
       raw_rpc
       "$ENV{PW_ROOT}/pw_rpc/py/pw_rpc/plugin_raw.py"
       ".raw_rpc.pb.h"
@@ -241,9 +242,13 @@
     if("${SOURCES}" MATCHES "nanopb\\.proto")
       add_custom_target("${NAME}._generate.nanopb")  # Nothing to do
       add_library("${NAME}.nanopb" INTERFACE)
-      target_link_libraries("${NAME}.nanopb" INTERFACE pw_third_party.nanopb ${DEPS})
+      target_link_libraries("${NAME}.nanopb"
+        INTERFACE
+          pw_third_party.nanopb
+          ${DEPS}
+      )
     else()
-      _pw_generate_protos("${NAME}._generate.nanopb"
+      _pw_generate_protos("${NAME}"
           nanopb
           "${dir_pw_third_party_nanopb}/generator/protoc-gen-nanopb"
           ".pb.h;.pb.c"
@@ -274,7 +279,7 @@
   # Determine the names of the output files.
   list(TRANSFORM DEPS APPEND .nanopb_rpc)
 
-  _pw_generate_protos("${NAME}._generate.nanopb_rpc"
+  _pw_generate_protos("${NAME}"
       nanopb_rpc
       "$ENV{PW_ROOT}/pw_rpc/py/pw_rpc/plugin_nanopb.py"
       ".rpc.pb.h"