Ninja code generator does not build in correct order when using protobuf and custom_command

I added
find_package(Python3 REQUIRED)
in the top-level CMakeLists.txt and used “${Python3_EXECUTABLE}” instead of plain python to make it work in Windows with python not in PATH.

Then I fixed the test.py to “import foo_pb2” (remove the .py suffix).
I then build with Ninja generator and it worked.

Since the test.py could not be run, there was not some_header.h. Always look at the first error message, not the last.