首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >cmake问题在FetchContent和or-tools之间存在相同的协议依赖

cmake问题在FetchContent和or-tools之间存在相同的协议依赖
EN

Stack Overflow用户
提问于 2020-11-10 22:02:08
回答 1查看 730关注 0票数 0

我正在使用cmake中的FetchContent来管理我的依赖项

代码语言:javascript
复制
FetchContent_Declare(
        protobuf
        GIT_REPOSITORY https://github.com/protocolbuffers/protobuf.git
        GIT_TAG        v3.13.0
        SOURCE_SUBDIR  cmake
)
## END PROTOBUF ##

## GRPC ##
FetchContent_Declare(
        grpc
        GIT_REPOSITORY https://github.com/grpc/grpc.git
        GIT_TAG        v1.33.x
        GIT_PROGRESS   TRUE
)
## END GRPC ##

## OR-TOOLS ##
FetchContent_Declare(
        or-tools
        GIT_REPOSITORY https://github.com/google/or-tools.git
        GIT_TAG        master
        GIT_PROGRESS   TRUE
        PATCH_COMMAND git apply "${PROJECT_SOURCE_DIR}/patches/or-tools-protobuf.patch"
)
FetchContent_MakeAvailable(protobuf grpc or-tools)

问题是or-tools和grpc在内部也使用protobuf作为FetchContent_Declare,因此OR-TOOLS会抱怨protobuf已经存在

代码语言:javascript
复制
CMake Error at build/_deps/protobuf-src/cmake/libprotobuf-lite.cmake:64 (add_library):
  add_library cannot create target "libprotobuf-lite" because another target
  with the same name already exists.  The existing target is a static library
  created in source directory
  "/Users/samuaz/Projects/itbit/securities-settlement/cpp/third_party/grpc-src/third_party/protobuf/cmake".
  See documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  build/_deps/protobuf-src/cmake/CMakeLists.txt:250 (include) 

如果我尝试为或-tools集(BUILD_Protobuf关闭)禁用protobuf,则找不到或-tools complan aboud包protobuf

代码语言:javascript
复制
--   No package 'protobuf' found
CMake Error at /Users/samuaz/Library/Application Support/JetBrains/Toolbox/apps/CLion/ch-0/202.6948.80/CLion.app/Contents/bin/cmake/mac/share/cmake-3.17/Modules/FindPkgConfig.cmake:497 (message):
  A required package was not found

怎样才能避免这个问题,或者让protobuf包在之前的protobuf FetchContent_Declare中可用?

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-11 04:58:44

交叉过帐...已经在这里回答了:https://github.com/google/or-tools/issues/2219

将deps.cmake (或稳定v8.0上的cpp.cmake )修改为

代码语言:javascript
复制
if(NOT BUILD_Protobuf AND NOT TARGET protobuf::libprotobuf)
  find_package(Protobuf REQUIRED)
endif()

相关:https://gitlab.kitware.com/cmake/cmake/-/issues/17735

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64770392

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档