Skip to content

Commit 4518e0c

Browse files
authored
Merge pull request #2889 from SalvoVirga/fix/libzmq-static-cmake
Correct linking for libzmq-static
2 parents 2540e1a + 9d6a5f3 commit 4518e0c

File tree

1 file changed

+38
-14
lines changed

1 file changed

+38
-14
lines changed

CMakeLists.txt

+38-14
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ elseif (WITH_LIBSODIUM)
4343
if (SODIUM_FOUND)
4444
message (STATUS "Using libsodium for CURVE security")
4545
include_directories (${SODIUM_INCLUDE_DIRS})
46-
47-
# On Solaris, libsodium depends on libssp
48-
if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
49-
target_link_libraries (libzmq ssp)
50-
endif ()
5146
set (ZMQ_USE_LIBSODIUM 1)
5247
set (ZMQ_HAVE_CURVE 1)
5348
set (pkg_config_libs_private "${pkg_config_libs_private} -lsodium")
@@ -764,7 +759,6 @@ if (MSVC)
764759
set( CMAKE_STATIC_LINKER_FLAGS /ignore:4221 )
765760
if (BUILD_SHARED)
766761
add_library (libzmq SHARED ${sources} ${public_headers} ${html-docs} ${readme-docs} ${CMAKE_CURRENT_BINARY_DIR}/NSIS.template.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
767-
target_link_libraries (libzmq ${OPTIONAL_LIBRARIES})
768762
set_target_properties (libzmq PROPERTIES
769763
PUBLIC_HEADER "${public_headers}"
770764
RELEASE_POSTFIX "${MSVC_TOOLSET}-mt-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
@@ -798,7 +792,6 @@ else ()
798792

799793
if (BUILD_SHARED)
800794
add_library (libzmq SHARED $<TARGET_OBJECTS:objects> ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig} ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
801-
target_link_libraries (libzmq ${OPTIONAL_LIBRARIES})
802795
# NOTE: the SOVERSION and VERSION MUST be the same as the one generated by libtool! It is NOT the same as the version of the package.
803796
set_target_properties (libzmq PROPERTIES
804797
COMPILE_DEFINITIONS "DLL_EXPORT"
@@ -849,11 +842,16 @@ foreach (target ${target_outputs})
849842
endforeach()
850843

851844
if (BUILD_SHARED)
852-
target_link_libraries (libzmq ${CMAKE_THREAD_LIBS_INIT})
853-
845+
target_link_libraries (libzmq ${OPTIONAL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
846+
854847
if (SODIUM_FOUND)
855848
target_link_libraries (libzmq ${SODIUM_LIBRARIES})
849+
# On Solaris, libsodium depends on libssp
850+
if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
851+
target_link_libraries (libzmq ssp)
852+
endif ()
856853
endif ()
854+
857855
if (HAVE_WS2_32)
858856
target_link_libraries (libzmq ws2_32)
859857
elseif (HAVE_WS2)
@@ -873,6 +871,36 @@ if (BUILD_SHARED)
873871
endif ()
874872
endif ()
875873

874+
if (BUILD_STATIC)
875+
target_link_libraries (libzmq-static ${OPTIONAL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
876+
877+
if (SODIUM_FOUND)
878+
target_link_libraries (libzmq-static ${SODIUM_LIBRARIES})
879+
# On Solaris, libsodium depends on libssp
880+
if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
881+
target_link_libraries (libzmq-static ssp)
882+
endif ()
883+
endif ()
884+
885+
if (HAVE_WS2_32)
886+
target_link_libraries (libzmq-static ws2_32)
887+
elseif (HAVE_WS2)
888+
target_link_libraries (libzmq-static ws2)
889+
endif ()
890+
891+
if (HAVE_RPCRT4)
892+
target_link_libraries (libzmq-static rpcrt4)
893+
endif ()
894+
895+
if (HAVE_IPHLAPI)
896+
target_link_libraries (libzmq-static iphlpapi)
897+
endif ()
898+
899+
if (RT_LIBRARY)
900+
target_link_libraries (libzmq-static -lrt)
901+
endif ()
902+
endif ()
903+
876904
if (BUILD_SHARED)
877905
set (perf-tools local_lat
878906
remote_lat
@@ -890,11 +918,7 @@ if (BUILD_SHARED)
890918
if (WITH_PERF_TOOL)
891919
foreach (perf-tool ${perf-tools})
892920
add_executable (${perf-tool} perf/${perf-tool}.cpp)
893-
target_link_libraries (${perf-tool} libzmq ${OPTIONAL_LIBRARIES})
894-
895-
if (RT_LIBRARY)
896-
target_link_libraries (${perf-tool} -lrt)
897-
endif ()
921+
target_link_libraries (${perf-tool} libzmq)
898922

899923
if (ZMQ_BUILD_FRAMEWORK)
900924
# Copy perf-tools binaries into Framework

0 commit comments

Comments
 (0)