@@ -23,6 +23,22 @@ if (VCPKG_TRIPLET)
2323 set (CMAKE_PREFIX_PATH "${PROJECT_SOURCE_DIR} /vcpkg_installed/${VCPKG_TRIPLET} " )
2424 message (STATUS "Use CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH} " )
2525 set (PROTOC_PATH "${CMAKE_PREFIX_PATH} /tools/protobuf/protoc" )
26+ if (MSVC )
27+ # vcpkg host tools (protoc, etc.) are always built for the host machine
28+ # architecture (x64 on GitHub Actions), regardless of the target triplet.
29+ # Use find_program to locate protoc.exe across known host tool paths.
30+ find_program (PROTOC_PATH NAMES protoc.exe
31+ PATHS
32+ "${PROJECT_SOURCE_DIR} /vcpkg_installed/x64-windows/tools/protobuf"
33+ "${PROJECT_SOURCE_DIR} /vcpkg_installed/arm64-windows/tools/protobuf"
34+ "${PROJECT_SOURCE_DIR} /vcpkg_installed/${VCPKG_TRIPLET} /tools/protobuf"
35+ NO_DEFAULT_PATH)
36+ if (NOT PROTOC_PATH)
37+ set (PROTOC_PATH "${CMAKE_PREFIX_PATH} /tools/protobuf/protoc.exe" )
38+ endif ()
39+ # Set the cache variable so protobuf's CMake module compatibility shim finds it
40+ set (Protobuf_PROTOC_EXECUTABLE "${PROTOC_PATH} " CACHE FILEPATH "protoc executable" FORCE)
41+ endif ()
2642 message (STATUS "Use protoc: ${PROTOC_PATH} " )
2743 set (VCPKG_ROOT "${PROJECT_SOURCE_DIR} /vcpkg_installed/${VCPKG_TRIPLET} " )
2844 set (VCPKG_DEBUG_ROOT "${VCPKG_ROOT} /debug" )
@@ -51,6 +67,10 @@ if (APPLE AND NOT LINK_STATIC)
5167 # The latest Protobuf dependency on macOS requires the C++17 support and
5268 # it could only be found by the CONFIG mode
5369 set (LATEST_PROTOBUF TRUE )
70+ elseif (MSVC AND VCPKG_TRIPLET)
71+ # protobuf >= 6.x on Windows with vcpkg requires CONFIG mode to resolve
72+ # the protobuf::libprotobuf CMake target and its abseil dependencies
73+ set (LATEST_PROTOBUF TRUE )
5474else ()
5575 set (LATEST_PROTOBUF FALSE )
5676endif ()
@@ -83,8 +103,13 @@ message("OPENSSL_INCLUDE_DIR: " ${OPENSSL_INCLUDE_DIR})
83103message ("OPENSSL_LIBRARIES: " ${OPENSSL_LIBRARIES} )
84104
85105if (LATEST_PROTOBUF)
86- # See https://github.com/apache/arrow/issues/35987
87- add_definitions (-DPROTOBUF_USE_DLLS)
106+ if (NOT LINK_STATIC)
107+ # Only needed when protobuf itself is a DLL; static builds must NOT define this
108+ # because it marks symbols as __declspec(dllimport), causing LNK2019 when
109+ # linking against a static libprotobuf.lib.
110+ # See https://github.com/apache/arrow/issues/35987
111+ add_definitions (-DPROTOBUF_USE_DLLS)
112+ endif ()
88113 # Use Config mode to avoid FindProtobuf.cmake does not find the Abseil library
89114 find_package (Protobuf REQUIRED CONFIG)
90115else ()
@@ -127,8 +152,10 @@ if (LINK_STATIC AND NOT VCPKG_TRIPLET)
127152 add_definitions (-DCURL_STATICLIB)
128153 endif ()
129154elseif (LINK_STATIC AND VCPKG_TRIPLET)
130- find_package (Protobuf REQUIRED)
131- message (STATUS "Found protobuf static library: " ${Protobuf_LIBRARIES} )
155+ if (NOT LATEST_PROTOBUF)
156+ find_package (Protobuf REQUIRED)
157+ message (STATUS "Found protobuf static library: " ${Protobuf_LIBRARIES} )
158+ endif ()
132159 if (MSVC AND (${CMAKE_BUILD_TYPE} STREQUAL Debug))
133160 find_library (ZLIB_LIBRARIES NAMES zlibd)
134161 else ()
@@ -264,8 +291,8 @@ if (MSVC)
264291 wldap32.lib
265292 Normaliz.lib)
266293 if (LINK_STATIC)
267- # add external dependencies of libcurl
268- set (COMMON_LIBS ${COMMON_LIBS} ws2_32.lib crypt32.lib)
294+ # add external dependencies of libcurl (iphlpapi for if_nametoindex)
295+ set (COMMON_LIBS ${COMMON_LIBS} ws2_32.lib crypt32.lib iphlpapi.lib )
269296 # the default compile options have /MD, which cannot be used to build DLLs that link static libraries
270297 string (REGEX REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG} )
271298 string (REGEX REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} )
@@ -279,6 +306,23 @@ if (MSVC)
279306 message (STATUS "CMAKE_CXX_FLAGS_RELEASE: " ${CMAKE_CXX_FLAGS_RELEASE} )
280307 message (STATUS "CMAKE_CXX_FLAGS_RELWITHDEBINFO: " ${CMAKE_CXX_FLAGS_RELWITHDEBINFO} )
281308 endif ()
309+ if (VCPKG_TRIPLET)
310+ # protobuf >= 6.x requires abseil; link it explicitly since MSVC static
311+ # linking does not resolve transitive dependencies automatically
312+ find_package (absl CONFIG REQUIRED)
313+ set (COMMON_LIBS ${COMMON_LIBS}
314+ absl::base
315+ absl::log
316+ absl::log_internal_message
317+ absl::log_internal_check_op
318+ absl::status
319+ absl::statusor
320+ absl::strings
321+ absl::str_format
322+ absl::time
323+ absl::synchronization
324+ absl::cord)
325+ endif ()
282326else ()
283327 set (COMMON_LIBS ${COMMON_LIBS} m)
284328endif ()
0 commit comments