问题
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?
回答1:
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()
来源:https://stackoverflow.com/questions/53651181/cmake-find-protobuf-package-in-custom-directory