From 78e65bf143edeceae3179c40b511e1313621ffde Mon Sep 17 00:00:00 2001 From: Michael Baentsch <57787676+baentsch@users.noreply.github.com> Date: Tue, 7 Nov 2023 22:59:03 +0100 Subject: [PATCH] add uninstall support (#1604) --- .CMake/cmake_uninstall.cmake.in | 24 ++++++++++++++++++++++++ CMakeLists.txt | 12 ++++++++++++ README.md | 2 ++ 3 files changed, 38 insertions(+) create mode 100644 .CMake/cmake_uninstall.cmake.in diff --git a/.CMake/cmake_uninstall.cmake.in b/.CMake/cmake_uninstall.cmake.in new file mode 100644 index 000000000..3880d489e --- /dev/null +++ b/.CMake/cmake_uninstall.cmake.in @@ -0,0 +1,24 @@ +# As per https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake + +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() + diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a10f8d57..03912599d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -215,3 +215,15 @@ endif() set(CPACK_DEBIAN_PACKAGE_MAINTAINER "www.openquantumsafe.org") include(CPack) + +# uninstall target +if(NOT TARGET uninstall) + configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/.CMake/cmake_uninstall.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" + IMMEDIATE @ONLY) + + add_custom_target(uninstall + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) +endif() + diff --git a/README.md b/README.md index 037e04f38..2e6950f26 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,8 @@ The following instructions assume we are in `build`. 4. `ninja install` can be run to install the built library and `include` files to a location of choice, which can be specified by passing the `-DCMAKE_INSTALL_PREFIX=