diff --git a/.travis.yml b/.travis.yml index 097781a4d4903027e5ec16ae9cc84e906531033a..37310a76a1aec730f98385a27d0869a6ec8c2ffd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,6 +36,7 @@ script: # Run unit tests - make test - # Make sure we can install with no issues + # Make sure we can install and uninstall with no issues - sudo make -j4 install + - sudo make -j4 uninstall diff --git a/CMakeLists.txt b/CMakeLists.txt index 41cfb3e8e819545347195e88c1da61a041d3c698..ec5eda945732999fc6eeeaf5a9571c5e255a6531 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -145,6 +145,13 @@ install(DIRECTORY include/ DESTINATION include install(FILES "${pkg_conf_file_out}" DESTINATION lib/pkgconfig/ COMPONENT pkgconfig) +# Add uninstall target +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/cmake_uninstall.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/CMakeModules/cmake_uninstall.cmake" + IMMEDIATE @ONLY) +add_custom_target(uninstall + "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/CMakeModules/cmake_uninstall.cmake") enable_testing() add_subdirectory(test) diff --git a/CMakeModules/cmake_uninstall.cmake.in b/CMakeModules/cmake_uninstall.cmake.in new file mode 100644 index 0000000000000000000000000000000000000000..14cd01d2bc9158871c44ca874d6f2026eeea6f57 --- /dev/null +++ b/CMakeModules/cmake_uninstall.cmake.in @@ -0,0 +1,21 @@ +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}") +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}" STREQUAL 0) + message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") + endif(NOT "${rm_retval}" STREQUAL 0) + else(EXISTS "$ENV{DESTDIR}${file}") + message(STATUS "File $ENV{DESTDIR}${file} does not exist.") + endif(EXISTS "$ENV{DESTDIR}${file}") +endforeach(file)