我想在我的protobuf
库中使用C++。到目前为止,所有依赖项都是使用cmake的FetchContent
模块包含的。我也想对protobuf
做同样的事情。但是,我遇到了以下问题:Unknown CMake command "protobuf_generate_cpp".
--关于如何解决这个问题的任何提示?
我的CMakeLists.txt
节选
FetchContent_Declare(fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 9.0.0)
FetchContent_Declare(protobuf
GIT_REPOSITORY https://github.com/protocolbuffers/protobuf.git
GIT_TAG v21.4)
FetchContent_MakeAvailable(fmt protobuf)
include_directories(${Protobuf_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS message.proto)
发布于 2022-11-23 10:21:28
这对我来说很管用:
FetchContent_Declare(protobuf
GIT_REPOSITORY https://github.com/protocolbuffers/protobuf.git
GIT_TAG v21.4
SOURCE_SUBDIR cmake
FIND_PACKAGE_ARGS NAMES protobuf
)
FetchContent_MakeAvailable(protobuf)
在消费者端做这件事
include(FindProtobuf)
find_package(protobuf CONFIG REQUIRED)
注意:这只在CMake v3.25上进行了测试
https://stackoverflow.com/questions/73208290
复制相似问题