]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: add "make uninstall" support
authorKefu Chai <kchai@redhat.com>
Thu, 21 Jul 2016 17:45:59 +0000 (01:45 +0800)
committerKefu Chai <kchai@redhat.com>
Mon, 25 Jul 2016 07:39:02 +0000 (15:39 +0800)
following https://cmake.org/Wiki/RecipeAddUninstallTarget

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/script/CMakeLists.txt
src/script/cmake_uninstall.cmake.in [new file with mode: 0644]

index 7a20ba31aa901678884e483b7fa329476e2ccd82..42568a13e567992edc806995f87d715e15db39f4 100644 (file)
@@ -5,3 +5,11 @@ if(WITH_SUBMAN)
     ${CMAKE_CURRENT_SOURCE_DIR}/subman
     DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/cron.hourly)
 endif()
+
+configure_file(
+    "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
+    "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
+    IMMEDIATE @ONLY)
+
+add_custom_target(uninstall
+    COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
diff --git a/src/script/cmake_uninstall.cmake.in b/src/script/cmake_uninstall.cmake.in
new file mode 100644 (file)
index 0000000..4c07dc7
--- /dev/null
@@ -0,0 +1,21 @@
+if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
+  message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt")
+endif(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
+
+file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
+string(REGEX REPLACE "\n" ";" files "${files}")
+foreach(file ${files})
+  message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
+  if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
+    exec_program(
+      "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
+      OUTPUT_VARIABLE rm_out
+      RETURN_VALUE rm_retval
+      )
+    if(NOT "${rm_retval}" STREQUAL 0)
+      message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
+    endif(NOT "${rm_retval}" STREQUAL 0)
+  else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
+    message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
+  endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
+endforeach(file)