THRIFT-4163: update cmake build type handling
diff --git a/build/cmake/BuildType.cmake b/build/cmake/BuildType.cmake
new file mode 100644
index 0000000..b3bf353
--- /dev/null
+++ b/build/cmake/BuildType.cmake
@@ -0,0 +1,36 @@
+#
+# 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.
+#
+
+# originally from:
+# https://raw.githubusercontent.com/OpenChemistry/tomviz/master/cmake/BuildType.cmake
+
+# Set a default build type if none was specified
+set(default_build_type "RelWithDebInfo")
+if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
+  set(default_build_type "Debug")
+endif()
+
+if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
+  message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
+  set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
+      STRING "Choose the type of build." FORCE)
+  # Set the possible values of build type for cmake-gui
+  set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
+    "MinSizeRel" "RelWithDebInfo")
+endif()
diff --git a/build/cmake/DefineCMakeDefaults.cmake b/build/cmake/DefineCMakeDefaults.cmake
index 7ae2136..6714357 100644
--- a/build/cmake/DefineCMakeDefaults.cmake
+++ b/build/cmake/DefineCMakeDefaults.cmake
@@ -34,17 +34,12 @@
 # since cmake 2.4.0
 set(CMAKE_COLOR_MAKEFILE ON)
 
-# Set the default build type to release with debug info
-if (NOT CMAKE_BUILD_TYPE)
-  set(CMAKE_BUILD_TYPE RelWithDebInfo
-    CACHE STRING
-      "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
-  )
-endif (NOT CMAKE_BUILD_TYPE)
-
 # Create the compile command database for clang by default
 set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
 
+# Set the CMAKE_BUILD_TYPE if it is not already defined
+include(BuildType)
+
 # Put the libraries and binaries that get built into directories at the
 # top of the build tree rather than in hard-to-find leaf
 # directories. This simplifies manual testing and the use of the build
diff --git a/build/cmake/DefineOptions.cmake b/build/cmake/DefineOptions.cmake
index e9b094c..8e334d9 100644
--- a/build/cmake/DefineOptions.cmake
+++ b/build/cmake/DefineOptions.cmake
@@ -145,6 +145,9 @@
 message(STATUS "Thrift version:                               ${thrift_VERSION} (${thrift_VERSION_MAJOR}.${thrift_VERSION_MINOR}.${thrift_VERSION_PATCH})")
 message(STATUS "Thrift package version:                       ${PACKAGE_VERSION}")
 message(STATUS "Build configuration Summary")
+if (UNIX)
+    message(STATUS "  Build type:                                 ${CMAKE_BUILD_TYPE}")
+endif ()
 message(STATUS "  Build Thrift compiler:                      ${BUILD_COMPILER}")
 message(STATUS "  Build compiler plugin support:              ${WITH_PLUGIN}")
 message(STATUS "  Build with unit tests:                      ${BUILD_TESTING}")
diff --git a/lib/csharp/src/Protocol/TProtocolException.cs b/lib/csharp/src/Protocol/TProtocolException.cs
index 41c26a3..7bef236 100644
--- a/lib/csharp/src/Protocol/TProtocolException.cs
+++ b/lib/csharp/src/Protocol/TProtocolException.cs
@@ -43,7 +43,7 @@
         }
 
         public TProtocolException(int type, Exception inner = null)
-            : base(string.Empty,inner)
+            : base(string.Empty, inner)
         {
             type_ = type;
         }
diff --git a/lib/csharp/src/TException.cs b/lib/csharp/src/TException.cs
index aa9a210..b9fae6e 100644
--- a/lib/csharp/src/TException.cs
+++ b/lib/csharp/src/TException.cs
@@ -31,7 +31,7 @@
         {
         }
 
-        public TException(string message, Exception inner)
+        public TException(string message, Exception inner = null)
             : base(message, inner)
         {
         }
diff --git a/lib/hs/CMakeLists.txt b/lib/hs/CMakeLists.txt
index a20a319..1a5b8fd 100644
--- a/lib/hs/CMakeLists.txt
+++ b/lib/hs/CMakeLists.txt
@@ -60,7 +60,7 @@
 
 if(CMAKE_BUILD_TYPE STREQUAL "Debug")
     set(hs_optimize -O0)
-elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
+else()
     set(hs_optimize -O1)
 endif()