diff --git a/CMakeLists.txt b/CMakeLists.txt index 03c3e6ca..c6f69130 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -208,6 +208,23 @@ include(SetInstallRpath) include(P4RuntimeProtobufs) +#################### +# Uninstall target # +#################### + +# Create script to uninstall the build. +configure_file( + "cmake/cmake_uninstall.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" + @ONLY +) + +# Define target to run uninstall script. +add_custom_target(uninstall + COMMAND + ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" +) + ################## # Subdirectories # ################## diff --git a/cmake/cmake_uninstall.cmake.in b/cmake/cmake_uninstall.cmake.in new file mode 100644 index 00000000..9f8083c2 --- /dev/null +++ b/cmake/cmake_uninstall.cmake.in @@ -0,0 +1,17 @@ +# Copyright 2024 Intel Corporation +# SPDX-License-Identifier: Apache 2.0 +# +# Uninstalls the files listed in install_manifest.txt. +# + +file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files) +string(REPLACE "\n" ";" files "${files}") + +foreach(file ${files}) + message(STATUS "Uninstalling ${file}") + if(EXISTS "${file}") + file(REMOVE "${file}") + else() + message(STATUS "File ${file} does not exist.") + endif() +endforeach()