From 2f628a03d76ccfd2c41d42c6bd81789a5e4064f5 Mon Sep 17 00:00:00 2001 From: jkhsjdhjs Date: Thu, 24 Aug 2023 08:51:50 +0200 Subject: [PATCH] Fix linking with Protobuf 23 (#4104) Google introduced abseil as a new dependency of Protobuf, but CMake's FindProtobuf hasn't been updated yet to link with abseil. Thus, CMake is now advised to use the config provided by Protobuf instead of its own. In case no config can be found, we fall back to the old behavior. The Protobuf version constraint is removed since it only applies with `P4C_USE_PREINSTALLED_PROTOBUF=ON` anyway, in which case we'll want to use whatever preinstalled version is available. Furthermore, the variables `PROTOBUF_LIBRARY` and `PROTOBUF_PROTOC_EXECUTABLE` are set correctly so executing `protoc` and linking with Protobuf doesn't fail. Fix #4055 See also https://github.com/protocolbuffers/protobuf/issues/12292 --- cmake/Protobuf.cmake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmake/Protobuf.cmake b/cmake/Protobuf.cmake index 943cf37b074..31c9c16a4ca 100644 --- a/cmake/Protobuf.cmake +++ b/cmake/Protobuf.cmake @@ -11,10 +11,15 @@ macro(p4c_obtain_protobuf) set(SAVED_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) set(CMAKE_FIND_LIBRARY_SUFFIXES .a) endif() - find_package(Protobuf 3.0.0 REQUIRED) + find_package(Protobuf CONFIG) + if(NOT Protobuf_FOUND) + find_package(Protobuf REQUIRED) + endif() if(ENABLE_PROTOBUF_STATIC) set(CMAKE_FIND_LIBRARY_SUFFIXES ${SAVED_CMAKE_FIND_LIBRARY_SUFFIXES}) endif() + set(PROTOBUF_LIBRARY "protobuf::libprotobuf") + set(PROTOBUF_PROTOC_EXECUTABLE "protobuf::protoc") else() # Google introduced another breaking change with protobuf 22.x by adding abseil as a new # dependency. https://protobuf.dev/news/2022-08-03/#abseil-dep We do not want abseil, so we stay