FindProtobuf - FindPkgConfig cannot be used as a hint to Find_Package(protobuf)
This relates to #21229 (closed)
The default for protocol buffers is to install a pkg-config file on Linux. Though there is a cmake build which works (providing you don't simultaneous need static and shared libraries). This includes at least CentOS8 and Debian9.
If you attempt to piggyback finding protocol buffers off of pkg-config it does not work for example:
pkg_check_modules(Protobuf REQUIRED protobuf)
Will result in:
-- Found protobuf, version 3.5.0
But:
find_package(Protobof 3.3.0 REQUIRED)
Will result in:
Could not find a package configuration file provided by "Protobuf" (requested version 3.3.0) with any of the following names:
ProtobufConfig.cmake
protobuf-config.cmake
Both lines together:
pkg_check_modules(Protobuf REQUIRED protobuf)
find_package(Protobof 3.3.0 REQUIRED)
Confusingly outputs both seemingly contradictory (but in fact separate) messages.
If you locate protocol buffers using pkg_check_modules() alone the protobuf_generate_cpp() function is not available (FindProtobuf.cmake is not invoked).
find_package() is not able to locate the package if it is installed to a non standard location. For example, I install to /opt/protobuf-3.5.0 on CentOS7.
Find_Package(protobuf) and/or FindProtobuf.cmake should be able to find the package if it can be found using pkg-config (as is proven by adding pkg_check_modules().
The only workaround I found for this was to use the cmake build for protobuf (which creates cmake config files but appears to be intended for windows) and to add a hint to find_package as per #21229 (closed) .