0

How does PROTOBUF_GENERATE_CPP know where to pick up the protoc binary from?

I have compiled protobuf locally and would like to point my CMakeLists.txt to the installed binary ( myfolder/protobuf-install/bin/protoc ) and not the system binary ( /usr/bin/protoc )

Normally for Boost, I would just set the BOOST_ROOT to my installed folder and it will find all the include_directories, libraries, etc.

How should it be done for Protobuf. I dont see any prefix option in the FindProtobuf.cmake.

set( Protobuf_SRC_ROOT_FOLDER "${CMAKE_SOURCE_DIR}/myfolder/")
find_package(Protobuf MODULE REQUIRED)

The error is

file STRINGS file "/usr/include/google/protobuf/stubs/common.h" cannot be read.
Call Stack (most recent call first):
CMakeLists.txt:17 (find_package)

Ofcourse, the above path is in myfolder/ and not in the system folder. But why is protobuf looking for includes in the system path, when I have explicitly declared the root path as myfolder/

infoclogged
  • 3,641
  • 5
  • 32
  • 53

1 Answers1

0

Module FindProtobuf.cmake has a nice description of how to hint it with various things. E.g., hinting with executable could be performed with setting Protobuf_PROTOC_EXECUTABLE variable:

The following cache variables are also available to set or use:

...

Protobuf_PROTOC_EXECUTABLE

The protoc compiler

cmake -DProtobuf_PROTOC_EXECUTABLE=myfolder/protobuf-install/bin/protoc

Also, common CMAKE_PREFIX_PATH variable works well, see that question: Hinting Find<name>.cmake Files with a custom directory.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • I have modfified the question a little bit. the source of the problem starts with the include folder and not the binary. – infoclogged Jul 22 '17 at 13:15
  • Neither of these does anything for my build. set(Protobuf_PROTOC_EXECUTABLE ${grpc_SOURCE_DIR}/bin/protoc) CMake Error at /usr/share/cmake3/Modules/FindPackageHandleStandardArgs.cmake:164 (message): Could NOT find Protobuf (missing: Protobuf_PROTOC_EXECUTABLE) (found version "3.13.0.0") – Christopher Pisz Nov 02 '20 at 22:55
  • `Protobuf_PROTOC_EXECUTABLE` should be a **CACHE** variable: Either set it in the command line with `-D` option or set it in `CMakeLists.txt` with CACHE option (see [documentation](https://cmake.org/cmake/help/v3.9/command/set.html#set-cache-entry)). – Tsyvarev Nov 02 '20 at 23:05