I have a problem with cmake
I'm writting in CMakeLists
set(PROTOBUF_VERSION "2.4.1")
find_package(Protobuf ${PROTOBUF_VERSION} EXACT REQUIRED)
But when I run cmake on my machine with protobuf 2.5.0, it successfully generates makefile.
In stdout I have only:
-- Found PROTOBUF: /usr/local/lib/libprotobuf.so
But for ZLIB I have
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.7")
Probably, protobuf doesn't contain a version of itself in the library. Is there a way to specify protobufer's version?
I'm not sure whether the fault is in protobuf, or in the CMake module, but you have a couple of choices here.
If the find_package
call succeeds, you should have access to both the protobuf include path, and to the protoc compiler. You can either read in the contents of ${PROTOBUF_INCLUDE_DIRS}/google/protobuf/stubs/common.h
and do a regex search for #define GOOGLE_PROTOBUF_VERSION
, or you can invoke protoc --version
and search the output for the correct version.
So, for option 1, you can do:
find_package(Protobuf ${PROTOBUF_VERSION} REQUIRED)
if(NOT EXISTS "${PROTOBUF_INCLUDE_DIRS}/google/protobuf/stubs/common.h")
message(FATAL_ERROR "Failed to find protobuf headers")
endif()
file(STRINGS "${PROTOBUF_INCLUDE_DIRS}/google/protobuf/stubs/common.h" Found
REGEX "#define GOOGLE_PROTOBUF_VERSION 2004001")
if(NOT Found)
message(FATAL_ERROR "Didn't find v2.4.1 of protobuf")
endif()
or for option 2:
find_package(Protobuf ${PROTOBUF_VERSION} REQUIRED)
if(NOT PROTOBUF_PROTOC_EXECUTABLE)
message(FATAL_ERROR "Failed to find protoc")
endif()
execute_process(COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --version
OUTPUT_VARIABLE VersionInfo)
string(FIND "${VersionInfo}" "2.4.1" Found)
if(Found LESS 0)
message(FATAL_ERROR "Didn't find v2.4.1 of protobuf")
endif()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With