From ecbc65028fd205821cb5f55f4fd70fb4e4d969f5 Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Fri, 24 May 2024 02:16:07 +0200 Subject: [PATCH] Conditionally link protobuf to its dependencies in Debug mode This is a workaround to the issue of certain versions of protobuf not advertising their dependencies when using `find_package(Protobuf)`. --- CMakeLists.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index a22d32316..09eed123f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2621,6 +2621,15 @@ if(((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSI endif() else() find_package(Protobuf) + + if((CMAKE_BUILD_TYPE STREQUAL "Debug") AND Protobuf_FOUND AND absl_FOUND) + string(REGEX REPLACE "^[0-9]+\.([0-9]+\.[0-9]+)$" "\\1.0" PROTOBUF_LIBRARY_VERSION "${Protobuf_VERSION}") + if((PROTOBUF_LIBRARY_VERSION VERSION_GREATER_EQUAL "22") AND (PROTOBUF_LIBRARY_VERSION VERSION_LESS "26")) + find_package(PkgConfig REQUIRED) + pkg_check_modules(protobuf REQUIRED IMPORTED_TARGET protobuf=${PROTOBUF_LIBRARY_VERSION}) + target_link_libraries(protobuf::libprotobuf INTERFACE PkgConfig::protobuf) + endif() + endif() endif() set_package_properties(Protobuf PROPERTIES URL "https://protobuf.dev/"