diff options
-rwxr-xr-x | CMakeLists.txt | 4 | ||||
-rw-r--r-- | cmake/opentrack-clean-build-directory.cmake | 48 |
2 files changed, 51 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c2353d70..741d0c0d 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,8 +5,8 @@ include(opentrack-build) project(opentrack C CXX) cmake_minimum_required(VERSION 2.8.11) -include(opentrack-hier) include(opentrack-word-size) +include(opentrack-hier) include(opentrack-policy) include(opentrack-qt) include(opentrack-platform) @@ -14,6 +14,8 @@ include(opentrack-boilerplate) include(opentrack-version) include(opentrack-install) +add_custom_target(mrproper COMMAND cmake -P "${CMAKE_SOURCE_DIR}/cmake/opentrack-clean-build-directory.cmake" WORKING_DIRECTORY "${CMAKE_BINARY_DIR}") + set(C CMakeLists.txt) file(GLOB opentrack-subprojects "tracker-*/${C}" diff --git a/cmake/opentrack-clean-build-directory.cmake b/cmake/opentrack-clean-build-directory.cmake new file mode 100644 index 00000000..13c3c282 --- /dev/null +++ b/cmake/opentrack-clean-build-directory.cmake @@ -0,0 +1,48 @@ +function(cleanup_install_dir)
+ if(NOT $ENV{USERNAME} STREQUAL "sthalik")
+ message(WARNING "you can't run this potentially destructive function")
+ message(FATAL_ERROR "if you're sure, remove this line")
+ endif()
+
+ file(GLOB_RECURSE files LIST_DIRECTORIES TRUE RELATIVE "${CMAKE_BINARY_DIR}" "*")
+
+ set(files_ "")
+
+ set(got-install FALSE)
+ set(got-install-file FALSE)
+ set(got-cache FALSE)
+
+ foreach(i ${files})
+ if (i STREQUAL "install")
+ set(got-install TRUE)
+ continue()
+ endif()
+
+ string(FIND "${i}" "install/" pos)
+
+ if(pos GREATER -1)
+ set(got-install-file TRUE)
+ continue()
+ endif()
+
+ if(i STREQUAL "CMakeCache.txt")
+ set(got-cache TRUE)
+ continue()
+ endif()
+
+ list(APPEND files_ "${CMAKE_BINARY_DIR}/${i}")
+ endforeach()
+
+ unset(files)
+
+ if(NOT got-cache OR NOT got-install OR NOT got-install-file)
+ message(FATAL_ERROR "")
+ endif()
+
+ # let's hope nothing bad happens
+ file(REMOVE_RECURSE ${files_})
+
+ execute_process(COMMAND cmake . WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" OUTPUT_QUIET)
+endfunction()
+
+cleanup_install_dir()
|