diff options
Diffstat (limited to 'cmake/scripts/common/Uninstall.cmake')
| -rw-r--r-- | cmake/scripts/common/Uninstall.cmake | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/cmake/scripts/common/Uninstall.cmake b/cmake/scripts/common/Uninstall.cmake index 5660e19..5753857 100644 --- a/cmake/scripts/common/Uninstall.cmake +++ b/cmake/scripts/common/Uninstall.cmake | |||
| @@ -1,9 +1,40 @@ | |||
| 1 | macro(remove_empty_dirs) | ||
| 2 | list(REMOVE_DUPLICATES DIRECTORIES) | ||
| 3 | unset(PDIRECTORIES) | ||
| 4 | foreach(dir IN LISTS DIRECTORIES) | ||
| 5 | if(EXISTS $ENV{DESTDIR}${dir}) | ||
| 6 | file(GLOB _res $ENV{DESTDIR}${dir}/*) | ||
| 7 | list(LENGTH _res _len) | ||
| 8 | if(_len EQUAL 0 AND EXISTS $ENV{DESTDIR}${dir}) | ||
| 9 | message(STATUS "Removing empty dir: ${dir}") | ||
| 10 | execute_process( | ||
| 11 | COMMAND ${CMAKE_COMMAND} -E remove_directory $ENV{DESTDIR}${dir} | ||
| 12 | OUTPUT_VARIABLE rm_out | ||
| 13 | RESULT_VARIABLE rm_retval | ||
| 14 | ) | ||
| 15 | if(NOT "${rm_retval}" STREQUAL 0) | ||
| 16 | message(FATAL_ERROR "Failed to remove directory: $ENV{DESTDIR}${dir}") | ||
| 17 | endif() | ||
| 18 | get_filename_component(_pdir $ENV{DESTDIR}${dir} DIRECTORY) | ||
| 19 | list(APPEND PDIRECTORIES ${_pdir}) | ||
| 20 | endif() | ||
| 21 | endif() | ||
| 22 | endforeach() | ||
| 23 | list(LENGTH PDIRECTORIES _plen) | ||
| 24 | if(_plen GREATER 0) | ||
| 25 | set(DIRECTORIES ${PDIRECTORIES}) | ||
| 26 | remove_empty_dirs() | ||
| 27 | endif() | ||
| 28 | endmacro() | ||
| 29 | |||
| 1 | # Uninstall target | 30 | # Uninstall target |
| 2 | set(MANIFEST ${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt) | 31 | set(MANIFEST ${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt) |
| 3 | if(EXISTS ${MANIFEST}) | 32 | if(EXISTS ${MANIFEST}) |
| 4 | file(STRINGS ${MANIFEST} files) | 33 | file(STRINGS ${MANIFEST} files) |
| 5 | foreach(file IN LISTS files) | 34 | foreach(file IN LISTS files) |
| 6 | if(EXISTS $ENV{DESTDIR}${file}) | 35 | if(EXISTS $ENV{DESTDIR}${file}) |
| 36 | get_filename_component(_dir $ENV{DESTDIR}${file} DIRECTORY) | ||
| 37 | list(APPEND DIRECTORIES $ENV{DESTDIR}${_dir}) | ||
| 7 | message(STATUS "Uninstalling: ${file}") | 38 | message(STATUS "Uninstalling: ${file}") |
| 8 | execute_process( | 39 | execute_process( |
| 9 | COMMAND ${CMAKE_COMMAND} -E remove $ENV{DESTDIR}${file} | 40 | COMMAND ${CMAKE_COMMAND} -E remove $ENV{DESTDIR}${file} |
| @@ -17,6 +48,11 @@ if(EXISTS ${MANIFEST}) | |||
| 17 | message(STATUS "File does not exist: $ENV{DESTDIR}${file}") | 48 | message(STATUS "File does not exist: $ENV{DESTDIR}${file}") |
| 18 | endif() | 49 | endif() |
| 19 | endforeach(file) | 50 | endforeach(file) |
| 51 | |||
| 52 | # delete empty dirs | ||
| 53 | if(DIRECTORIES) | ||
| 54 | remove_empty_dirs() | ||
| 55 | endif() | ||
| 20 | else() | 56 | else() |
| 21 | message(STATUS "Cannot find install manifest: '${MANIFEST}'") | 57 | message(STATUS "Cannot find install manifest: '${MANIFEST}'") |
| 22 | endif() | 58 | endif() |
