Skip to content

FindProtobuf: Do not verify protoc version if it is not found

Diego Pino requested to merge dpino/cmake:fix-find-protobuf into master

In some systems, the FindProtobuf.cmake module ends with the following message:

Protobuf compiler version doesn't match library version 3.6.1

The error message is meant to print out the actual version installed in the system, however the actual version is not part of the message.

if(NOT "${_PROTOBUF_PROTOC_EXECUTABLE_VERSION}" VERSION_EQUAL "${Protobuf_VERSION}")
   message(WARNING "Protobuf compiler version ${_PROTOBUF_PROTOC_EXECUTABLE_VERSION}"
          " doesn't match library version ${Protobuf_VERSION}")
endif()

The reason why ${_PROTOBUF_PROTOC_EXECUTABLE_VERSION}" is empty is because actually a Protobuf compiler program could not be found. In line 445:

# Find the protoc Executable
find_program(Protobuf_PROTOC_EXECUTABLE
    NAMES protoc
    DOC "The Google Protocol Buffers Compiler"
    PATHS
    ${Protobuf_SRC_ROOT_FOLDER}/vsprojects/${_PROTOBUF_ARCH_DIR}Release
    ${Protobuf_SRC_ROOT_FOLDER}/vsprojects/${_PROTOBUF_ARCH_DIR}Debug
)

In some systems, the Protobuf compiler goes by the name of protoc-c instead of protoc. The solution might be creating a symbolic link from protoc-c to protoc, although a more generic solution is to additionally search for protoc-c, which is what the patch does.

In addition, the patch also checks whether a binary could be found before checking the version number of the compiler.

Topic-rename: FindProtobuf-no-protoc

Edited by Brad King

Merge request reports