conan-io / conan-center-index

Recipes for the ConanCenter repository
https://conan.io/center
MIT License
948 stars 1.73k forks source link

[question] Protobuf versioning scheme and Protobuf_VERSION variables #25297

Open lia-viam opened 4 days ago

lia-viam commented 4 days ago

What is your question?

So the versioning schemes in protobuf are a tad confusing, see eg https://protobuf.dev/support/version-support/#cpp In the second table, a version like C++ version 5.26.x corresponds to protoc version 26.x.

But in a homebrew install, for example, brew info protobuf reports version 26.1, and using find_package(Protobuf CONFIG) with such an install sets Protobuf_VERSION to 26.1.0. But then include/google/protobuf/port_def.inc defines

#define PROTOBUF_VERSION 5026001

corresponding to 5.26.1.

Now compare this to a conan project which requires and tool_requires, e.g., protobuf/5.27.0. The generated FindProtobuf.cmake sets set(Protobuf_VERSION "5.27.0"), but a conan create . with a CMake project which requires protobuf/5.27.0 prints

...
-- Conan: Including build module from '/Users/lia/.conan2/p/b/proto24456bb2a2261/p/lib/cmake/protobuf/protobuf-module.cmake'

and in this file protobuf-module.cmake, we have set(Protobuf_VERSION "27.0.0"), which is also what's reported from

$ ~/.conan2/p/b/proto24456bb2a2261/p/bin/protoc --version
libprotoc 27.0

Anyway long story short, is there a canonical way to extract what we might call the [lib]protoc version from the conan installation? I do think conan may be doing the more correct thing here, but I am dealing with some existing CMake code which expected to get a 20-something variable number like the one produced by homebrew. Some options I was considering would be

Any feedback/suggestions are appreciated!

Ahajha commented 3 days ago

Potential option is to add it as a conf_info define (see https://docs.conan.io/2/reference/conanfile/methods/package_info.html#conf-info). Then you can just read this value from the consumer conanfile.