简体   繁体   English

cmake 问题与 FetchContent 相同的 protobuf 依赖关系在 grpc 和 or-tools 之间

[英]cmake issue with FetchContent same protobuf dependency between grpc and or-tools

im using the FetchContent from cmake to manage my dependencies我使用 cmake 中的 FetchContent 来管理我的依赖项

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)

the problem is that both or-tools and grpc use protobuf internally too as FetchContent_Declare so the OR-TOOLS complains about that protobuf already exists问题是 or-tools 和 grpc 在内部也使用 protobuf 作为 FetchContent_Declare 所以 OR-TOOLS 抱怨 protobuf 已经存在

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) 

if I try to disable the protobuf for or-tools set(BUILD_Protobuf OFF), the or-tools complan aboud package protobuf is not found如果我尝试禁用 or-tools set(BUILD_Protobuf OFF) 的 protobuf,则找不到 or-tools complan aboud package protobuf

--   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

how can avoid this issue or make the package protobuf available from the previous protobuf FetchContent_Declare?如何避免这个问题或使包 protobuf 从以前的 protobuf FetchContent_Declare 可用?

thanks!谢谢!

cross posting... already answered here: https://github.com/google/or-tools/issues/2219交叉发布......已经在这里回答: https : //github.com/google/or-tools/issues/2219

modify deps.cmake (or cpp.cmake on stable v8.0) to将 deps.cmake(或稳定版 v8.0 上的 cpp.cmake)修改为

if(NOT BUILD_Protobuf AND NOT TARGET protobuf::libprotobuf)
  find_package(Protobuf REQUIRED)
endif()

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM