Skip to content

Commit

Permalink
Bug#36678092 Contribution: Build failure with Protobuf 22+ in Linux
Browse files Browse the repository at this point in the history
Add explicit INTERFACE_LINK_LIBRARIES for "system" protobuf on Linux.
This will be essential when building with protobuf version 22+

The patch is based on a contribution by Github user: gordonwwang

Change-Id: I5bc0932144f3ad0b340e383d0ce8afdda821874b
(cherry picked from commit d31d3aa0b3623061b012f596e25df08a7f294973)
  • Loading branch information
Tor Didriksen committed Jun 10, 2024
1 parent 115ca6d commit 941e4ac
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
21 changes: 21 additions & 0 deletions cmake/fileutils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,27 @@ IF(APPLE)
ENDIF(APPLE)

IF(LINUX)
# Parse output of 'ldd ${FILE_NAME}' and return anything starting with lib.
FUNCTION(FIND_LIBRARY_DEPENDENCIES FILE_NAME RETURN_VALUE)
SET(${RETURN_VALUE} PARENT_SCOPE)
EXECUTE_PROCESS(COMMAND
ldd "${FILE_NAME}"
OUTPUT_VARIABLE LDD_OUTPUT
RESULT_VARIABLE LDD_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
STRING(REPLACE "\n" ";" LDD_OUTPUT_LIST "${LDD_OUTPUT}")
SET(DEPENDENCIES)
FOREACH(LINE ${LDD_OUTPUT_LIST})
STRING(REGEX MATCH "^[\t ]+(lib[-+_A-Za-z0-9\\.]+).*" UNUSED ${LINE})
IF(CMAKE_MATCH_1)
# MESSAGE(STATUS "xxx ${FILE_NAME} ${CMAKE_MATCH_1}")
LIST(APPEND DEPENDENCIES ${CMAKE_MATCH_1})
ENDIF()
ENDFOREACH()
SET(${RETURN_VALUE} ${DEPENDENCIES} PARENT_SCOPE)
ENDFUNCTION(FIND_LIBRARY_DEPENDENCIES)

FUNCTION(FIND_OBJECT_DEPENDENCIES FILE_NAME RETURN_VALUE)
SET(${RETURN_VALUE} PARENT_SCOPE)
EXECUTE_PROCESS(COMMAND
Expand Down
18 changes: 18 additions & 0 deletions cmake/protobuf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -155,23 +155,41 @@ MACRO(MYSQL_CHECK_PROTOBUF)
# set_property(TARGET protobuf::libprotobuf APPEND PROPERTY
# INTERFACE_COMPILE_FEATURES cxx_std_11
# )
# INTERFACE_LINK_LIBRARIES will be needed once this is built
# with protobuf 22 and above (lots of abseil libs).
ADD_LIBRARY(ext::libprotobuf UNKNOWN IMPORTED)
SET_TARGET_PROPERTIES(ext::libprotobuf PROPERTIES
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${Protobuf_INCLUDE_DIR}")
SET_TARGET_PROPERTIES(ext::libprotobuf PROPERTIES
IMPORTED_LOCATION "${PROTOBUF_LIBRARY}")
IF(LINUX)
FIND_LIBRARY_DEPENDENCIES("${PROTOBUF_LIBRARY}" protobuf_dependencies)
SET_TARGET_PROPERTIES(ext::libprotobuf PROPERTIES
INTERFACE_LINK_LIBRARIES "${protobuf_dependencies}")
ENDIF()

ADD_LIBRARY(ext::libprotobuf-lite UNKNOWN IMPORTED)
SET_TARGET_PROPERTIES(ext::libprotobuf-lite PROPERTIES
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${Protobuf_INCLUDE_DIR}")
SET_TARGET_PROPERTIES(ext::libprotobuf-lite PROPERTIES
IMPORTED_LOCATION "${PROTOBUF_LITE_LIBRARY}")
IF(LINUX)
FIND_LIBRARY_DEPENDENCIES("${PROTOBUF_LITE_LIBRARY}" lite_dependencies)
SET_TARGET_PROPERTIES(ext::libprotobuf-lite PROPERTIES
INTERFACE_LINK_LIBRARIES "${lite_dependencies}")
ENDIF()

ADD_LIBRARY(ext::libprotoc UNKNOWN IMPORTED)
SET_TARGET_PROPERTIES(ext::libprotoc PROPERTIES
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${Protobuf_INCLUDE_DIR}")
SET_TARGET_PROPERTIES(ext::libprotoc PROPERTIES
IMPORTED_LOCATION "${Protobuf_PROTOC_LIBRARY}")
IF(LINUX)
FIND_LIBRARY_DEPENDENCIES(
"${Protobuf_PROTOC_LIBRARY}" protoc_dependencies)
SET_TARGET_PROPERTIES(ext::libprotoc PROPERTIES
INTERFACE_LINK_LIBRARIES "${protoc_dependencies}")
ENDIF()
ENDIF()

FIND_PROTOBUF_VERSION()
Expand Down

0 comments on commit 941e4ac

Please sign in to comment.