THRIFT-3873: fix various compiler warnings and overflow errors
THRIFT-3847: change VERSION to PACKAGE_VERSION to avoid conflicts with third party or OS headers

This closes #1128
diff --git a/build/cmake/ConfigureChecks.cmake b/build/cmake/ConfigureChecks.cmake
index f650544..81223d8 100644
--- a/build/cmake/ConfigureChecks.cmake
+++ b/build/cmake/ConfigureChecks.cmake
@@ -17,17 +17,16 @@
 # under the License.
 #
 
-
-include(CheckSymbolExists)
+include(CheckFunctionExists)
 include(CheckIncludeFile)
 include(CheckIncludeFiles)
-include(CheckFunctionExists)
+include(CheckSymbolExists)
 
-# If AI_ADDRCONFIG is not defined we define it as 0
-check_symbol_exists(AI_ADDRCONFIG "sys/types.h;sys/socket.h;netdb.h" HAVE_AI_ADDRCONFIG)
-if(NOT HAVE_AI_ADDRCONFIG)
-set(AI_ADDRCONFIG 1)
-endif(NOT HAVE_AI_ADDRCONFIG)
+if (Inttypes_FOUND)
+  # This allows the inttypes.h and stdint.h checks to succeed on platforms that
+  # do not natively provide there.
+  set (CMAKE_REQUIRED_INCLUDES ${INTTYPES_INCLUDE_DIRS})
+endif ()
 
 check_include_file(arpa/inet.h HAVE_ARPA_INET_H)
 check_include_file(fcntl.h HAVE_FCNTL_H)
@@ -72,5 +71,5 @@
 
 # generate a config.h file
 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/build/cmake/config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/thrift/config.h")
-# HACK: Some files include thrift/config.h and some config.h so we include both. This should be cleaned up.
-include_directories("${CMAKE_CURRENT_BINARY_DIR}/thrift" "${CMAKE_CURRENT_BINARY_DIR}")
+
+include_directories("${CMAKE_CURRENT_BINARY_DIR}")
diff --git a/build/cmake/DefinePlatformSpecifc.cmake b/build/cmake/DefinePlatformSpecifc.cmake
index e57ecc2..496134c 100644
--- a/build/cmake/DefinePlatformSpecifc.cmake
+++ b/build/cmake/DefinePlatformSpecifc.cmake
@@ -71,12 +71,24 @@
       message (FATAL_ERROR "Windows build does not support shared library output yet, please set -DWITH_SHARED_LIB=off")
     endif()
 
+    add_definitions("/MP") # parallel build
+    add_definitions("/W3") # warning level 3
+
+    # VS2010 does not provide inttypes which we need for "PRId64" used in many places
+    find_package(Inttypes)
+    if (Inttypes_FOUND)
+      include_directories(${INTTYPES_INCLUDE_DIRS})
+      # OpenSSL conflicts with the definition of PRId64 unless it is defined first
+      add_definitions("/FIinttypes.h")
+    endif ()
 elseif(UNIX)
   find_program( MEMORYCHECK_COMMAND valgrind )
   set( MEMORYCHECK_COMMAND_OPTIONS "--gen-suppressions=all --leak-check=full" )
   set( MEMORYCHECK_SUPPRESSIONS_FILE "${PROJECT_SOURCE_DIR}/test/valgrind.suppress" )
 endif()
 
+add_definitions("-D__STDC_FORMAT_MACROS")
+
 # WITH_*THREADS selects which threading library to use
 if(WITH_BOOSTTHREADS)
   add_definitions("-DUSE_BOOST_THREAD=1")
diff --git a/build/cmake/FindInttypes.cmake b/build/cmake/FindInttypes.cmake
new file mode 100644
index 0000000..e661f78
--- /dev/null
+++ b/build/cmake/FindInttypes.cmake
@@ -0,0 +1,41 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# find msinttypes on compilers that don't provide it, for example
+#   VS2010
+
+# Usage: 
+# Provide INTTYPES_ROOT if you need it
+# Result: INTTYPES_INCLUDE_DIRS, where to find inttypes.h
+# Result: Inttypes_FOUND, If false, inttypes.h was not found
+
+find_path(INTTYPES_INCLUDE_DIRS inttypes.h HINTS ${INTTYPES_ROOT})
+if (INTTYPES_INCLUDE_DIRS)
+  set(Inttypes_FOUND TRUE)
+else ()
+  set(Inttypes_FOUND FALSE)
+  if (Inttypes_FIND_REQUIRED)
+    message(FATAL_ERROR "Could NOT find inttypes.h")
+  endif ()
+  message(STATUS "inttypes.h NOT found")
+endif ()
+
+mark_as_advanced(
+  INTTYPES_INCLUDE_DIRS
+)
diff --git a/build/cmake/FindLibevent.cmake b/build/cmake/FindLibevent.cmake
index 2bcd709..ac6a078 100644
--- a/build/cmake/FindLibevent.cmake
+++ b/build/cmake/FindLibevent.cmake
@@ -13,9 +13,13 @@
   list(APPEND LibEvent_LIBRARIES_PATHS "${prefix}/lib")
 endforeach()
 
-find_path(LIBEVENT_INCLUDE_DIRS event.h PATHS ${LibEvent_INCLUDE_PATHS})
-# "lib" prefix is needed on Windows
-find_library(LIBEVENT_LIBRARIES NAMES event libevent PATHS ${LibEvent_LIBRARIES_PATHS})
+# Looking for "event.h" will find the Platform SDK include dir on windows
+# so we also look for a peer header like evhttp.h to get the right path
+find_path(LIBEVENT_INCLUDE_DIRS evhttp.h event.h PATHS ${LibEvent_INCLUDE_PATHS})
+
+# "lib" prefix is needed on Windows in some cases
+# newer versions of libevent use three libraries
+find_library(LIBEVENT_LIBRARIES NAMES event event_core event_extra libevent PATHS ${LibEvent_LIBRARIES_PATHS})
 
 if (LIBEVENT_LIBRARIES AND LIBEVENT_INCLUDE_DIRS)
   set(Libevent_FOUND TRUE)
diff --git a/build/cmake/config.h.in b/build/cmake/config.h.in
index 181ea18..083bc55 100644
--- a/build/cmake/config.h.in
+++ b/build/cmake/config.h.in
@@ -44,9 +44,6 @@
 /* Define to the full name and version of this package. */
 #define PACKAGE_STRING "${PACKAGE_STRING}"
 
-/* Version number of package */
-#define VERSION "${VERSION}"
-
 /************************** DEFINES *************************/
 
 /* Define if the AI_ADDRCONFIG symbol is unavailable */
@@ -154,4 +151,4 @@
 /* Define to 1 if strerror_r returns char *. */
 #cmakedefine STRERROR_R_CHAR_P 1
 
-#endif
\ No newline at end of file
+#endif