diff --git a/CMakeLists.txt b/CMakeLists.txt index a42352fccf..a8b00306f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -282,3 +282,14 @@ if(PCAPPP_INSTALL) COMPONENT devel DESTINATION "${PCAPPP_INSTALL_CMAKEDIR}") endif() + +# uninstall target +if(NOT TARGET uninstall) + configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/PcapPlusPlusUninstall.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/PcapPlusPlusUninstall.cmake" + IMMEDIATE + @ONLY) + + add_custom_target(uninstall COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/PcapPlusPlusUninstall.cmake") +endif() diff --git a/ci/cmake-format-all.sh b/ci/cmake-format-all.sh index f103fc1f74..13c53d2731 100755 --- a/ci/cmake-format-all.sh +++ b/ci/cmake-format-all.sh @@ -3,6 +3,10 @@ set -e SCRIPT=$(readlink -f "$0") SCRIPTPATH=$(dirname "${SCRIPT}") -ROOTPATH=${SCRIPTPATH}/.. +ROOTPATH=$(realpath "${SCRIPTPATH}"/..) +if ! command -v cmake-format; then + echo "cmake-format is not found!" + exit 1 +fi find "${ROOTPATH}" \( -name '*.cmake' -o -name 'CMakeLists.txt' \) -not -path "*/3rdParty/*" -exec echo 'Formatting:' {} ';' -exec cmake-format -i {} ';' diff --git a/cmake/PcapPlusPlusUninstall.cmake.in b/cmake/PcapPlusPlusUninstall.cmake.in new file mode 100644 index 0000000000..9a3121336c --- /dev/null +++ b/cmake/PcapPlusPlusUninstall.cmake.in @@ -0,0 +1,25 @@ +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}") + # If the file exists or is symlink + # run remove command through cmake in command mode + # See https://cmake.org/cmake/help/latest/manual/cmake.1.html#run-a-command-line-tool + exec_program( + "@CMAKE_COMMAND@" ARGS "-E rm -rf \"$ENV{DESTDIR}${file}\"" + OUTPUT_VARIABLE rm_out + RETURN_VALUE rm_retval + ) + if(NOT "${rm_retval}" STREQUAL 0) + message(FATAL_ERROR "Error 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() +file(REMOVE "@CMAKE_BINARY_DIR@/install_manifest.txt")