diff options
author | Dundar Goc <gocdundar@gmail.com> | 2022-06-17 14:11:08 +0200 |
---|---|---|
committer | Dundar Goc <gocdundar@gmail.com> | 2022-06-19 18:34:28 +0200 |
commit | cd1b2998d394ad85f1f48a5f2a8cb064ae31b521 (patch) | |
tree | 895e08f1e2dc257357e225b21a56933fd746fe7c | |
parent | 668591ae04b3578d48d916680e4641c3c4afa525 (diff) | |
download | rneovim-cd1b2998d394ad85f1f48a5f2a8cb064ae31b521.tar.gz rneovim-cd1b2998d394ad85f1f48a5f2a8cb064ae31b521.tar.bz2 rneovim-cd1b2998d394ad85f1f48a5f2a8cb064ae31b521.zip |
build(cmake): simplify and speed up the uninstall target
More specifically, replace exec_program with file(REMOVE ...) so that
the uninstall target is run during the build stage instead of the
configure stage, significantly speeding up the target.
The code snippet that was removed is taken from the cmake FAQ
https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake.
However, this uses undocumented features such as IMMEDIATE when calling
configure_file, which is an artifact from cmake 2.x (it's so old it's
difficult to find information on it). Similarly, this particular code
snippet has been around for a long time and originated from the cmake
mailing lists. Based on this I believe the in-file was a workaround for
the limitations of cmake back then and that it's not required anymore.
-rw-r--r-- | CMakeLists.txt | 13 | ||||
-rw-r--r-- | cmake/UninstallHelper.cmake | 13 | ||||
-rw-r--r-- | cmake/UninstallHelper.cmake.in | 21 |
3 files changed, 15 insertions, 32 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 39659d6469..ac67dad75c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -752,17 +752,8 @@ if(BUSTED_LUA_PRG) set_target_properties(functionaltest-lua PROPERTIES FOLDER test) endif() -#add uninstall target -if(NOT TARGET uninstall) - configure_file( - "cmake/UninstallHelper.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/UninstallHelper.cmake" - IMMEDIATE @ONLY) - - add_custom_target(uninstall - COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/UninstallHelper.cmake) -endif() - +add_custom_target(uninstall + COMMAND ${CMAKE_COMMAND} -P ${PROJECT_SOURCE_DIR}/cmake/UninstallHelper.cmake) if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) add_subdirectory(packaging) diff --git a/cmake/UninstallHelper.cmake b/cmake/UninstallHelper.cmake new file mode 100644 index 0000000000..9a3d30af59 --- /dev/null +++ b/cmake/UninstallHelper.cmake @@ -0,0 +1,13 @@ +if(NOT EXISTS "${CMAKE_BINARY_DIR}/install_manifest.txt") + message(FATAL_ERROR "Cannot find install manifest: ${CMAKE_BINARY_DIR}/install_manifest.txt") +endif() + +file(STRINGS "${CMAKE_BINARY_DIR}/install_manifest.txt" 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}) + else() + message(STATUS "File $ENV{DESTDIR}${file} does not exist.") + endif() +endforeach() diff --git a/cmake/UninstallHelper.cmake.in b/cmake/UninstallHelper.cmake.in deleted file mode 100644 index c2d34d4796..0000000000 --- a/cmake/UninstallHelper.cmake.in +++ /dev/null @@ -1,21 +0,0 @@ -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}") - if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR 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() - else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") - message(STATUS "File $ENV{DESTDIR}${file} does not exist.") - endif() -endforeach() |