diff --git a/CMakeLists.txt b/CMakeLists.txt index 614e0edb0c2..0f9d0ad9211 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -958,12 +958,12 @@ add_custom_target(distcheck DEPENDS dist # uninstall target configure_file( - "${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.sh.in" - "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.sh" + "${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" @ONLY) add_custom_target(uninstall - COMMAND /bin/sh ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.sh) + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) set(_MODULES gnc-core-utils gnc-engine gnc-app-utils gnc-module gnc-locale-tax gnc-backend-xml-utils gnucash-guile) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index f1bad025509..bb2f4495149 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -11,7 +11,7 @@ endif() set_dist_list(cmake_DIST CMakeLists.txt README_CMAKE.txt - cmake_uninstall.sh.in + cmake_uninstall.cmake.in configure-appdata.cmake configure-gnucash-desktop.cmake configure-manpage.cmake diff --git a/cmake/cmake_uninstall.cmake.in b/cmake/cmake_uninstall.cmake.in new file mode 100644 index 00000000000..f74680c890b --- /dev/null +++ b/cmake/cmake_uninstall.cmake.in @@ -0,0 +1,19 @@ +# This is taken from https://cmake.org/Wiki/CMake_FAQ#Can_I_do_.22make_uninstall.22_with_CMake.3F + +if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") + message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") +endif() + +file(READ "@CMAKE_CURRENT_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}") + file(REMOVE "$ENV{DESTDIR}${file}") + if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") + message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") + endif() + else() + message(STATUS "File $ENV{DESTDIR}${file} does not exist.") + endif() +endforeach(file) diff --git a/cmake/cmake_uninstall.sh.in b/cmake/cmake_uninstall.sh.in deleted file mode 100644 index 88c0583efad..00000000000 --- a/cmake/cmake_uninstall.sh.in +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh -if [ ! -s install_manifest.txt ]; then - echo "Error: No install manifest." -fi -while IFS= read -r filename; do - if [ -e $filename ]; then - echo "--Uninstalling $filename" - rm $filename - else - echo "--$filename not found" - fi -done