diff --git a/CMakeLists.txt b/CMakeLists.txt index 34b89f2b9..a7a4b4be7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,3 +99,7 @@ if(RYML_BUILD_TESTS OR RYML_BUILD_BENCHMARKS) endif() c4_add_dev_targets() + +add_custom_target(uninstall + "${CMAKE_COMMAND}" -P "${PROJECT_SOURCE_DIR}/cmake/uninstall.cmake" +) diff --git a/cmake/uninstall.cmake b/cmake/uninstall.cmake new file mode 100644 index 000000000..5ac7ceb6d --- /dev/null +++ b/cmake/uninstall.cmake @@ -0,0 +1,24 @@ +set(MANIFEST "${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt") + +if(NOT EXISTS ${MANIFEST}) + message(FATAL_ERROR "Cannot find install manifest: '${MANIFEST}'") +endif() + +file(STRINGS ${MANIFEST} files) +foreach(file ${files}) + if(EXISTS ${file}) + message(STATUS "Removing file: '${file}'") + + exec_program( + ${CMAKE_COMMAND} ARGS "-E remove ${file}" + OUTPUT_VARIABLE stdout + RETURN_VALUE result + ) + + if(NOT "${result}" STREQUAL 0) + message(FATAL_ERROR "Failed to remove file: '${file}'.") + endif() + else() + MESSAGE(STATUS "File '${file}' does not exist.") + endif() +endforeach(file)