THRIFT-5147: Add uninstall function
Patch: Zezeng Wang

This closes #2066
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 18e52f6..127ceaf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -135,4 +135,7 @@
     endif()
 endif()
 
+# Create the uninstall target
+add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${PROJECT_SOURCE_DIR}/build/cmake/uninstall.cmake")
+
 PRINT_CONFIG_SUMMARY()
diff --git a/README.md b/README.md
index ff57321..011b75a 100644
--- a/README.md
+++ b/README.md
@@ -163,11 +163,15 @@
 
 Make thrift:
 
-	make
+    make
 
 From the top directory, become superuser and do:
 
-	make install
+    make install
+
+Uninstall thrift:
+
+    make uninstall
 
 Note that some language packages must be installed manually using build tools
 better suited to those languages (at the time of this writing, this applies
@@ -190,7 +194,7 @@
 There are a large number of client library tests that can all be run
 from the top-level directory.
 
-          make -k check
+    make -k check
 
 This will make all of the libraries (as necessary), and run through
 the unit tests defined in each of the client libraries. If a single
@@ -199,7 +203,7 @@
 
 To run the cross-language test suite, please run:
 
-          make cross
+    make cross
 
 This will run a set of tests that use different language clients and
 servers.
diff --git a/build/cmake/uninstall.cmake b/build/cmake/uninstall.cmake
new file mode 100644
index 0000000..3842a83
--- /dev/null
+++ b/build/cmake/uninstall.cmake
@@ -0,0 +1,47 @@
+#
+# 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.
+#
+
+cmake_minimum_required(VERSION 3.4)
+
+set(MANIFEST "${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt")
+
+if(NOT EXISTS ${MANIFEST})
+    message(FATAL_ERROR "Cannot find install mainfest: ${MANIFEST}")
+endif()
+
+file(STRINGS ${MANIFEST} files)
+foreach(file ${files})
+    if(EXISTS ${file} OR IS_SYMLINK ${file})
+        message(STATUS "Removing: ${file}")
+
+	execute_process(
+	    COMMAND ${CMAKE_COMMAND} -E remove  ${file}
+	    RESULT_VARIABLE result
+	    OUTPUT_QUIET
+	    ERROR_VARIABLE stderr
+	    ERROR_STRIP_TRAILING_WHITESPACE
+        )
+
+        if(NOT ${result} EQUAL 0)
+            message(FATAL_ERROR "${stderr}")
+        endif()
+    else()
+        message(STATUS "Does-not-exist: ${file}")
+    endif()
+endforeach(file)