我有 cmake 3.10.x 并下载了当前的 protobuf 源 3.6.1。使用 cmake 我创建了 bin 目录“{PROTOBUF_SOURCE_DIR}/bin”,在其中成功构建了该库。下一步我想在我的基于 cmake 的项目中使用这个自定义树。我有
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 找到必要的东西。
如果我使用find_package( Protobuf REQUIRED PATHS ${PROTOBUF_ROOT}/bin/lib/cmake/protobuf )
然后我看到 cmake 的以下输出:
Protobuf version : 3.6.1
Protobuf include path :
Protobuf libraries :
如何让 cmake 找到包含路径、库和协议编译器?
最后我找到了一个解决方案 - 也许它会为其他人节省很多时间
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()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)