Add suport for "make uninstall" to cmake.
authorWander Lairson Costa <wander.lairson@gmail.com>
Mon, 16 Jun 2014 10:58:09 -0300
changeset 887448d4f2d74d67
parent 8873 77ffe680093f
child 8875 c65a4cfdd8b2
Add suport for "make uninstall" to cmake.
CMakeLists.txt
cmake_uninstall.cmake.in
     1.1 --- a/CMakeLists.txt	Mon Jun 16 09:54:33 2014 -0300
     1.2 +++ b/CMakeLists.txt	Mon Jun 16 10:58:09 2014 -0300
     1.3 @@ -1308,3 +1308,12 @@
     1.4    install(TARGETS SDL2 RUNTIME DESTINATION bin)
     1.5  endif()
     1.6  
     1.7 +##### Uninstall target #####
     1.8 +
     1.9 +configure_file(
    1.10 +    "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
    1.11 +    "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
    1.12 +    IMMEDIATE @ONLY)
    1.13 +
    1.14 +add_custom_target(uninstall
    1.15 +    COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/cmake_uninstall.cmake.in	Mon Jun 16 10:58:09 2014 -0300
     2.3 @@ -0,0 +1,18 @@
     2.4 +if (NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
     2.5 +    message(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"")
     2.6 +endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
     2.7 +
     2.8 +file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
     2.9 +string(REGEX REPLACE "\n" ";" files "${files}")
    2.10 +foreach (file ${files})
    2.11 +    message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"")
    2.12 +    execute_process(
    2.13 +        COMMAND @CMAKE_COMMAND@ -E remove "$ENV{DESTDIR}${file}"
    2.14 +        OUTPUT_VARIABLE rm_out
    2.15 +        RESULT_VARIABLE rm_retval
    2.16 +    )
    2.17 +    if(NOT ${rm_retval} EQUAL 0)
    2.18 +        message(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"")
    2.19 +    endif (NOT ${rm_retval} EQUAL 0)
    2.20 +endforeach(file)
    2.21 +