Link to ws2_32 more consistently.

This fixes a couple issues:

- Which libraries to use should be based on WIN32, not MSVC.

- Windows libraries can be specified by #pragma comment lines in the
  source or by build dependencies. We specified #pragma lines in
  source, but also have build dependencies in crypto_test, etc. The
  latter was missing bssl.

  The comment line should be sufficient, but being explicit is useful,
  so fill in the missing one. This should help building with MINGW,
  which is missing support for the usual Windows pragma.

Change-Id: Ide9328c7dd306738ebbb0792e47da96948fe12f4
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/42105
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/crypto/CMakeLists.txt b/crypto/CMakeLists.txt
index 0339e7d..0e2adaa 100644
--- a/crypto/CMakeLists.txt
+++ b/crypto/CMakeLists.txt
@@ -456,7 +456,7 @@
 
 SET_TARGET_PROPERTIES(crypto PROPERTIES LINKER_LANGUAGE C)
 
-if(NOT MSVC AND NOT ANDROID)
+if(NOT WIN32 AND NOT ANDROID)
   target_link_libraries(crypto pthread)
 endif()
 
diff --git a/tool/CMakeLists.txt b/tool/CMakeLists.txt
index 7658713..e9e387b 100644
--- a/tool/CMakeLists.txt
+++ b/tool/CMakeLists.txt
@@ -23,6 +23,10 @@
 
 add_dependencies(bssl global_target)
 
+if(WIN32)
+  target_link_libraries(bssl ws2_32)
+endif()
+
 if(APPLE OR WIN32 OR ANDROID)
   target_link_libraries(bssl ssl crypto)
 else()
diff --git a/util/generate_build_files.py b/util/generate_build_files.py
index 623e7d3..6c3977d 100644
--- a/util/generate_build_files.py
+++ b/util/generate_build_files.py
@@ -608,10 +608,14 @@
       self.PrintExe(cmake, 'bssl', files['tool'], ['ssl', 'crypto'])
 
       cmake.write(
-R'''if(NOT MSVC AND NOT ANDROID)
+R'''if(NOT WIN32 AND NOT ANDROID)
   target_link_libraries(crypto pthread)
 endif()
 
+if(WIN32)
+  target_link_libraries(bssl ws2_32)
+endif()
+
 ''')
 
 def FindCMakeFiles(directory):