Skip to content

Commit

Permalink
Fix linking with Protobuf 23
Browse files Browse the repository at this point in the history
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 p4lang#4055
See also protocolbuffers/protobuf#12292
  • Loading branch information
jkhsjdhjs committed Aug 12, 2023
1 parent 6a144da commit 7e656e0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cmake/Protobuf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7e656e0

Please sign in to comment.