[cmake-developers] [PATCH] FindProtobuf: check version
Rolf Eike Beer
eike at sf-mail.de
Tue Feb 2 10:18:31 EST 2016
> +
> + set(Protobuf_VERSION 0)
Just set it to an empty string.
> + set(Protobuf_LIB_VERSION "")
> + file(STRINGS ${_Protobuf_COMMON_HEADER} _Protobuf_COMMON_H_CONTENTS
> REGEX "#define GOOGLE_PROTOBUF_VERSION ")
I would replace the spaces with "[ \t]+" so a formatting change will not
break the extraction, also below.
> + set(_Protobuf_VERSION_REGEX "([0-9]+)")
No need for that variable, just put it into the matches argument below.
> + if("${_Protobuf_COMMON_H_CONTENTS}" MATCHES "#define
> GOOGLE_PROTOBUF_VERSION ${_Protobuf_VERSION_REGEX}")
> + set(Protobuf_VERSION "${CMAKE_MATCH_1}")
> + endif()
> + unset(_Protobuf_COMMON_H_CONTENTS)
> +
> + math(EXPR Protobuf_MAJOR_VERSION "${Protobuf_VERSION} / 1000000")
> + math(EXPR Protobuf_MINOR_VERSION "${Protobuf_VERSION} / 1000 %
> 1000")
> + math(EXPR Protobuf_SUBMINOR_VERSION "${Protobuf_VERSION} % 1000")
You are not required to export these variables, only if you expect it to
be useful for something beyond version checking. If anyone needs
specific version fiddling Protobuf_VERSION can be used.
Eike
More information about the cmake-developers
mailing list