Skip to content

Commit a0cc973

Browse files
committed
fix windows build
1 parent 607a530 commit a0cc973

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

LegacyFindPackages.cmake

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,13 @@ message("OPENSSL_INCLUDE_DIR: " ${OPENSSL_INCLUDE_DIR})
9595
message("OPENSSL_LIBRARIES: " ${OPENSSL_LIBRARIES})
9696

9797
if (LATEST_PROTOBUF)
98-
# See https://github.com/apache/arrow/issues/35987
99-
add_definitions(-DPROTOBUF_USE_DLLS)
98+
if (NOT LINK_STATIC)
99+
# Only needed when protobuf itself is a DLL; static builds must NOT define this
100+
# because it marks symbols as __declspec(dllimport), causing LNK2019 when
101+
# linking against a static libprotobuf.lib.
102+
# See https://github.com/apache/arrow/issues/35987
103+
add_definitions(-DPROTOBUF_USE_DLLS)
104+
endif ()
100105
# Use Config mode to avoid FindProtobuf.cmake does not find the Abseil library
101106
find_package(Protobuf REQUIRED CONFIG)
102107
else ()
@@ -278,8 +283,8 @@ if (MSVC)
278283
wldap32.lib
279284
Normaliz.lib)
280285
if (LINK_STATIC)
281-
# add external dependencies of libcurl
282-
set(COMMON_LIBS ${COMMON_LIBS} ws2_32.lib crypt32.lib)
286+
# add external dependencies of libcurl (iphlpapi for if_nametoindex)
287+
set(COMMON_LIBS ${COMMON_LIBS} ws2_32.lib crypt32.lib iphlpapi.lib)
283288
# the default compile options have /MD, which cannot be used to build DLLs that link static libraries
284289
string(REGEX REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
285290
string(REGEX REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})

lib/CMakeLists.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,21 @@ if (LINK_STATIC AND BUILD_STATIC_LIB)
145145
else ()
146146
remove_libtype("${COMMON_LIBS}" "debug" STATIC_LIBS)
147147
endif ()
148-
set_property(TARGET pulsarStaticWithDeps PROPERTY STATIC_LIBRARY_OPTIONS ${STATIC_LIBS})
148+
# lib.exe (STATIC_LIBRARY_OPTIONS) cannot resolve CMake imported target names.
149+
# Replace each CMake target with $<TARGET_FILE:...>; keep only static archives
150+
# (skip system import libs that have no absolute path and non-archive targets).
151+
set(RESOLVED_STATIC_LIBS "")
152+
foreach (LIB IN LISTS STATIC_LIBS)
153+
if (TARGET ${LIB})
154+
get_target_property(_LIB_TYPE ${LIB} TYPE)
155+
if (_LIB_TYPE STREQUAL "STATIC_LIBRARY" OR _LIB_TYPE STREQUAL "UNKNOWN_LIBRARY")
156+
list(APPEND RESOLVED_STATIC_LIBS "$<TARGET_FILE:${LIB}>")
157+
endif ()
158+
elseif (IS_ABSOLUTE "${LIB}" AND LIB MATCHES "\\.(lib|a)$")
159+
list(APPEND RESOLVED_STATIC_LIBS "${LIB}")
160+
endif ()
161+
endforeach ()
162+
set_property(TARGET pulsarStaticWithDeps PROPERTY STATIC_LIBRARY_OPTIONS ${RESOLVED_STATIC_LIBS})
149163
set_property(TARGET pulsarStaticWithDeps PROPERTY OUTPUT_NAME ${LIB_NAME}WithDeps)
150164
set_property(TARGET pulsarStaticWithDeps PROPERTY VERSION ${LIBRARY_VERSION})
151165
install(TARGETS pulsarStaticWithDeps DESTINATION lib)

0 commit comments

Comments
 (0)