Skip to content

Commit

Permalink
sudo make uninstall の実行時にインストール時に作成されたディレクトリが削除されない不具合を修正
Browse files Browse the repository at this point in the history
  • Loading branch information
tsukumijima committed Aug 25, 2023
1 parent d957e65 commit 43c5b43
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions cmake/Uninstall.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ if(NOT EXISTS ${MANIFEST})
endif()

file(STRINGS ${MANIFEST} files)
set(dirs "")

foreach(file ${files})
if(EXISTS ${file} OR IS_SYMLINK ${file})
message(STATUS "Removing file: '${file}'")
Expand All @@ -18,7 +20,33 @@ foreach(file ${files})
if(NOT "${result}" STREQUAL 0)
message(FATAL_ERROR "Failed to remove file: '${file}'.")
endif()
else()
message(STATUS "File '${file}' does not exist.")

# Get the directory of the file and add it to the list
get_filename_component(dir ${file} DIRECTORY)
set(dirs ${dirs} ${dir})
endif()
endforeach(file)

# Remove empty directories
list(REMOVE_DUPLICATES dirs)
list(SORT dirs)
list(REVERSE dirs) # Start from the deepest directory

foreach(dir ${dirs})
if(IS_DIRECTORY ${dir})
file(GLOB children RELATIVE ${dir} ${dir}/*)

if(NOT children)
message(STATUS "Removing empty directory: '${dir}'")
exec_program(
${CMAKE_COMMAND} ARGS "-E remove_directory ${dir}"
OUTPUT_VARIABLE stdout
RETURN_VALUE result
)

if(NOT "${result}" STREQUAL 0)
message(FATAL_ERROR "Failed to remove directory: '${dir}'.")
endif()
endif()
endif()
endforeach(dir)

0 comments on commit 43c5b43

Please sign in to comment.