summaryrefslogtreecommitdiffstats
path: root/Tests/MakeClean
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2005-02-09 14:21:01 (GMT)
committerBrad King <brad.king@kitware.com>2005-02-09 14:21:01 (GMT)
commit41b2216594093a2070c5eb7523c61fab7ff3f40e (patch)
tree9c8e302ed1446f73e9ba6fc170bc92004ec16dbf /Tests/MakeClean
parentf6f765e86f88210025d8cec8be562835972ad102 (diff)
downloadCMake-41b2216594093a2070c5eb7523c61fab7ff3f40e.zip
CMake-41b2216594093a2070c5eb7523c61fab7ff3f40e.tar.gz
CMake-41b2216594093a2070c5eb7523c61fab7ff3f40e.tar.bz2
ENH: Adding test of "make clean".
Diffstat (limited to 'Tests/MakeClean')
-rw-r--r--Tests/MakeClean/CMakeLists.txt57
-rw-r--r--Tests/MakeClean/ToClean/CMakeLists.txt22
-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, 110 insertions, 0 deletions
diff --git a/Tests/MakeClean/CMakeLists.txt b/Tests/MakeClean/CMakeLists.txt
new file mode 100644
index 0000000..a1a292c
--- /dev/null
+++ b/Tests/MakeClean/CMakeLists.txt
@@ -0,0 +1,57 @@
+PROJECT(MakeClean)
+
+# Build the to-clean project.
+TRY_COMPILE(TOCLEAN_BUILT
+ ${MakeClean_BINARY_DIR}/ToClean
+ ${MakeClean_SOURCE_DIR}/ToClean
+ ToClean
+ toclean
+ OUTPUT_VARIABLE OUTPUT
+ )
+IF(TOCLEAN_BUILT)
+ MESSAGE(
+ "Building ToClean succeeded with the following output:\n"
+ "[${OUTPUT}]"
+ )
+ELSE(TOCLEAN_BUILT)
+ MESSAGE(FATAL_ERROR
+ "Building ToClean failed with the following output:\n"
+ "[${OUTPUT}]"
+ )
+ENDIF(TOCLEAN_BUILT)
+
+# 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(EXISTS "${f}")
+ MESSAGE(FATAL_ERROR "File \"${f}\" does not exist!")
+ ENDIF(EXISTS "${f}")
+ENDFOREACH(f)
+
+# 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(f)
+CONFIGURE_FILE(${MakeClean_SOURCE_DIR}/check_clean.c.in
+ ${MakeClean_BINARY_DIR}/check_clean.c @ONLY IMMEDIATE)
+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_CTEST_COMMAND}
+ ARGS --build-and-test
+ ${MakeClean_SOURCE_DIR}/ToClean
+ ${MakeClean_BINARY_DIR}/ToClean
+ --build-generator ${CMAKE_GENERATOR}
+ --build-project ToClean
+ --build-makeprogram ${CMAKE_MAKE_PROGRAM}
+ --build-noclean
+ --build-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 0000000..49507f4
--- /dev/null
+++ b/Tests/MakeClean/ToClean/CMakeLists.txt
@@ -0,0 +1,22 @@
+PROJECT(ToClean)
+
+# Build a simple project.
+ADD_EXECUTABLE(toclean toclean.cxx)
+
+# List some build-time-generated files.
+GET_TARGET_PROPERTY(TOCLEAN_FILES toclean LOCATION)
+SET(TOCLEAN_FILES ${TOCLEAN_FILES}
+ "${ToClean_BINARY_DIR}/toclean${CMAKE_CXX_OUTPUT_EXTENSION}")
+#SET(TOCLEAN_FILES ${TOCLEAN_FILES}
+# "${ToClean_BINARY_DIR}/toclean.dir/toclean${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")
+
+# Configure a file listing these build-time-generated files.
+CONFIGURE_FILE(${ToClean_SOURCE_DIR}/ToCleanFiles.cmake.in
+ ${ToClean_BINARY_DIR}/ToCleanFiles.cmake @ONLY IMMEDIATE)
diff --git a/Tests/MakeClean/ToClean/ToCleanFiles.cmake.in b/Tests/MakeClean/ToClean/ToCleanFiles.cmake.in
new file mode 100644
index 0000000..10d11c3
--- /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 0000000..f8b643a
--- /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 0000000..5bc4ab8
--- /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;
+}