cmake: minor improvements to cmake_uninstall.in.cmake

- reduce log noise by showing 'Uninstalling' message only if the file
  exists. (and a different message otherwise)
- replace cmake `rm` command with `file(REMOVE)`. For efficiency.
  Show manual message if the file could not be deleted.
  Ref: https://cmake.org/cmake/help/v3.18/command/file.html#remove
  Follow-up to 6d008352c6 #22193
- reduce log noise by showing 'Uninstalled' only if the deletion was
  successful. (and a different message otherwise)
- display `DESTDIR` env value if set.
- drop checking, setting and showing `CMAKE_INSTALL_PREFIX`.
  The value was never predefined, also not used, besides showing it,
  and showing it is misleading because `--prefix` may override the
  configure-time value, and also superfluous because the filenames
  are showing the actual prefix anyway.

Follow-up to 27e2a4733c

Closes #22201
This commit is contained in:
Viktor Szakats 2026-06-26 22:56:02 +02:00
parent 0a6c74a802
commit 88d85916f2
No known key found for this signature in database
2 changed files with 11 additions and 9 deletions

View file

@ -26,18 +26,22 @@ if(NOT EXISTS "${_manifest}")
message(FATAL_ERROR "Cannot find install manifest: ${_manifest}")
endif()
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@")
set(_destdir "$ENV{DESTDIR}")
if(NOT _destdir STREQUAL "")
message(STATUS "DESTDIR environment: ${_destdir}")
endif()
message(${CMAKE_INSTALL_PREFIX})
file(READ "${_manifest}" _files)
string(REGEX REPLACE "\n" ";" _files "${_files}")
foreach(_file IN LISTS _files)
set(_target "$ENV{DESTDIR}${_file}")
message(STATUS "Uninstalling ${_target}")
set(_target "${_destdir}${_file}")
if(IS_SYMLINK "${_target}" OR EXISTS "${_target}")
execute_process(COMMAND "@CMAKE_COMMAND@" -E rm -f -- "${_target}")
file(REMOVE "${_target}")
if(IS_SYMLINK "${_target}" OR EXISTS "${_target}")
message(STATUS "Failed to delete: ${_target}")
else()
message(STATUS "Uninstalled: ${_target}")
endif()
else()
message(STATUS "File does not exist: ${_target}")
endif()

View file

@ -2452,9 +2452,7 @@ if(NOT CURL_DISABLE_INSTALL)
DESTINATION ${_install_cmake_dir})
if(NOT TARGET curl_uninstall)
# Consumed variables:
# CMAKE_COMMAND
# CMAKE_INSTALL_PREFIX
# Consumed variable:
# PROJECT_BINARY_DIR
configure_file(
"${PROJECT_SOURCE_DIR}/CMake/cmake_uninstall.in.cmake"