Skip to content

Commit 9ff83cf

Browse files
committed
Add the uninstall target
Signed-off-by: Lukasz Dorau <[email protected]>
1 parent 7ba518d commit 9ff83cf

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,11 @@ install(
170170
${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}-config.cmake
171171
${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}-config-version.cmake
172172
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
173+
174+
configure_file(
175+
"${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
176+
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
177+
IMMEDIATE @ONLY)
178+
179+
add_custom_target(uninstall
180+
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)

cmake/cmake_uninstall.cmake.in

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# From: https://cmake.org/Uncyclo/CMake_FAQ
2+
3+
if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
4+
message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
5+
endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
6+
7+
file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
8+
string(REGEX REPLACE "\n" ";" files "${files}")
9+
foreach(file ${files})
10+
message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
11+
if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
12+
execute_process(
13+
COMMAND @CMAKE_COMMAND@ -E remove $ENV{DESTDIR}${file}
14+
OUTPUT_VARIABLE rm_out
15+
RESULT_VARIABLE rm_retval
16+
)
17+
if(NOT "${rm_retval}" STREQUAL 0)
18+
message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
19+
endif(NOT "${rm_retval}" STREQUAL 0)
20+
else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
21+
message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
22+
endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
23+
endforeach(file)

0 commit comments

Comments
 (0)