THRIFT-4732: windows cmake refinements and add windows docker build support
diff --git a/build/cmake/DefineOptions.cmake b/build/cmake/DefineOptions.cmake
index 9d95b7c..19cb104 100644
--- a/build/cmake/DefineOptions.cmake
+++ b/build/cmake/DefineOptions.cmake
@@ -28,8 +28,8 @@
 if(BUILD_COMPILER OR EXISTS ${THRIFT_COMPILER})
     set(HAVE_COMPILER ON)
 endif()
-CMAKE_DEPENDENT_OPTION(BUILD_TESTING "Build with unit tests" ON "HAVE_COMPILER" OFF)
 CMAKE_DEPENDENT_OPTION(BUILD_EXAMPLES "Build examples" ON "HAVE_COMPILER" OFF)
+CMAKE_DEPENDENT_OPTION(BUILD_TESTING "Build with unit tests" ON "HAVE_COMPILER" OFF)
 CMAKE_DEPENDENT_OPTION(BUILD_TUTORIALS "Build Thrift tutorials" ON "HAVE_COMPILER" OFF)
 option(BUILD_LIBRARIES "Build Thrift libraries" ON)
 
@@ -40,9 +40,7 @@
 # and enables the library if all are found. This means the default is to build as
 # much as possible but leaving out libraries if their dependencies are not met.
 
-option(WITH_BOOST_STATIC "Build with Boost static link library" OFF)
-set(Boost_USE_STATIC_LIBS ${WITH_BOOST_STATIC})
-if (NOT WITH_BOOST_STATIC)
+if (NOT Boost_USE_STATIC_LIBS)
     add_definitions(-DBOOST_ALL_DYN_LINK)
     add_definitions(-DBOOST_TEST_DYN_LINK)
 endif()
@@ -113,7 +111,7 @@
 find_package(PythonInterp QUIET) # for Python executable
 find_package(PythonLibs QUIET) # for Python.h
 CMAKE_DEPENDENT_OPTION(BUILD_PYTHON "Build Python library" ON
-                       "BUILD_LIBRARIES;WITH_PYTHON;PYTHONLIBS_FOUND" OFF)
+                       "BUILD_LIBRARIES;WITH_PYTHON;PYTHONINTERP_FOUND;PYTHONLIBS_FOUND" OFF)
 
 # Haskell
 option(WITH_HASKELL "Build Haskell Thrift library" ON)
@@ -123,22 +121,29 @@
                        "BUILD_LIBRARIES;WITH_HASKELL;GHC_FOUND;CABAL_FOUND" OFF)
 
 # Common library options
-option(WITH_SHARED_LIB "Build shared libraries" ON)
-option(WITH_STATIC_LIB "Build static libraries" ON)
-if (NOT WITH_SHARED_LIB AND NOT WITH_STATIC_LIB)
-    message(FATAL_ERROR "Cannot build with both shared and static outputs disabled!")
-endif()
+# https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html
+# Default on Windows is static, shared mode library support needs work...
+CMAKE_DEPENDENT_OPTION(BUILD_SHARED_LIBS "Build shared libraries" OFF "WIN32" ON)
 
-#NOTE: C++ compiler options are defined in the lib/cpp/CMakeLists.txt
+if (WITH_SHARED_LIB)
+    message(WARNING "WITH_SHARED_LIB is deprecated; use -DBUILD_SHARED_LIBS=ON instead")
+    set(BUILD_SHARED_LIBS ON)
+elseif (WITH_STATIC_LIB)
+    if (WITH_SHARED_LIB)
+        message(FATAL_ERROR "Cannot build shared and static together; set BUILD_SHARED_LIBS instead.")
+    endif ()
+    message(WARNING "WITH_STATIC_LIB is deprecated; use -DBUILD_SHARED_LIBS=OFF instead")
+    set(BUILD_SHARED_LIBS OFF)
+endif ()
 
 # Visual Studio only options
 if(MSVC)
-option(WITH_MT "Build using MT instead of MD (MSVC only)" OFF)
+    option(WITH_MT "Build using MT instead of MD (MSVC only)" OFF)
 endif(MSVC)
 
 macro(MESSAGE_DEP flag summary)
 if(NOT ${flag})
-  message(STATUS "   - ${summary}")
+    message(STATUS "   - ${summary}")
 endif()
 endmacro(MESSAGE_DEP flag summary)
 
@@ -176,14 +181,13 @@
 MESSAGE_DEP(WITH_HASKELL "Disabled by WITH_HASKELL=OFF")
 MESSAGE_DEP(GHC_FOUND "GHC missing")
 MESSAGE_DEP(CABAL_FOUND "Cabal missing")
-message(STATUS " Library features:")
-message(STATUS "  Build shared libraries:                     ${WITH_SHARED_LIB}")
-message(STATUS "  Build static libraries:                     ${WITH_STATIC_LIB}")
-message(STATUS "  Build with Boost static link library:       ${WITH_BOOST_STATIC}")
-message(STATUS "  Build with libevent support:                ${WITH_LIBEVENT}")
-message(STATUS "  Build with OpenSSL support:                 ${WITH_OPENSSL}")
-message(STATUS "  Build with Qt4 support:                     ${WITH_QT4}")
-message(STATUS "  Build with Qt5 support:                     ${WITH_QT5}")
-message(STATUS "  Build with ZLIB support:                    ${WITH_ZLIB}")
+if (BUILD_CPP)
+    message(STATUS " Library features:")
+    message(STATUS "  Build shared libraries:                     ${BUILD_SHARED_LIBS}")
+    message(STATUS "  Build with libevent support:                ${WITH_LIBEVENT}")
+    message(STATUS "  Build with Qt4 support:                     ${WITH_QT4}")
+    message(STATUS "  Build with Qt5 support:                     ${WITH_QT5}")
+    message(STATUS "  Build with ZLIB support:                    ${WITH_ZLIB}")
+endif ()
 message(STATUS "----------------------------------------------------------")
 endmacro(PRINT_CONFIG_SUMMARY)
diff --git a/build/cmake/DefinePlatformSpecifc.cmake b/build/cmake/DefinePlatformSpecifc.cmake
index 9d7c903..ac33e29 100644
--- a/build/cmake/DefinePlatformSpecifc.cmake
+++ b/build/cmake/DefinePlatformSpecifc.cmake
@@ -20,8 +20,16 @@
 # Uncomment this to show some basic cmake variables about platforms
 # include (NewPlatformDebug)
 
+# For Debug build types, append a "d" to the library names.
+set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Set debug library postfix" FORCE)
+
 # Visual Studio specific options
 if(MSVC)
+    # Allow for shared library builds
+    if(BUILD_SHARED_LIBS)
+        set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON CACHE TYPE BOOL FORCE)
+    endif()
+
     #For visual studio the library naming is as following:
     # Dynamic libraries:
     #  - thrift.dll  for release library
@@ -36,11 +44,6 @@
     #
     # the same holds for other libraries like libthriftz etc.
 
-    # For Debug build types, append a "d" to the library names.
-    set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Set debug library postfix" FORCE)
-    set(CMAKE_RELEASE_POSTFIX "" CACHE STRING "Set release library postfix" FORCE)
-    set(CMAKE_RELWITHDEBINFO_POSTFIX "" CACHE STRING "Set release library postfix" FORCE)
-
     # Build using /MT option instead of /MD if the WITH_MT options is set
     if(WITH_MT)
         set(CompilerFlags
@@ -56,9 +59,9 @@
         foreach(CompilerFlag ${CompilerFlags})
           string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
         endforeach()
-        set(STATIC_POSTFIX "mt" CACHE STRING "Set static library postfix" FORCE)
+        set(THRIFT_RUNTIME_POSTFIX "mt" CACHE STRING "Set static library postfix" FORCE)
     else(WITH_MT)
-        set(STATIC_POSTFIX "md" CACHE STRING "Set static library postfix" FORCE)
+        set(THRIFT_RUNTIME_POSTFIX "md" CACHE STRING "Set static library postfix" FORCE)
     endif(WITH_MT)
 
     # Disable boost auto linking pragmas - cmake includes the right files
@@ -72,14 +75,6 @@
 
     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" )
diff --git a/build/cmake/README.md b/build/cmake/README.md
index e5c128b..a0eb859 100644
--- a/build/cmake/README.md
+++ b/build/cmake/README.md
@@ -1,6 +1,7 @@
-# Apache Thrift - CMake build
+# Apache Thrift - CMake Build
 
 ## Goal
+
 Extend Apache Thrift's *make cross* approach to the build system.
 
 Due to growing the field of operating system support, a proper executable
@@ -11,12 +12,26 @@
 As nice side benefit of CMake is the generation of development environment
 specific soultion files. => No solution files within source tree.
 
+## Prerequisites
+
+These are language-specific, however for C++ you must provide:
+
+- Boost
+- OpenSSL
+
+You may optionally provide:
+
+- libevent
+- zlib
 
 ## Usage
-just do this:
 
-    mkdir cmake-build && cd cmake-build
-    cmake ..
+To use CMake you first create an out-of-tree build directory, then use
+CMake to generate a build framework, then build:
+
+    mkdir /tmp/build
+    cd /tmp/build
+    cmake /location/to/thrift
 
 if you use a specific toolchain pass it to cmake, the same for options:
 
@@ -25,13 +40,6 @@
     cmake -DTHRIFT_COMPILER_HS=OFF ..
     cmake -DWITH_ZLIB=ON ..
 
-or on Windows
-
-    cmake -G "Visual Studio 12 2013 Win64" \
-    -DBOOST_ROOT=C:/3rdparty/boost_1_58_0 \
-    -DZLIB_ROOT=C:/3rdparty/zlib128-dll \
-    -DWITH_SHARED_LIB=off ..
-
 and open the development environment you like with the solution or do this:
 
     make
@@ -39,15 +47,25 @@
     make cross
     make dist
 
-to generate an installer and distribution package do this:
+or on Windows, the following will produce a solution file you can use
+inside Visual Studio:
+
+    cmake -G "Visual Studio 15 2017 Win64" \
+      -DBOOST_ROOT=C:/3rdparty/boost_1_69_0 \
+      -DBOOST_LIBRARYDIR=C:/3rdparty/boost_1_69_0/lib64-msvc-14.1^
+      -DZLIB_ROOT=C:/3rdparty/zlib-1.2.11
+
+<!--
+To generate an installer and distribution package do this:
 
     cpack
+-->
 
 ## TODO
+
 * git hash or tag based versioning depending on source state
 * build tutorial
 * build test
-* with/without language lib/<lang>/
 * enable/disable
 * make cross
 * make dist (create an alias to make package_source)
@@ -57,4 +75,4 @@
   * libthrift
   * tutorial
   * test
-* merge into /README.md
+* merge into /README.md
\ No newline at end of file
diff --git a/build/cmake/ThriftMacros.cmake b/build/cmake/ThriftMacros.cmake
index f837f94..366719f 100644
--- a/build/cmake/ThriftMacros.cmake
+++ b/build/cmake/ThriftMacros.cmake
@@ -17,89 +17,31 @@
 # under the License.
 #
 
-
-set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Set debug library postfix" FORCE)
-
-
 macro(ADD_LIBRARY_THRIFT name)
-
-if(WITH_SHARED_LIB)
-    add_library(${name} SHARED ${ARGN})
+    add_library(${name} ${ARGN})
     set_target_properties(${name} PROPERTIES
-        OUTPUT_NAME ${name}
-        VERSION ${thrift_VERSION}
-        SOVERSION ${thrift_VERSION} )
-    #set_target_properties(${name} PROPERTIES PUBLIC_HEADER "${thriftcpp_HEADERS}")
+        OUTPUT_NAME ${name}${THRIFT_RUNTIME_POSTFIX}   # windows link variants (/MT, /MD, /MTd, /MDd) get different names
+        VERSION ${thrift_VERSION} )
+    # set_target_properties(${name} PROPERTIES PUBLIC_HEADER "${thriftcpp_HEADERS}")
     install(TARGETS ${name}
         RUNTIME DESTINATION "${BIN_INSTALL_DIR}"
         LIBRARY DESTINATION "${LIB_INSTALL_DIR}"
         ARCHIVE DESTINATION "${LIB_INSTALL_DIR}"
         PUBLIC_HEADER DESTINATION "${INCLUDE_INSTALL_DIR}")
-endif()
-
-if(WITH_STATIC_LIB)
-    add_library(${name}_static STATIC ${ARGN})
-    set_target_properties(${name}_static PROPERTIES
-        OUTPUT_NAME ${name}${STATIC_POSTFIX}
-        VERSION ${thrift_VERSION}
-        SOVERSION ${thrift_VERSION} )
-    install(TARGETS ${name}_static
-        RUNTIME DESTINATION "${BIN_INSTALL_DIR}"
-        LIBRARY DESTINATION "${LIB_INSTALL_DIR}"
-        ARCHIVE DESTINATION "${LIB_INSTALL_DIR}"
-        PUBLIC_HEADER DESTINATION "${INCLUDE_INSTALL_DIR}")
-endif()
-
-endmacro(ADD_LIBRARY_THRIFT)
-
+endmacro()
 
 macro(TARGET_INCLUDE_DIRECTORIES_THRIFT name)
-
-if(WITH_SHARED_LIB)
     target_include_directories(${name} ${ARGN})
-endif()
-
-if(WITH_STATIC_LIB)
-    target_include_directories(${name}_static ${ARGN})
-endif()
-
-endmacro(TARGET_INCLUDE_DIRECTORIES_THRIFT)
-
+endmacro()
 
 macro(TARGET_LINK_LIBRARIES_THRIFT name)
-
-if(WITH_SHARED_LIB)
     target_link_libraries(${name} ${ARGN})
-endif()
-
-if(WITH_STATIC_LIB)
-    target_link_libraries(${name}_static ${ARGN})
-endif()
-
-endmacro(TARGET_LINK_LIBRARIES_THRIFT)
-
+endmacro()
 
 macro(LINK_AGAINST_THRIFT_LIBRARY target libname)
-
-if (WITH_SHARED_LIB)
     target_link_libraries(${target} ${libname})
-elseif (WITH_STATIC_LIB)
-    target_link_libraries(${target} ${libname}_static)
-else()
-    message(FATAL "Not linking with shared or static libraries?")
-endif()
-
-endmacro(LINK_AGAINST_THRIFT_LIBRARY)
-
+endmacro()
 
 macro(TARGET_LINK_LIBRARIES_THRIFT_AGAINST_THRIFT_LIBRARY target libname)
-
-if(WITH_SHARED_LIB)
     target_link_libraries(${target} ${ARGN} ${libname})
-endif()
-
-if(WITH_STATIC_LIB)
-    target_link_libraries(${target}_static ${ARGN} ${libname}_static)
-endif()
-
-endmacro(TARGET_LINK_LIBRARIES_THRIFT_AGAINST_THRIFT_LIBRARY)
+endmacro()