Skip to content

Commit aeef9db

Browse files
committed
Add uninstall target to generated Makefile
1 parent fbdc201 commit aeef9db

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,17 @@ target_link_libraries(OpenCoarrays INTERFACE caf_mpi)
139139

140140
install(DIRECTORY ${CMAKE_BINARY_DIR}/mod DESTINATION .)
141141

142+
#------------------------------------------
143+
# Add portable unistall command to makefile
144+
#------------------------------------------
145+
# Adapted from the CMake Wiki FAQ
146+
configure_file ( "${CMAKE_SOURCE_DIR}/cmake/uninstall.cmake.in" "${CMAKE_BINARY_DIR}/uninstall.cmake"
147+
@ONLY)
148+
149+
add_custom_target ( uninstall
150+
COMMAND ${CMAKE_COMMAND} -P "${CMAKE_BINARY_DIR}/uninstall.cmake" )
151+
152+
142153
enable_testing()
143154

144155
function(add_mpi_test name num_mpi_proc path)

cmake/uninstall.cmake.in

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Adapted from http://www.cmake.org/Wiki/CMake_FAQ#Can_I_do_.22make_uninstall.22_with_CMake.3F May 1, 2014
2+
3+
if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
4+
message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt")
5+
endif(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
6+
7+
file(READ "@CMAKE_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+
exec_program(
13+
"@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
14+
OUTPUT_VARIABLE rm_out
15+
RETURN_VALUE 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)