CMake does this automatically now (as of version 3.20). Also, for some reason unbeknownst to me, cmake doesn't clean the generated proto files when they are explicitly marked as such.