CMakeLists.txt 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. cmake_minimum_required (VERSION 2.6)
  2. project(MakeClean)
  3. # Build the to-clean project.
  4. try_compile(TOCLEAN_BUILT
  5. ${MakeClean_BINARY_DIR}/ToClean
  6. ${MakeClean_SOURCE_DIR}/ToClean
  7. ToClean
  8. OUTPUT_VARIABLE OUTPUT
  9. )
  10. if(TOCLEAN_BUILT)
  11. message(
  12. "Building ToClean succeeded with the following output:\n"
  13. "[${OUTPUT}]"
  14. )
  15. else()
  16. message(FATAL_ERROR
  17. "Building ToClean failed with the following output:\n"
  18. "[${OUTPUT}]"
  19. )
  20. endif()
  21. # Get the set of files to check from the ToClean project.
  22. include(${MakeClean_BINARY_DIR}/ToClean/ToCleanFiles.cmake)
  23. # Check for the existence of the files.
  24. foreach(f ${TOCLEAN_FILES})
  25. if(EXISTS "${f}")
  26. else()
  27. message(FATAL_ERROR "File \"${f}\" does not exist!")
  28. endif()
  29. endforeach()
  30. # Configure an executable to check that all the files are missing.
  31. set(CHECK_FILES)
  32. foreach(f ${TOCLEAN_FILES})
  33. string(APPEND CHECK_FILES " \"${f}\",\n")
  34. endforeach()
  35. configure_file(${MakeClean_SOURCE_DIR}/check_clean.c.in
  36. ${MakeClean_BINARY_DIR}/check_clean.c @ONLY)
  37. add_executable(check_clean ${MakeClean_BINARY_DIR}/check_clean.c)
  38. # After the executable builds, clean the files.
  39. add_custom_command(
  40. TARGET check_clean
  41. POST_BUILD
  42. COMMAND ${CMAKE_COMMAND} --build ${MakeClean_BINARY_DIR}/ToClean
  43. --target clean
  44. COMMENT "Clean the ToClean Project"
  45. )