Skip to content

Commit 3a7c7b5

Browse files
dtbpkmteNhiNguyencmt8
authored andcommitted
Add uninstall target
1 parent 9545d0d commit 3a7c7b5

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

CMakeLists.txt

+12
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,17 @@ install(
7474
DESTINATION lib/cmake/huron/Modules
7575
)
7676

77+
# Uninstall target
78+
# Source: https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake
79+
if(NOT TARGET uninstall)
80+
configure_file(
81+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
82+
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
83+
IMMEDIATE @ONLY)
84+
85+
add_custom_target(uninstall
86+
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
87+
endif()
88+
7789
# Build examples
7890
add_subdirectory(examples)

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,10 @@ Notes:
4343
- Currently, the project can be built on Linux only
4444
- By default, the project builds for Raspberry Pi (armv7l). To change platform,
4545
`BUILD_TYPE` needs to be changed. For example, on Linux x86_64: `-DBUILD_TYPE=x86_64`
46+
47+
Uninstall:
48+
49+
```
50+
cd build
51+
sudo make uninstall
52+
```

cmake_uninstall.cmake.in

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Source: https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake
2+
if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
3+
message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt")
4+
endif()
5+
6+
file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
7+
string(REGEX REPLACE "\n" ";" files "${files}")
8+
foreach(file ${files})
9+
message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
10+
if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
11+
exec_program(
12+
"@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
13+
OUTPUT_VARIABLE rm_out
14+
RETURN_VALUE rm_retval
15+
)
16+
if(NOT "${rm_retval}" STREQUAL 0)
17+
message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
18+
endif()
19+
else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
20+
message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
21+
endif()
22+
endforeach()

0 commit comments

Comments
 (0)