CMakeLists.txt 1.31 KB
Newer Older
Ken Martin's avatar
Ken Martin committed
1
cmake_minimum_required (VERSION 2.6)
2
project(MakeClean)
3 4

# Build the to-clean project.
5
try_compile(TOCLEAN_BUILT
6 7 8 9 10
  ${MakeClean_BINARY_DIR}/ToClean
  ${MakeClean_SOURCE_DIR}/ToClean
  ToClean
  OUTPUT_VARIABLE OUTPUT
  )
11 12
if(TOCLEAN_BUILT)
  message(
13 14 15
    "Building ToClean succeeded with the following output:\n"
    "[${OUTPUT}]"
    )
16
else()
17
  message(FATAL_ERROR
18 19 20
    "Building ToClean failed with the following output:\n"
    "[${OUTPUT}]"
    )
21
endif()
22 23

# Get the set of files to check from the ToClean project.
24
include(${MakeClean_BINARY_DIR}/ToClean/ToCleanFiles.cmake)
25 26

# Check for the existence of the files.
27 28
foreach(f ${TOCLEAN_FILES})
  if(EXISTS "${f}")
29
  else()
30
    message(FATAL_ERROR "File \"${f}\" does not exist!")
31 32
  endif()
endforeach()
33 34

# Configure an executable to check that all the files are missing.
35 36
set(CHECK_FILES)
foreach(f ${TOCLEAN_FILES})
37
  string(APPEND CHECK_FILES "      \"${f}\",\n")
38
endforeach()
39
configure_file(${MakeClean_SOURCE_DIR}/check_clean.c.in
40
               ${MakeClean_BINARY_DIR}/check_clean.c @ONLY)
41
add_executable(check_clean ${MakeClean_BINARY_DIR}/check_clean.c)
42 43

# After the executable builds, clean the files.
44
add_custom_command(
45 46
  TARGET check_clean
  POST_BUILD
47 48
  COMMAND ${CMAKE_COMMAND} --build ${MakeClean_BINARY_DIR}/ToClean
          --target clean
49 50
  COMMENT "Clean the ToClean Project"
  )