Skip to content

Commit

Permalink
build(cmake): simplify and speed up the uninstall target
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dundargoc committed Jun 19, 2022
1 parent 668591a commit cd1b299
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 32 deletions.
13 changes: 2 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions cmake/UninstallHelper.cmake
Original file line number Diff line number Diff line change
@@ -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()
21 changes: 0 additions & 21 deletions cmake/UninstallHelper.cmake.in

This file was deleted.

0 comments on commit cd1b299

Please sign in to comment.