From b044cfbf1509ff45b2d4b0f518dadd8ad7c05046 Mon Sep 17 00:00:00 2001 From: iphydf Date: Thu, 18 Aug 2016 10:29:39 +0100 Subject: Fix windows build. The threading networking functions (on windows: winsock and friends) need to be linked into the toxnetwork library, not the toxcore library, anymore. On Linux and OSX, there is no winsock. On OSX, there is no need to link against threading libraries, and on Linux, toxnetwork can have unresolved symbols when linking, so this failure wasn't caught before. Tested by building on the iphydf/windows-x86-qt5 docker image. --- CMakeLists.txt | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index bed16d26..25c8ed15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,6 +96,16 @@ endif() # ################################################################################ +# toxcore_PKGCONFIG_LIBS is what's added to the Libs: line in toxcore.pc. It +# needs to contain all the libraries a program using toxcore should link against +# if it's statically linked. If it's dynamically linked, there is no need to +# explicitly link against all the dependencies, but it doesn't harm much(*) +# either. +# +# (*) It allows client code to use symbols from our dependencies without +# explicitly linking against them. +set(toxcore_PKGCONFIG_LIBS) + # LAYER 1: Crypto core # -------------------- add_library(toxcrypto ${LIBTYPE} @@ -109,11 +119,22 @@ add_library(toxnetwork ${LIBTYPE} toxcore/network.c toxcore/util.c) target_link_libraries(toxnetwork toxcrypto) + +if(CMAKE_THREAD_LIBS_INIT) + target_link_libraries(toxnetwork ${CMAKE_THREAD_LIBS_INIT}) + set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} "-l${CMAKE_THREAD_LIBS_INIT}") +endif() + if(RT_LIBRARIES) target_link_libraries(toxnetwork ${RT_LIBRARIES}) set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} "-lrt") endif() +if(WIN32) + target_link_libraries(toxnetwork ws2_32 iphlpapi) + set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} "-lws2_32 -liphlpapi") +endif() + # LAYER 3: Distributed Hash Table # ------------------------------- add_library(toxdht ${LIBTYPE} @@ -162,15 +183,6 @@ add_library(toxcore ${LIBTYPE} toxcore/tox.c) target_link_libraries(toxcore toxgroup) -target_link_libraries(toxcore ${CMAKE_THREAD_LIBS_INIT}) -if(CMAKE_THREAD_LIBS_INIT) - set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} "-l${CMAKE_THREAD_LIBS_INIT}") -endif() - -if(WIN32) - target_link_libraries(toxcore ws2_32 iphlpapi) -endif() - ################################################################################ # -- cgit v1.2.3