3 # Build a simple project.
4 ADD_EXECUTABLE(toclean toclean.cxx)
6 # List some build-time-generated files.
7 GET_TARGET_PROPERTY(TOCLEAN_FILES toclean LOCATION)
8 IF(CMAKE_GENERATOR_NEW)
9 SET(TOCLEAN_FILES ${TOCLEAN_FILES}
10 "${ToClean_BINARY_DIR}/toclean.dir/toclean${CMAKE_CXX_OUTPUT_EXTENSION}")
11 ELSE(CMAKE_GENERATOR_NEW)
12 SET(TOCLEAN_FILES ${TOCLEAN_FILES}
13 "${ToClean_BINARY_DIR}/toclean${CMAKE_CXX_OUTPUT_EXTENSION}")
14 ENDIF(CMAKE_GENERATOR_NEW)
16 # Create a file that must be registered for cleaning.
17 FILE(WRITE "${ToClean_BINARY_DIR}/Registered.txt"
18 "File registered for cleaning.\n")
19 SET_DIRECTORY_PROPERTIES(PROPERTIES
20 ADDITIONAL_MAKE_CLEAN_FILES "${ToClean_BINARY_DIR}/Registered.txt")
21 SET(TOCLEAN_FILES ${TOCLEAN_FILES} "${ToClean_BINARY_DIR}/Registered.txt")
23 # Create a custom command whose output should be cleaned.
24 IF(CMAKE_GENERATOR_NEW)
25 ADD_CUSTOM_COMMAND(OUTPUT ${ToClean_BINARY_DIR}/generated.txt
26 DEPENDS ${ToClean_SOURCE_DIR}/toclean.cxx
27 COMMAND ${CMAKE_COMMAND}
28 ARGS -E copy ${ToClean_SOURCE_DIR}/toclean.cxx
29 ${ToClean_BINARY_DIR}/generated.txt
31 ADD_CUSTOM_TARGET(generate ALL DEPENDS ${ToClean_BINARY_DIR}/generated.txt)
32 SET(TOCLEAN_FILES ${TOCLEAN_FILES} "${ToClean_BINARY_DIR}/generated.txt")
33 ENDIF(CMAKE_GENERATOR_NEW)
35 # Configure a file listing these build-time-generated files.
36 CONFIGURE_FILE(${ToClean_SOURCE_DIR}/ToCleanFiles.cmake.in
37 ${ToClean_BINARY_DIR}/ToCleanFiles.cmake @ONLY IMMEDIATE)