CMake:在自定义目录中找到protobuf软件包 [英] Cmake : find protobuf package in custom directory
问题描述
我有cmake 3.10.x,并下载了当前的protobuf源码3.6.1。我使用cmake创建了bin目录 {PROTOBUF_SOURCE_DIR} / bin,此库已成功建立。下一步,我想在基于cmake的项目中使用此自定义树。我有
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()
但是如何为cmake指定我的自定义目录树以查找必要的内容。
But how to specify my custom directory tree for cmake to find the necessary stuff.
如果我使用 find_package(Protobuf所需路径$ {PROTOBUF_ROOT} / bin / lib / cmake / protobuf)
我从cmake看到以下输出:
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 :
我如何使cmake查找包含路径,库和protoc编译器?
How can I make cmake to find include paths, libraries and protoc compiler?
推荐答案
最后我有了一个解决方案-也许它将为其他人节省很多时间
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()
这篇关于CMake:在自定义目录中找到protobuf软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!