diff options
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/MakeClean/CMakeLists.txt | 57 | ||||
-rw-r--r-- | Tests/MakeClean/ToClean/CMakeLists.txt | 22 | ||||
-rw-r--r-- | Tests/MakeClean/ToClean/ToCleanFiles.cmake.in | 1 | ||||
-rw-r--r-- | Tests/MakeClean/ToClean/toclean.cxx | 4 | ||||
-rw-r--r-- | Tests/MakeClean/check_clean.c.in | 26 |
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; +} |