summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2023-12-12 00:30:36 +0100
committerAlbrecht Schlosser <albrechts.fltk@online.de>2023-12-12 00:30:36 +0100
commit5ef962781fb04f63c6e327ce395d81457838cd61 (patch)
treeeaa700f91cb6430ca5713348877ab7c9fdaa7fc5
parent5e3681c22a2073a63271d554ea99105264800659 (diff)
CMake: remove deprecated 'exec_program' from target 'uninstall'
1. 'exec_program()' should be replaced with 'execute_process()'. Done. 2. 'cmake -E remove' is broken and deprecated since 3.17, hence we use 'cmake -E rm' (!) for CMake since 3.17 and 'cmake -E remove' only for older CMake versions.
-rw-r--r--CMake/cmake_uninstall.cmake.in71
1 files changed, 54 insertions, 17 deletions
diff --git a/CMake/cmake_uninstall.cmake.in b/CMake/cmake_uninstall.cmake.in
index ed3a5bdfd..b2547ecf2 100644
--- a/CMake/cmake_uninstall.cmake.in
+++ b/CMake/cmake_uninstall.cmake.in
@@ -1,19 +1,56 @@
-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(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
+#
+# Support file to uninstall the FLTK project using CMake
+# Originally written by Michael Surette
+#
+# Copyright 1998-2023 by Bill Spitzak and others.
+#
+# This library is free software. Distribution and use rights are outlined in
+# the file "COPYING" which should have been included with this file. If this
+# file is missing or damaged, see the license at:
+#
+# https://www.fltk.org/COPYING.php
+#
+# Please see the following page on how to report bugs and issues:
+#
+# https://www.fltk.org/bugs.php
+#
-file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
-string(REGEX REPLACE "\n" ";" files "${files}")
+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 ()
-foreach(file ${files})
-message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"")
- exec_program("@CMAKE_COMMAND@"
- ARGS "-E remove -f \"$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)
-endforeach(file)
+file (READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
+string (REGEX REPLACE "\n" ";" files "${files}")
+
+# Note 1: 'cmake -E remove [-f]' is deprecated since CMake 3.17 and the docs
+# state: "The implementation was buggy and always returned 0. It cannot be
+# fixed without breaking backwards compatibility. Use rm instead."
+# Note 2: 'cmake -E rm [-f]' has been added in CMake 3.17
+# Note 3:
+# Remove this distinction if: cmake_minimum_required(VERSION 3.17) or higher.
+
+if (CMAKE_VERSION VERSION_LESS 3.17)
+ set (rm_cmd remove)
+else ()
+ set (rm_cmd rm)
+endif ()
+
+foreach (file ${files})
+ message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"")
+ execute_process(
+ COMMAND "${CMAKE_COMMAND}" -E ${rm_cmd} -f "$ENV{DESTDIR}${file}"
+ OUTPUT_VARIABLE rm_out
+ ERROR_VARIABLE rm_err
+ RESULT_VARIABLE rm_retval
+ )
+
+ if (NOT "${rm_retval}" STREQUAL 0)
+ message (STATUS "Error removing \"$ENV{DESTDIR}${file}\"")
+ message (STATUS " Status = '${rm_retval}'")
+ message (STATUS " Output = '${rm_out}'")
+ message (STATUS " Error = '${rm_err}'")
+ message (FATAL_ERROR "Exiting with fatal error.")
+ endif ()
+
+endforeach (file)