Make generated C++ code compilable with C++/CLI in MSVC
Client: cpp
Patch: Shaoyu Zhang

This closes #3234
diff --git a/lib/cpp/src/thrift/transport/TNonblockingServerSocket.cpp b/lib/cpp/src/thrift/transport/TNonblockingServerSocket.cpp
index 0c6654c..39534b7 100644
--- a/lib/cpp/src/thrift/transport/TNonblockingServerSocket.cpp
+++ b/lib/cpp/src/thrift/transport/TNonblockingServerSocket.cpp
@@ -68,6 +68,10 @@
 #endif // _WIN32
 #endif
 
+#if _WIN32
+#include <thrift/windows/TWinsockSingleton.h>
+#endif
+
 template <class T>
 inline const SOCKOPT_CAST_T* const_cast_sockopt(const T* v) {
   return reinterpret_cast<const SOCKOPT_CAST_T*>(v);
diff --git a/lib/cpp/src/thrift/transport/TServerSocket.cpp b/lib/cpp/src/thrift/transport/TServerSocket.cpp
index 563f234..5b8bf2e 100644
--- a/lib/cpp/src/thrift/transport/TServerSocket.cpp
+++ b/lib/cpp/src/thrift/transport/TServerSocket.cpp
@@ -76,6 +76,7 @@
 #include <windows.h>
 #undef NOMINMAX
 #undef WIN32_LEAN_AND_MEAN
+#include <thrift/windows/TWinsockSingleton.h>
 #endif
 
 template <class T>
diff --git a/lib/cpp/src/thrift/transport/TSocket.cpp b/lib/cpp/src/thrift/transport/TSocket.cpp
index 48953aa..6e5727c 100644
--- a/lib/cpp/src/thrift/transport/TSocket.cpp
+++ b/lib/cpp/src/thrift/transport/TSocket.cpp
@@ -63,6 +63,10 @@
 #endif // _WIN32
 #endif
 
+#if _WIN32
+#include <thrift/windows/TWinsockSingleton.h>
+#endif
+
 template <class T>
 inline const SOCKOPT_CAST_T* const_cast_sockopt(const T* v) {
   return reinterpret_cast<const SOCKOPT_CAST_T*>(v);
diff --git a/lib/cpp/src/thrift/windows/config.h b/lib/cpp/src/thrift/windows/config.h
index 19296d6..2fc6458 100644
--- a/lib/cpp/src/thrift/windows/config.h
+++ b/lib/cpp/src/thrift/windows/config.h
@@ -52,7 +52,6 @@
 #include <thrift/transport/PlatformSocket.h>
 #include <thrift/windows/GetTimeOfDay.h>
 #include <thrift/windows/Operators.h>
-#include <thrift/windows/TWinsockSingleton.h>
 #include <thrift/windows/WinFcntl.h>
 #include <thrift/windows/SocketPair.h>
 
diff --git a/lib/cpp/test/CMakeLists.txt b/lib/cpp/test/CMakeLists.txt
index 31acf12..3ed1d20 100644
--- a/lib/cpp/test/CMakeLists.txt
+++ b/lib/cpp/test/CMakeLists.txt
@@ -67,6 +67,11 @@
 )
 add_library(testgencpp_cob STATIC ${testgencpp_cob_SOURCES})
 
+if (WIN32 AND MSVC)
+    add_library(testgencppCLI STATIC ${testgencpp_SOURCES})
+    set_target_properties(testgencppCLI PROPERTIES COMMON_LANGUAGE_RUNTIME "")
+endif()
+
 add_executable(Benchmark Benchmark.cpp)
 target_link_libraries(Benchmark testgencpp)
 target_link_libraries(Benchmark thrift)