ENH: Adding test of "make clean".

This commit is contained in:
Brad King 2005-02-09 09:21:01 -05:00
parent f6f765e86f
commit 41b2216594
5 changed files with 110 additions and 0 deletions

View File

@ -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"
)

View File

@ -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)

View File

@ -0,0 +1 @@
SET(TOCLEAN_FILES "@TOCLEAN_FILES@")

View File

@ -0,0 +1,4 @@
int main()
{
return 0;
}

View File

@ -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;
}