BUG: Don't return checkable flag for item when in the middle of configure/generate.
[cmake.git] / Tests / MakeClean / CMakeLists.txt
blobaaf39d79d9ccda708568b770eec7ec072040186a
1 cmake_minimum_required (VERSION 2.6)
2 PROJECT(MakeClean)
4 SET(CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}")
6 # Build the to-clean project.
7 TRY_COMPILE(TOCLEAN_BUILT
8   ${MakeClean_BINARY_DIR}/ToClean
9   ${MakeClean_SOURCE_DIR}/ToClean
10   ToClean
11   OUTPUT_VARIABLE OUTPUT
12   )
13 IF(TOCLEAN_BUILT)
14   MESSAGE(
15     "Building ToClean succeeded with the following output:\n"
16     "[${OUTPUT}]"
17     )
18 ELSE(TOCLEAN_BUILT)
19   MESSAGE(FATAL_ERROR
20     "Building ToClean failed with the following output:\n"
21     "[${OUTPUT}]"
22     )
23 ENDIF(TOCLEAN_BUILT)
25 # Get the set of files to check from the ToClean project.
26 INCLUDE(${MakeClean_BINARY_DIR}/ToClean/ToCleanFiles.cmake)
28 # Check for the existence of the files.
29 FOREACH(f ${TOCLEAN_FILES})
30   IF(EXISTS "${f}")
31   ELSE(EXISTS "${f}")
32     MESSAGE(FATAL_ERROR "File \"${f}\" does not exist!")
33   ENDIF(EXISTS "${f}")
34 ENDFOREACH(f)
36 # Enable ANSI flags for the C executable.
37 IF(CMAKE_ANSI_CFLAGS)
38   SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_ANSI_CFLAGS}")
39 ENDIF(CMAKE_ANSI_CFLAGS)
41 # Configure an executable to check that all the files are missing.
42 SET(CHECK_FILES)
43 FOREACH(f ${TOCLEAN_FILES})
44   SET(CHECK_FILES "${CHECK_FILES}      \"${f}\",\n")
45 ENDFOREACH(f)
46 CONFIGURE_FILE(${MakeClean_SOURCE_DIR}/check_clean.c.in
47                ${MakeClean_BINARY_DIR}/check_clean.c @ONLY IMMEDIATE)
48 ADD_EXECUTABLE(check_clean ${MakeClean_BINARY_DIR}/check_clean.c)
50 # After the executable builds, clean the files.
51 ADD_CUSTOM_COMMAND(
52   TARGET check_clean
53   POST_BUILD
54   COMMAND ${CMAKE_CTEST_COMMAND}
55   ARGS --build-and-test
56        ${MakeClean_SOURCE_DIR}/ToClean
57        ${MakeClean_BINARY_DIR}/ToClean
58        --build-generator ${CMAKE_GENERATOR}
59        --build-project ToClean
60        --build-makeprogram ${CMAKE_MAKE_PROGRAM}
61        --build-noclean
62        --build-target clean
63   COMMENT "Clean the ToClean Project"
64   )