From f03dc44e97e993024e42b3a0915de6401d9cecb0 Mon Sep 17 00:00:00 2001
From: Maxim Biro <nurupo.contributions@gmail.com>
Date: Sun, 4 Aug 2013 21:20:48 -0400
Subject: [PATCH] Fixed Windows build

---
 CMakeLists.txt         | 4 ++--
 cmake/FindSODIUM.cmake | 4 +++-
 core/CMakeLists.txt    | 4 ++++
 testing/CMakeLists.txt | 5 ++---
 4 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 07098391..f2657fc5 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -25,11 +25,11 @@ if(NOT WIN32)
 		message(STATUS "==== ${CMAKE_C_COMPILER_ID} detected - Adding compiler flags ====")
 		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror")
 	endif()
-	find_package(SODIUM REQUIRED)
 endif()
 
 if(NOT USE_NACL)
-	 set(LINK_CRYPTO_LIBRARY ${SODIUM_LIBRARY})
+	find_package(SODIUM REQUIRED)
+	set(LINK_CRYPTO_LIBRARY ${SODIUM_LIBRARY})
 endif()
 
 macro(linkCoreLibraries exe_name)
diff --git a/cmake/FindSODIUM.cmake b/cmake/FindSODIUM.cmake
index fd6206ff..ff9bc27b 100644
--- a/cmake/FindSODIUM.cmake
+++ b/cmake/FindSODIUM.cmake
@@ -26,11 +26,12 @@ set(_SODIUM_ROOT_HINTS
 
 set(_SODIUM_ROOT_PATHS
     "$ENV{PROGRAMFILES}/sodium"
+    "${CMAKE_SOURCE_DIR}/sodium"
 )
 
 find_path(SODIUM_ROOT_DIR
     NAMES
-        include/cmocka.h
+        include/sodium.h
     HINTS
         ${_SODIUM_ROOT_HINTS}
     PATHS
@@ -48,6 +49,7 @@ find_path(SODIUM_INCLUDE_DIR
 find_library(SODIUM_LIBRARY
     NAMES
         sodium
+        libsodium.a
     PATHS
         ${SODIUM_ROOT_DIR}/lib
 )
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt
index 5bd496cb..c7016a49 100644
--- a/core/CMakeLists.txt
+++ b/core/CMakeLists.txt
@@ -18,3 +18,7 @@ set(core_sources
 
 add_library(toxcore SHARED ${core_sources})
 target_link_libraries(toxcore ${SODIUM_LIBRARY})
+
+if(WIN32)
+	target_link_libraries(toxcore ws2_32)
+endif()
diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt
index abbc278e..f2a2e95e 100644
--- a/testing/CMakeLists.txt
+++ b/testing/CMakeLists.txt
@@ -8,11 +8,10 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/DHT_test.cmake)
 include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testclient.cmake)
 include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Lossless_UDP_testserver.cmake)
 include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Messenger_test.cmake)
+
 if(WIN32)
 	include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox_win32.cmake)
-endif()
-
-if(NOT WIN32)
+else()
 	include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nTox.cmake)
 	add_subdirectory(toxic)
 endif()