diff options
author | Brad King <brad.king@kitware.com> | 2019-05-15 13:21:59 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2019-05-15 13:22:18 (GMT) |
commit | 66efdbd21a46b63572f5de677ed126a68e524e7a (patch) | |
tree | ca828de9a043ff83bd321185b1c23de9a6b2a788 /Tests | |
parent | 0064edf4173fad72749da2c66753387e9a671223 (diff) | |
parent | b5bf369ec68a60bf71297e941bcc742904aae148 (diff) | |
download | CMake-66efdbd21a46b63572f5de677ed126a68e524e7a.zip CMake-66efdbd21a46b63572f5de677ed126a68e524e7a.tar.gz CMake-66efdbd21a46b63572f5de677ed126a68e524e7a.tar.bz2 |
Merge topic 'additional_clean_files'
b5bf369ec6 Release notes: Add release notes for ADDITIONAL_CLEAN_FILES properties
4e2ce0a67a Doc: Update and deprecate ADDITIONAL_MAKE_CLEAN_FILES directory property
338994d65d Doc: Add documentation for ADDITIONAL_CLEAN_FILES properties
c11f089d73 Tests: Extend MakeClean test to cover ADDITIONAL_CLEAN_FILES
012d599e26 Ninja: Add support for ADDITIONAL_CLEAN_FILES target property
890a1b9dc3 Ninja: Add support for ADDITIONAL_CLEAN_FILES directory property
7b23001f20 Ninja: Add support for additional clean files
d745df4b01 Makefiles: Add support for ADDITIONAL_CLEAN_FILES target property
...
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3318
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/CMakeLists.txt | 3 | ||||
-rw-r--r-- | Tests/MakeClean/ToClean/CMakeLists.txt | 112 | ||||
-rw-r--r-- | Tests/MakeClean/check_clean.c.in | 2 |
3 files changed, 87 insertions, 30 deletions
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index bc4812b..d992986 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -2007,7 +2007,8 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release ADD_TEST_MACRO(CheckCompilerRelatedVariables CheckCompilerRelatedVariables) - if("${CMAKE_GENERATOR}" MATCHES "Makefile") + if("${CMAKE_GENERATOR}" MATCHES "Makefile" OR + "${CMAKE_GENERATOR}" MATCHES "Ninja") add_test(MakeClean ${CMAKE_CTEST_COMMAND} --build-and-test "${CMake_SOURCE_DIR}/Tests/MakeClean" diff --git a/Tests/MakeClean/ToClean/CMakeLists.txt b/Tests/MakeClean/ToClean/CMakeLists.txt index d0e24ce..5d84e6c 100644 --- a/Tests/MakeClean/ToClean/CMakeLists.txt +++ b/Tests/MakeClean/ToClean/CMakeLists.txt @@ -1,42 +1,98 @@ -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 3.14) project(ToClean) -# Build a simple project. -add_executable(toclean toclean.cxx) +# Utility variables +set(TSD ${ToClean_SOURCE_DIR}) +set(TBD ${ToClean_BINARY_DIR}) +set(CLEAN_FILE_CONTENT "File registered for cleaning.\n") -# List some build-time-generated files. -set(TOCLEAN_FILES ${TOCLEAN_FILES} - "${ToClean_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/toclean.dir/toclean.cxx${CMAKE_CXX_OUTPUT_EXTENSION}") +# Lists build-time-generated files that should be cleaned away +set(TOCLEAN_FILES) -# Create a file that must be registered for cleaning. -file(WRITE "${ToClean_BINARY_DIR}/Registered.txt" - "File registered for cleaning.\n") -set_directory_properties(PROPERTIES - ADDITIONAL_MAKE_CLEAN_FILES "${ToClean_BINARY_DIR}/Registered.txt") -set(TOCLEAN_FILES ${TOCLEAN_FILES} "${ToClean_BINARY_DIR}/Registered.txt") +# Build a simple project whose compiled objects should be cleaned. +add_executable(toclean toclean.cxx) +list(APPEND TOCLEAN_FILES + "${TBD}${CMAKE_FILES_DIRECTORY}/toclean.dir/toclean.cxx${CMAKE_CXX_OUTPUT_EXTENSION}") # Create a custom command whose output should be cleaned. -add_custom_command(OUTPUT ${ToClean_BINARY_DIR}/generated.txt - DEPENDS ${ToClean_SOURCE_DIR}/toclean.cxx +set(CustomCommandFile "${TBD}/CustomCommandFile.txt") +add_custom_command(OUTPUT ${CustomCommandFile} + DEPENDS ${TSD}/toclean.cxx COMMAND ${CMAKE_COMMAND} - ARGS -E copy ${ToClean_SOURCE_DIR}/toclean.cxx - ${ToClean_BINARY_DIR}/generated.txt - ) -add_custom_target(generate ALL DEPENDS ${ToClean_BINARY_DIR}/generated.txt) -set(TOCLEAN_FILES ${TOCLEAN_FILES} "${ToClean_BINARY_DIR}/generated.txt") + ARGS -E copy ${TSD}/toclean.cxx ${CustomCommandFile}) +add_custom_target(generate ALL DEPENDS ${CustomCommandFile}) +list(APPEND TOCLEAN_FILES ${CustomCommandFile}) + + +### Tests ADDITIONAL_MAKE_CLEAN_FILES directory property +if("${CMAKE_GENERATOR}" MATCHES "Makefile") + # Create a file that must be registered for cleaning. + set(MakeDirPropFile "${TBD}/MakeDirPropFile.txt") + file(WRITE "${MakeDirPropFile}" ${CLEAN_FILE_CONTENT}) + set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${MakeDirPropFile}") + list(APPEND TOCLEAN_FILES "${MakeDirPropFile}") + + # Create a custom command whose output should be cleaned, but whose name + # is not known until generate-time + set(MakeDirPropExpFileRel "MakeDirProp_copy${CMAKE_EXECUTABLE_SUFFIX}") + set(MakeDirPropExpFile "$<TARGET_FILE_DIR:toclean>/${MakeDirPropExpFileRel}") + add_custom_command(TARGET toclean POST_BUILD + COMMAND ${CMAKE_COMMAND} + ARGS -E copy $<TARGET_FILE:toclean> ${MakeDirPropExpFile}) + set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${MakeDirPropExpFile}) + list(APPEND TOCLEAN_FILES "${TBD}/${MakeDirPropExpFileRel}") +endif() + + +### Tests ADDITIONAL_CLEAN_FILES directory property + +# Register a file path relative to the build directory +set(DirPropFileRel "DirPropFileRel.txt") +file(WRITE "${TBD}/${DirPropFileRel}" ${CLEAN_FILE_CONTENT}) +set_directory_properties(PROPERTIES ADDITIONAL_CLEAN_FILES ${DirPropFileRel}) +list(APPEND TOCLEAN_FILES "${TBD}/${DirPropFileRel}") + +# Register an absolute file path +set(DirPropFileAbs "${TBD}/DirPropFileAbs.txt") +file(WRITE "${DirPropFileAbs}" ${CLEAN_FILE_CONTENT}) +set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${DirPropFileAbs}) +list(APPEND TOCLEAN_FILES "${DirPropFileAbs}") # Create a custom command whose output should be cleaned, but whose name # is not known until generate-time -set(copied_exe "$<TARGET_FILE_DIR:toclean>/toclean_copy${CMAKE_EXECUTABLE_SUFFIX}") +set(DirPropExpFileRel "DirProp_copy${CMAKE_EXECUTABLE_SUFFIX}") +set(DirPropExpFile "$<TARGET_FILE_DIR:toclean>/${DirPropExpFileRel}") add_custom_command(TARGET toclean POST_BUILD COMMAND ${CMAKE_COMMAND} - ARGS -E copy $<TARGET_FILE:toclean> - ${copied_exe} - ) -set_property(DIRECTORY APPEND PROPERTY - ADDITIONAL_MAKE_CLEAN_FILES ${copied_exe}) -list(APPEND TOCLEAN_FILES "${ToClean_BINARY_DIR}/toclean_copy${CMAKE_EXECUTABLE_SUFFIX}") + ARGS -E copy $<TARGET_FILE:toclean> ${DirPropExpFile}) +set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${DirPropExpFile}) +list(APPEND TOCLEAN_FILES "${TBD}/${DirPropExpFileRel}") + + +### Tests ADDITIONAL_CLEAN_FILES target property + +# Register a file path relative to the build directory +set(TgtPropFileRel "TargetPropFileRel.txt") +file(WRITE "${TBD}/${TgtPropFileRel}" ${CLEAN_FILE_CONTENT}) +set_target_properties(toclean PROPERTIES ADDITIONAL_CLEAN_FILES ${TgtPropFileRel}) +list(APPEND TOCLEAN_FILES "${TBD}/${TgtPropFileRel}") + +# Register an absolute file path +set(TgtPropFileAbs "${TBD}/TargetPropFileAbs.txt") +file(WRITE "${TgtPropFileAbs}" ${CLEAN_FILE_CONTENT}) +set_property(TARGET toclean APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${TgtPropFileAbs}) +list(APPEND TOCLEAN_FILES "${TgtPropFileAbs}") + +# Create a custom command whose output should be cleaned, but whose name +# is not known until generate-time +set(TgtPropExpFileRel "TgtProp_copy${CMAKE_EXECUTABLE_SUFFIX}") +set(TgtPropExpFile "$<TARGET_FILE_DIR:toclean>/${TgtPropExpFileRel}") +add_custom_command(TARGET toclean POST_BUILD + COMMAND ${CMAKE_COMMAND} + ARGS -E copy $<TARGET_FILE:toclean> ${TgtPropExpFile}) +set_property(TARGET toclean APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${TgtPropExpFile}) +list(APPEND TOCLEAN_FILES "${TBD}/${TgtPropExpFileRel}") + # Configure a file listing these build-time-generated files. -configure_file(${ToClean_SOURCE_DIR}/ToCleanFiles.cmake.in - ${ToClean_BINARY_DIR}/ToCleanFiles.cmake @ONLY) +configure_file(${TSD}/ToCleanFiles.cmake.in ${TBD}/ToCleanFiles.cmake @ONLY) diff --git a/Tests/MakeClean/check_clean.c.in b/Tests/MakeClean/check_clean.c.in index 5bc4ab8..e5a7945 100644 --- a/Tests/MakeClean/check_clean.c.in +++ b/Tests/MakeClean/check_clean.c.in @@ -18,7 +18,7 @@ int main() if(pf) { fclose(pf); - fprintf(stderr, "File \"%s\" exists!", *f); + fprintf(stderr, "File \"%s\" still exists!\n", *f); result = 1; } } |