Skip to content

Commit

Permalink
Add cmake TARGET: uninstall
Browse files Browse the repository at this point in the history
 Usage:
  $ sudo make install
  $ sudo make uninstall <<=== New Target
  • Loading branch information
Rtoax committed Aug 19, 2022
1 parent 66e72e4 commit 99146aa
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,13 @@ add_subdirectory(tests)
endif(ENABLE_TESTS)
add_subdirectory(tools)
endif(ENABLE_CLANG_JIT)

if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/CmakeUninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/CmakeUninstall.cmake"
IMMEDIATE @ONLY)

add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/CmakeUninstall.cmake)
endif()
29 changes: 29 additions & 0 deletions cmake/CmakeUninstall.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2022 Rong Tao
#
function(UninstallManifest manifest)
if(NOT EXISTS "${manifest}")
message(FATAL_ERROR "Cannot find install manifest: ${manifest}")
endif()

file(READ "${manifest}" 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()
endfunction()

UninstallManifest("@CMAKE_BINARY_DIR@/install_manifest.txt")
UninstallManifest("@CMAKE_BINARY_DIR@/install_manifest_python_bcc.txt")
2 changes: 1 addition & 1 deletion src/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ foreach(PY_CMD ${PYTHON_CMD})
install(
CODE "
execute_process(
COMMAND ${PY_CMD} setup.py install -f ${PYTHON_FLAGS} --prefix=${CMAKE_INSTALL_PREFIX}
COMMAND ${PY_CMD} setup.py install -f ${PYTHON_FLAGS} --prefix=${CMAKE_INSTALL_PREFIX} --record ${CMAKE_BINARY_DIR}/install_manifest_python_bcc.txt
WORKING_DIRECTORY ${PY_DIRECTORY})"
COMPONENT python)
endforeach()

0 comments on commit 99146aa

Please sign in to comment.