Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cmake : find protobuf package in custom directory

I have cmake 3.10.x and downloaded current protobuf sources 3.6.1. Using cmake I created bin directory "{PROTOBUF_SOURCE_DIR}/bin" where this library is successfully built. As the next step I would like to use this custom tree in my cmake based project. I have

set ( Protobuf_USE_STATIC_LIBS ON )

find_package( Protobuf REQUIRED )
if ( Protobuf_FOUND )
    message( STATUS "Protobuf version : ${Protobuf_VERSION}" )
    message( STATUS "Protobuf include path : ${Protobuf_INCLUDE_DIRS}" )
    message( STATUS "Protobuf libraries : ${Protobuf_LIBRARIES}" )
else()
    message( WARNING "Protobuf package not found -> specify search path via PROTOBUF_ROOT variable")
endif()

But how to specify my custom directory tree for cmake to find the necessary stuff.

If I use find_package( Protobuf REQUIRED PATHS ${PROTOBUF_ROOT}/bin/lib/cmake/protobuf ) then I see the following output from cmake :

Protobuf version : 3.6.1
Protobuf include path : 
Protobuf libraries :

How can I make cmake to find include paths, libraries and protoc compiler?

like image 469
Dmitry Avatar asked Dec 06 '18 12:12

Dmitry


2 Answers

Finally I've got a solution - maybe it would save a lot of time for someone else

set ( Protobuf_USE_STATIC_LIBS ON )

include(${PROTOBUF_ROOT}/bin/lib/cmake/protobuf/protobuf-config.cmake)
include(${PROTOBUF_ROOT}/bin/lib/cmake/protobuf/protobuf-module.cmake)
include(${PROTOBUF_ROOT}/bin/lib/cmake/protobuf/protobuf-options.cmake)
include(${PROTOBUF_ROOT}/bin/lib/cmake/protobuf/protobuf-targets.cmake)

find_package( Protobuf REQUIRED HINTS ${PROTOBUF_ROOT}/bin/lib/cmake/protobuf )
if ( Protobuf_FOUND )
    message( STATUS "Protobuf version : ${Protobuf_VERSION}" )
    message( STATUS "Protobuf include path : ${Protobuf_INCLUDE_DIRS}" )
    message( STATUS "Protobuf libraries : ${Protobuf_LIBRARIES}" )
    message( STATUS "Protobuf compiler libraries : ${Protobuf_PROTOC_LIBRARIES}")
    message( STATUS "Protobuf lite libraries : ${Protobuf_LITE_LIBRARIES}")
else()
    message( WARNING "Protobuf package not found -> specify search path via PROTOBUF_ROOT variable")
endif()
like image 80
Dmitry Avatar answered Sep 22 '22 21:09

Dmitry


This worked for me well pointing to my custom Windows static build:

set(Protobuf_USE_STATIC_LIBS ON)
# add parent directory containing bin/protoc.exe, cmake/protobuf-config.cmake, lib/libprotobufd.lib (or .a), etc.
list(APPEND CMAKE_PREFIX_PATH "/dir/where/protobuf/was/installed")
find_package(Protobuf REQUIRED)

Setting Protobuf_DIR or Protobuf_ROOT did NOT work for some reason.

like image 21
Darien Pardinas Avatar answered Sep 25 '22 21:09

Darien Pardinas