From daba52b346acaa491e6852f70b28d45c3e4a02d3 Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Wed, 13 Mar 2024 12:42:06 -0700 Subject: [PATCH] Update uninstall target --- CMakeLists.txt | 12 ++++++++--- cmake/uninstall_target.cmake.in | 38 +++++++++++++++++---------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ebca792abdfcb..ce7e074cba6e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -512,9 +512,15 @@ install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/tutorials" #=============================================================================== # Add an "uninstall" target -# Ref: http://www.cmake.org/Wiki/CMake_FAQ#Can_I_do_.22make_uninstall.22_with_CMake.3F -configure_file("${PROJECT_SOURCE_DIR}/cmake/uninstall_target.cmake.in" "${PROJECT_BINARY_DIR}/uninstall_target.cmake" IMMEDIATE @ONLY) -add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${PROJECT_BINARY_DIR}/uninstall_target.cmake") +# https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/recipe/AddUninstallTarget +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/uninstall_target.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/cmake/uninstall_target.cmake" + IMMEDIATE @ONLY +) +add_custom_target(uninstall + "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake" +) #=============================================================================== # Code Formatting diff --git a/cmake/uninstall_target.cmake.in b/cmake/uninstall_target.cmake.in index 0c70cfc7821ea..85aac49ee65a9 100644 --- a/cmake/uninstall_target.cmake.in +++ b/cmake/uninstall_target.cmake.in @@ -1,20 +1,22 @@ -# Ref: http://www.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(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") +# https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/recipe/AddUninstallTarget +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") -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}") - exec_program("@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" +FILE(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) +STRING(REGEX REPLACE " " ";" files "${files}") +FOREACH(file ${files}) + MESSAGE(STATUS "Uninstalling "$ENV{DESTDIR}${file}"") + IF(EXISTS "$ENV{DESTDIR}${file}") + EXEC_PROGRAM( + "@CMAKE_COMMAND@" ARGS "-E remove "$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) - else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") - message(STATUS "File $ENV{DESTDIR}${file} does not exist.") - endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") -endforeach(file) + 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) + ELSE(EXISTS "$ENV{DESTDIR}${file}") + MESSAGE(STATUS "File "$ENV{DESTDIR}${file}" does not exist.") + ENDIF(EXISTS "$ENV{DESTDIR}${file}") +ENDFOREACH(file)