From 702e64f45b0791d0a062e3e2246628a09aeb13ce Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Mon, 18 Nov 2024 10:52:51 +0800 Subject: [PATCH] cmake: add uninstall target --- CMakeLists.txt | 10 ++++++++++ cmake/cmake_uninstall.cmake.in | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 cmake/cmake_uninstall.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index df02f354..e80c9911 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1078,6 +1078,16 @@ if(SDLIMAGE_INSTALL) REVISION "${SDLIMAGE_REVISION}" ) endif() + + + ##### Uninstall target ##### + + if(NOT TARGET uninstall) + configure_file(cmake/cmake_uninstall.cmake.in cmake_uninstall.cmake IMMEDIATE @ONLY) + + add_custom_target(uninstall + COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake") + endif() endif() if(SDLIMAGE_SAMPLES) diff --git a/cmake/cmake_uninstall.cmake.in b/cmake/cmake_uninstall.cmake.in new file mode 100644 index 00000000..9a59b4f4 --- /dev/null +++ b/cmake/cmake_uninstall.cmake.in @@ -0,0 +1,17 @@ +if (NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") + message(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_BINARY_DIR@/install_manifest.txt\"") +endif() + +file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files) +string(REGEX REPLACE "\n" ";" files "${files}") +foreach(file ${files}) + message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"") + execute_process( + COMMAND @CMAKE_COMMAND@ -E remove "$ENV{DESTDIR}${file}" + OUTPUT_VARIABLE rm_out + RESULT_VARIABLE rm_retval + ) + if(NOT ${rm_retval} EQUAL 0) + message(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"") + endif (NOT ${rm_retval} EQUAL 0) +endforeach()