From aad44f95ff28b91c44f3b6cd351baa3072908c28 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Sun, 30 Jan 2022 14:49:28 +0100 Subject: [PATCH] CMake: Add uninstall target --- CMakeLists.txt | 11 +++++++++++ cmake/uninstall.cmake.in | 26 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 cmake/uninstall.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index ce99121..0a60f0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,3 +95,14 @@ target_link_libraries(test) # Man page target add_subdirectory(doc) + +# ------------------------------------------ +# Uninstall target + +configure_file( + ${CMAKE_SOURCE_DIR}/cmake/uninstall.cmake.in + ${CMAKE_BINARY_DIR}/cmake_uninstall.cmake + @ONLY) + +add_custom_target(uninstall + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/cmake_uninstall.cmake) diff --git a/cmake/uninstall.cmake.in b/cmake/uninstall.cmake.in new file mode 100644 index 0000000..ddc8db8 --- /dev/null +++ b/cmake/uninstall.cmake.in @@ -0,0 +1,26 @@ +set(INSTALL_MANIFEST "@CMAKE_BINARY_DIR@/install_manifest.txt") +if(NOT EXISTS ${INSTALL_MANIFEST}) + message(FATAL_ERROR "Cannot find install manifest: ${INSTALL_MANIFEST}") +endif() + +string(ASCII 27 esc) +message("${esc}[36mUninstall the project...${esc}[0m") + +file(READ ${INSTALL_MANIFEST} files) +string(REGEX REPLACE "\n" ";" files "${files}") +list(REVERSE files) + +foreach(file ${files}) + message(STATUS "Uninstalling: $ENV{DESTDIR}${file}") + if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") + execute_process(COMMAND "@CMAKE_COMMAND@" + -E rm "$ENV{DESTDIR}${file}" + OUTPUT_VARIABLE rm_out + RESULT_VARIABLE rm_retval) + if(NOT "${rm_retval}" STREQUAL 0) + message(FATAL_ERROR "Problem when removing: $ENV{DESTDIR}${file}") + endif() + else() + message(STATUS "File: $ENV{DESTDIR}${file} does not exist.") + endif() +endforeach()