3

I'm trying to build a protobuf project on Ubuntu using CMake. Protobuf version 3.5.1 was builded on the same machine successfully. To use this specific version, the flag NO_DEFAULT_PATH is passed to find_package and the new location of the protobuf related cmake files is passed as well.

My current CMakeLists.txt:

set (Protobuf_DIR "/home/ubuntu/Projects/Protobuf/build-host/lib/cmake/protobuf")
find_package(Protobuf REQUIRED NO_DEFAULT_PATH)
message("   --> PROTOBUF LIB: ${PROTOBUF_LIBRARIES}")
message("   --> PROTOBUF INCLUDE: ${PROTOBUF_INCLUDE_DIRS}")
message("   --> PROTOBUF VERSION: ${Protobuf_VERSION}")
message("   --> PROTOBUF Found: ${Protobuf_FOUND}")

The output:

--> PROTOBUF LIB: 
--> PROTOBUF INCLUDE: 
--> PROTOBUF VERSION: 3.5.1
--> PROTOBUF Found: 1

It claims, that protobuf has been found, BUT PROTOBUF_LIBRARIES and PROTOBUF_INCLUDE_DIRS are empty.

How can I solve this? Any hints?

johni07
  • 761
  • 1
  • 11
  • 31
  • 1
    According to [FindProtobuf.cmake](https://cmake.org/cmake/help/v3.9/module/FindProtobuf.html) documentation, it sets `Protobuf_INCLUDE_DIRS` and `Protobuf_LIBRARIES` variable, not their upper-case variant. Moreover, by using `NO_DEFAULT_PATH` option to the `find_package()` call, you trigger using `ProtobufConfig.cmake` file (located under the directory, specified in `Protobuf_DIR` variable) instead of `FindProtobuf.cmake` one provided by CMake. So consult your file `ProtobufConfig.cmake` about which variables it sets. – Tsyvarev Sep 25 '18 at 15:03
  • 1
    If you want to always find Protobuf with `FindProtobuf.cmake` script (which behavior is common for all CMake installations), use simple `find_package(Protobuf REQUIRED)`. You may require minimal version by `find_package(Protobuf 3.5 REQUIRED)`. For specify additional directory for search protobuf, use `list(APPEND CMAKE_PREFIX_PATH "/home/ubuntu/Projects/Protobuf/build-host")`; this directory will have preferences agains system-default ones. – Tsyvarev Sep 25 '18 at 15:09

0 Answers0