Skip to content

Commit b778df9

Browse files
committed
fix windows build
1 parent bce7c7d commit b778df9

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

LegacyFindPackages.cmake

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ if (APPLE AND NOT LINK_STATIC)
5151
# The latest Protobuf dependency on macOS requires the C++17 support and
5252
# it could only be found by the CONFIG mode
5353
set(LATEST_PROTOBUF TRUE)
54+
elseif (MSVC AND VCPKG_TRIPLET)
55+
# protobuf >= 6.x on Windows with vcpkg requires CONFIG mode to resolve
56+
# the protobuf::libprotobuf CMake target and its abseil dependencies
57+
set(LATEST_PROTOBUF TRUE)
5458
else ()
5559
set(LATEST_PROTOBUF FALSE)
5660
endif ()
@@ -127,8 +131,10 @@ if (LINK_STATIC AND NOT VCPKG_TRIPLET)
127131
add_definitions(-DCURL_STATICLIB)
128132
endif()
129133
elseif (LINK_STATIC AND VCPKG_TRIPLET)
130-
find_package(Protobuf REQUIRED)
131-
message(STATUS "Found protobuf static library: " ${Protobuf_LIBRARIES})
134+
if (NOT LATEST_PROTOBUF)
135+
find_package(Protobuf REQUIRED)
136+
message(STATUS "Found protobuf static library: " ${Protobuf_LIBRARIES})
137+
endif ()
132138
if (MSVC AND (${CMAKE_BUILD_TYPE} STREQUAL Debug))
133139
find_library(ZLIB_LIBRARIES NAMES zlibd)
134140
else ()
@@ -279,6 +285,23 @@ if (MSVC)
279285
message(STATUS "CMAKE_CXX_FLAGS_RELEASE: " ${CMAKE_CXX_FLAGS_RELEASE})
280286
message(STATUS "CMAKE_CXX_FLAGS_RELWITHDEBINFO: " ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
281287
endif ()
288+
if (VCPKG_TRIPLET)
289+
# protobuf >= 6.x requires abseil; link it explicitly since MSVC static
290+
# linking does not resolve transitive dependencies automatically
291+
find_package(absl CONFIG REQUIRED)
292+
set(COMMON_LIBS ${COMMON_LIBS}
293+
absl::base
294+
absl::log
295+
absl::log_internal_message
296+
absl::log_internal_check_op
297+
absl::status
298+
absl::statusor
299+
absl::strings
300+
absl::str_format
301+
absl::time
302+
absl::synchronization
303+
absl::cord)
304+
endif ()
282305
else()
283306
set(COMMON_LIBS ${COMMON_LIBS} m)
284307
endif()

0 commit comments

Comments
 (0)