FindProtobuf: protobuf_generate function returns wrong paths when .proto file paths are relative
According to the commit message of 1bcc0f36, the protobuf_generate
function in FindProtobuf.cmake
module has been adopted to include upstream versions of it (i.e., from https://github.com/protocolbuffers/protobuf/blob/93f6b67e/cmake/protobuf-config.cmake.in). However, this commit introduces a bug. It copies the definition of _rel_dir
, but this local variable is never used.
Instead of
list(APPEND _generated_srcs "${protobuf_generate_PROTOC_OUT_DIR}/${_rel_dir}/${_basename}${_ext}")
the FindProtobuf
module contains the incorrect code:
list(APPEND _generated_srcs "${protobuf_generate_PROTOC_OUT_DIR}/${_basename}${_ext}")
This mistakes affects the following lines:
- https://github.com/Kitware/CMake/blame/a7f5cd45e135dd51d67176fc40e2d769ac5f7db8/Modules/FindProtobuf.cmake#L212
- https://github.com/Kitware/CMake/blame/a7f5cd45e135dd51d67176fc40e2d769ac5f7db8/Modules/FindProtobuf.cmake#L225
The reference upstream code for these lines is:
- https://github.com/protocolbuffers/protobuf/blob/93f6b67e/cmake/protobuf-config.cmake.in#L101
- https://github.com/protocolbuffers/protobuf/blob/93f6b67e/cmake/protobuf-config.cmake.in#L108
Aforementioned commit thus breaks the use of protobuf_generate_cpp
, when .proto
files are not located in the same directory as the CMakeLists.txt
file that invokes this function, but a subdirectory instead. The generated files will end up in the build directory in a respective subdirectory, but the returned source paths are only pointing to CMAKE_CURRENT_BINARY_DIR
instead of the respective subdirectory.
- Protobuf version: 3.4.1
- CMake version: 3.13.20190123-ga7f5c
Note: In CMake version 3.12, the protobuf_generate
function does not exist in FindProtobuf
. The protobuf_generate_cpp
and protobuf_generate_python
functions were defined separately, without this new function copied (incorrectly) from upstream.