Skip to content

Commit

Permalink
Add cmake custom target uninstall
Browse files Browse the repository at this point in the history
`make uninstall` is enabled.
Without this, uninstalling was done manually with `rm` command.
  • Loading branch information
jiseongg authored and MartinNowack committed Mar 5, 2021
1 parent b1ef0c8 commit 3678058
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -814,3 +814,19 @@ endif()
# Miscellaneous install
################################################################################
install(FILES include/klee/klee.h DESTINATION include/klee)

################################################################################
# Uninstall rule
################################################################################
configure_file(
"${PROJECT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
@ONLY
)

add_custom_target(uninstall
COMMAND
"${CMAKE_COMMAND}" -P "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
COMMENT "Uninstalling..."
VERBATIM
)
24 changes: 24 additions & 0 deletions cmake/cmake_uninstall.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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})
set(file_path "$ENV{DESTDIR}${file}")
message(STATUS "Uninstalling ${file_path}")
if(IS_SYMLINK "${file_path}" OR EXISTS "${file_path}")
# We could use ``file(REMOVE ...)`` here but then we wouldn't
# know if the removal failed.
execute_process(COMMAND
"@CMAKE_COMMAND@" "-E" "remove" "${file_path}"
RESULT_VARIABLE rm_retval
)
if(NOT "${rm_retval}" STREQUAL 0)
message(FATAL_ERROR "Problem when removing \"${file_path}\"")
endif()
else()
message(STATUS "File \"${file_path}\" does not exist.")
endif()
endforeach()

0 comments on commit 3678058

Please sign in to comment.