summaryrefslogtreecommitdiff
path: root/Tests/MakeClean
diff options
context:
space:
mode:
Diffstat (limited to 'Tests/MakeClean')
-rw-r--r--Tests/MakeClean/CMakeLists.txt50
-rw-r--r--Tests/MakeClean/ToClean/CMakeLists.txt42
-rw-r--r--Tests/MakeClean/ToClean/ToCleanFiles.cmake.in1
-rw-r--r--Tests/MakeClean/ToClean/toclean.cxx4
-rw-r--r--Tests/MakeClean/check_clean.c.in26
5 files changed, 123 insertions, 0 deletions
diff --git a/Tests/MakeClean/CMakeLists.txt b/Tests/MakeClean/CMakeLists.txt
new file mode 100644
index 0000000000..8ac624a636
--- /dev/null
+++ b/Tests/MakeClean/CMakeLists.txt
@@ -0,0 +1,50 @@
+cmake_minimum_required (VERSION 2.6)
+project(MakeClean)
+
+# Build the to-clean project.
+try_compile(TOCLEAN_BUILT
+ ${MakeClean_BINARY_DIR}/ToClean
+ ${MakeClean_SOURCE_DIR}/ToClean
+ ToClean
+ OUTPUT_VARIABLE OUTPUT
+ )
+if(TOCLEAN_BUILT)
+ message(
+ "Building ToClean succeeded with the following output:\n"
+ "[${OUTPUT}]"
+ )
+else()
+ message(FATAL_ERROR
+ "Building ToClean failed with the following output:\n"
+ "[${OUTPUT}]"
+ )
+endif()
+
+# Get the set of files to check from the ToClean project.
+include(${MakeClean_BINARY_DIR}/ToClean/ToCleanFiles.cmake)
+
+# Check for the existence of the files.
+foreach(f ${TOCLEAN_FILES})
+ if(EXISTS "${f}")
+ else()
+ message(FATAL_ERROR "File \"${f}\" does not exist!")
+ endif()
+endforeach()
+
+# Configure an executable to check that all the files are missing.
+set(CHECK_FILES)
+foreach(f ${TOCLEAN_FILES})
+ set(CHECK_FILES "${CHECK_FILES} \"${f}\",\n")
+endforeach()
+configure_file(${MakeClean_SOURCE_DIR}/check_clean.c.in
+ ${MakeClean_BINARY_DIR}/check_clean.c @ONLY)
+add_executable(check_clean ${MakeClean_BINARY_DIR}/check_clean.c)
+
+# After the executable builds, clean the files.
+add_custom_command(
+ TARGET check_clean
+ POST_BUILD
+ COMMAND ${CMAKE_COMMAND} --build ${MakeClean_BINARY_DIR}/ToClean
+ --target clean
+ COMMENT "Clean the ToClean Project"
+ )
diff --git a/Tests/MakeClean/ToClean/CMakeLists.txt b/Tests/MakeClean/ToClean/CMakeLists.txt
new file mode 100644
index 0000000000..d0e24cefe3
--- /dev/null
+++ b/Tests/MakeClean/ToClean/CMakeLists.txt
@@ -0,0 +1,42 @@
+cmake_minimum_required(VERSION 2.6)
+project(ToClean)
+
+# Build a simple project.
+add_executable(toclean toclean.cxx)
+
+# List some build-time-generated files.
+set(TOCLEAN_FILES ${TOCLEAN_FILES}
+ "${ToClean_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/toclean.dir/toclean.cxx${CMAKE_CXX_OUTPUT_EXTENSION}")
+
+# Create a file that must be registered for cleaning.
+file(WRITE "${ToClean_BINARY_DIR}/Registered.txt"
+ "File registered for cleaning.\n")
+set_directory_properties(PROPERTIES
+ ADDITIONAL_MAKE_CLEAN_FILES "${ToClean_BINARY_DIR}/Registered.txt")
+set(TOCLEAN_FILES ${TOCLEAN_FILES} "${ToClean_BINARY_DIR}/Registered.txt")
+
+# Create a custom command whose output should be cleaned.
+add_custom_command(OUTPUT ${ToClean_BINARY_DIR}/generated.txt
+ DEPENDS ${ToClean_SOURCE_DIR}/toclean.cxx
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E copy ${ToClean_SOURCE_DIR}/toclean.cxx
+ ${ToClean_BINARY_DIR}/generated.txt
+ )
+add_custom_target(generate ALL DEPENDS ${ToClean_BINARY_DIR}/generated.txt)
+set(TOCLEAN_FILES ${TOCLEAN_FILES} "${ToClean_BINARY_DIR}/generated.txt")
+
+# Create a custom command whose output should be cleaned, but whose name
+# is not known until generate-time
+set(copied_exe "$<TARGET_FILE_DIR:toclean>/toclean_copy${CMAKE_EXECUTABLE_SUFFIX}")
+add_custom_command(TARGET toclean POST_BUILD
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E copy $<TARGET_FILE:toclean>
+ ${copied_exe}
+ )
+set_property(DIRECTORY APPEND PROPERTY
+ ADDITIONAL_MAKE_CLEAN_FILES ${copied_exe})
+list(APPEND TOCLEAN_FILES "${ToClean_BINARY_DIR}/toclean_copy${CMAKE_EXECUTABLE_SUFFIX}")
+
+# Configure a file listing these build-time-generated files.
+configure_file(${ToClean_SOURCE_DIR}/ToCleanFiles.cmake.in
+ ${ToClean_BINARY_DIR}/ToCleanFiles.cmake @ONLY)
diff --git a/Tests/MakeClean/ToClean/ToCleanFiles.cmake.in b/Tests/MakeClean/ToClean/ToCleanFiles.cmake.in
new file mode 100644
index 0000000000..e7d99470cb
--- /dev/null
+++ b/Tests/MakeClean/ToClean/ToCleanFiles.cmake.in
@@ -0,0 +1 @@
+set(TOCLEAN_FILES "@TOCLEAN_FILES@")
diff --git a/Tests/MakeClean/ToClean/toclean.cxx b/Tests/MakeClean/ToClean/toclean.cxx
new file mode 100644
index 0000000000..f8b643afbf
--- /dev/null
+++ b/Tests/MakeClean/ToClean/toclean.cxx
@@ -0,0 +1,4 @@
+int main()
+{
+ return 0;
+}
diff --git a/Tests/MakeClean/check_clean.c.in b/Tests/MakeClean/check_clean.c.in
new file mode 100644
index 0000000000..5bc4ab8807
--- /dev/null
+++ b/Tests/MakeClean/check_clean.c.in
@@ -0,0 +1,26 @@
+#include <stdio.h>
+
+int main()
+{
+ /* The list of files to check. */
+ const char* files[] =
+ {
+ @CHECK_FILES@
+ 0
+ };
+
+ /* No file should exist. */
+ const char** f = files;
+ int result = 0;
+ for(; *f; ++f)
+ {
+ FILE* pf = fopen(*f, "rb");
+ if(pf)
+ {
+ fclose(pf);
+ fprintf(stderr, "File \"%s\" exists!", *f);
+ result = 1;
+ }
+ }
+ return result;
+}