From 11e36ff48e5f9f7dd92c52e6a7869dc2ccf15487 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 25 Oct 2025 11:33:23 -0700
Subject: [PATCH] Add cmake uninstall target (thanks @ChillerDragon!)
---
CMakeLists.txt | 7 +++++++
cmake/cmake_uninstall.cmake.in | 17 +++++++++++++++++
2 files changed, 24 insertions(+)
create mode 100644 cmake/cmake_uninstall.cmake.in
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0516508c1..45f346d2b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -295,6 +295,13 @@ if(SDL12DEVEL)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/sdl-config.in" "${CMAKE_CURRENT_BINARY_DIR}/sdl-config" @ONLY)
install(PROGRAMS "${CMAKE_CURRENT_BINARY_DIR}/sdl-config" DESTINATION bin)
+
+ # uninstall
+ if(NOT TARGET uninstall)
+ configure_file(cmake/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")
+ endif()
endif()
set(SOEXT ${CMAKE_SHARED_LIBRARY_SUFFIX})
diff --git a/cmake/cmake_uninstall.cmake.in b/cmake/cmake_uninstall.cmake.in
new file mode 100644
index 000000000..9a59b4f48
--- /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()