1 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
4 # Build a simple project.
5 ADD_EXECUTABLE(toclean toclean.cxx)
7 # List some build-time-generated files.
8 GET_TARGET_PROPERTY(TOCLEAN_FILES toclean LOCATION)
9 SET(TOCLEAN_FILES ${TOCLEAN_FILES}
10 "${ToClean_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/toclean.dir/toclean.cxx${CMAKE_CXX_OUTPUT_EXTENSION}")
12 # Create a file that must be registered for cleaning.
13 FILE(WRITE "${ToClean_BINARY_DIR}/Registered.txt"
14 "File registered for cleaning.\n")
15 SET_DIRECTORY_PROPERTIES(PROPERTIES
16 ADDITIONAL_MAKE_CLEAN_FILES "${ToClean_BINARY_DIR}/Registered.txt")
17 SET(TOCLEAN_FILES ${TOCLEAN_FILES} "${ToClean_BINARY_DIR}/Registered.txt")
19 # Create a custom command whose output should be cleaned.
20 ADD_CUSTOM_COMMAND(OUTPUT ${ToClean_BINARY_DIR}/generated.txt
21 DEPENDS ${ToClean_SOURCE_DIR}/toclean.cxx
22 COMMAND ${CMAKE_COMMAND}
23 ARGS -E copy ${ToClean_SOURCE_DIR}/toclean.cxx
24 ${ToClean_BINARY_DIR}/generated.txt
26 ADD_CUSTOM_TARGET(generate ALL DEPENDS ${ToClean_BINARY_DIR}/generated.txt)
27 SET(TOCLEAN_FILES ${TOCLEAN_FILES} "${ToClean_BINARY_DIR}/generated.txt")
29 # Configure a file listing these build-time-generated files.
30 CONFIGURE_FILE(${ToClean_SOURCE_DIR}/ToCleanFiles.cmake.in
31 ${ToClean_BINARY_DIR}/ToCleanFiles.cmake @ONLY IMMEDIATE)