From 651962702a6e01c067cf6ae7c2d87664750393a0 Mon Sep 17 00:00:00 2001 From: theraven Date: Sat, 22 Dec 2012 11:04:20 +0000 Subject: [PATCH] Add uninstall target to CMake. --- CMakeLists.txt | 15 ++++++++++++--- cmake_uninstall.cmake.in | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 cmake_uninstall.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f60577..388987d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,7 +97,7 @@ if (BOEHM_GC) else () find_library(LIBGC gc PATHS GC_LIBRARY_DIRS) endif () - message("-- Using Boehm GC library: ${LIBGC}") + message(STATUS "Using Boehm GC library: ${LIBGC}") include_directories(GC_INCLUDE_DIRS) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GC_CFLAGS}") set(CMAKE_OBJC_FLAGS "${CMAKE_OBJC_FLAGS} -fobjc-gc") @@ -158,13 +158,13 @@ endif (NOT CXX_RUNTIME) # for Objective-C and Objective-C++. If not, then we need to provide a # separate libobjcxx. if (CXX_RUNTIME) - message("-- Using ${CXX_RUNTIME} as the C++ runtime library") + message(STATUS "Using ${CXX_RUNTIME} as the C++ runtime library") set(libobjc_CXX_SRCS ${libobjcxx_CXX_SRCS}) # We don't want to link the STL implementation (e.g. libstdc++) if we have # a separate C++ runtime. set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "") else (CXX_RUNTIME) - message("-- No C++ runtime library found") + message(STATUS "No C++ runtime library found") add_library(objcxx SHARED ${libobjcxx_CXX_SRCS}) set_target_properties(objcxx PROPERTIES LINKER_LANGUAGE C @@ -262,3 +262,12 @@ if (UNIX) endif () include (CPack) +# uninstall target +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" + IMMEDIATE @ONLY) + +add_custom_target(uninstall + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) + diff --git a/cmake_uninstall.cmake.in b/cmake_uninstall.cmake.in new file mode 100644 index 0000000..c6d8094 --- /dev/null +++ b/cmake_uninstall.cmake.in @@ -0,0 +1,22 @@ +if (NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") + message(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"") +endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") + +file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) +string(REGEX REPLACE "\n" ";" files "${files}") +list(REVERSE files) +foreach (file ${files}) + message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"") + if (EXISTS "$ENV{DESTDIR}${file}") + execute_process( + COMMAND @CMAKE_COMMAND@ -E remove "$ENV{DESTDIR}${file}" + OUTPUT_VARIABLE rm_out + RESULT_VARIABLE rm_retval + ) + if(NOT ${rm_retval} EQUAL 0) + message(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"") + endif (NOT ${rm_retval} EQUAL 0) + else (EXISTS "$ENV{DESTDIR}${file}") + message(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.") + endif (EXISTS "$ENV{DESTDIR}${file}") +endforeach(file)