CMake: Minor uninstall changes

* Fix missing CMAKE_UNINSTALL_PREFIX variable
* Use CMAKE_MINIMUM_REQUIRED instead of CMAKE_POLICY for IN_LIST support
* Use FILE(REMOVE …) instead of EXECUTE_PROCESS(…) for better performance
* Control flow changes
This commit is contained in:
Lukas W
2018-07-22 11:41:54 +02:00
parent 020ce8e4db
commit 63fd427c5e
2 changed files with 13 additions and 15 deletions

View File

@@ -614,7 +614,7 @@ ADD_CUSTOM_TARGET(dist
# add uninstall-target
#
ADD_CUSTOM_TARGET(uninstall
COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/uninstall.cmake"
COMMAND ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}" -P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/uninstall.cmake"
)

View File

@@ -1,3 +1,5 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.3)
MESSAGE(STATUS "Attempting to create uninstall target for make")
#Remove all of the files listed in install_manifest.txt
@@ -8,24 +10,20 @@ ENDIF()
MESSAGE(STATUS "install_manifest.txt found")
FILE(STRINGS ${INSTALL_MANIFEST_PATH} FILES_TO_REMOVE)
FOREACH(FILE_TO_REMOVE ${FILES_TO_REMOVE})
IF(EXISTS ${FILE_TO_REMOVE})
EXECUTE_PROCESS(
COMMAND ${CMAKE_COMMAND} -E remove ${FILE_TO_REMOVE}
RESULT_VARIABLE EXIT_CODE
)
IF(${EXIT_CODE} EQUAL 0)
MESSAGE(STATUS "Successfully removed file ${FILE_TO_REMOVE}")
ELSE()
MESSAGE(FATAL_ERROR "Failed to remove file ${FILE_TO_REMOVE} with error code ${EXIT_CODE}")
ENDIF()
ELSE()
IF(NOT EXISTS "${FILE_TO_REMOVE}")
MESSAGE(WARNING "Could not find file ${FILE_TO_REMOVE}")
CONTINUE()
ENDIF()
FILE(REMOVE "${FILE_TO_REMOVE}")
IF(NOT EXISTS "${FILE_TO_REMOVE}")
MESSAGE(STATUS "Successfully removed file ${FILE_TO_REMOVE}")
ELSE()
MESSAGE(FATAL_ERROR "Failed to remove file ${FILE_TO_REMOVE}.")
ENDIF()
ENDFOREACH(FILE_TO_REMOVE)
#Remove empty directories created during installation
#Required to support IN_LIST operator
CMAKE_POLICY(SET CMP0057 NEW)
# Remove empty directories created during installation
# Checks if a directory is empty and saves the result in out_var
FUNCTION(IS_EMPTY_DIR OUT_VAR DIR)