diff options
author | Brad King <brad.king@kitware.com> | 2019-08-27 14:11:06 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-08-27 14:11:06 (GMT) |
commit | b0566f62eb9de7d1baaf3d3d4bcdaea547e8ca86 (patch) | |
tree | d47fcb88b45ca3b08768c7654164ffb93925261f | |
parent | 290ab79f61508bac4ce44b15d2b3e661c4c32c32 (diff) | |
parent | d040f3f1eee237ca8cb35d7055a348a7c06fa572 (diff) | |
download | CMake-b0566f62eb9de7d1baaf3d3d4bcdaea547e8ca86.zip CMake-b0566f62eb9de7d1baaf3d3d4bcdaea547e8ca86.tar.gz CMake-b0566f62eb9de7d1baaf3d3d4bcdaea547e8ca86.tar.bz2 |
Merge branch 'ninja_additional_clean_files_custom_target' into release-3.15
Merge-request: !3739
-rw-r--r-- | Source/cmNinjaNormalTargetGenerator.cxx | 1 | ||||
-rw-r--r-- | Source/cmNinjaUtilityTargetGenerator.cxx | 3 | ||||
-rw-r--r-- | Tests/MakeClean/ToClean/CMakeLists.txt | 86 |
3 files changed, 53 insertions, 37 deletions
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index f65abc8..b7b822a 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -85,6 +85,7 @@ void cmNinjaNormalTargetGenerator::Generate() this->WriteLinkStatement(); } + // Find ADDITIONAL_CLEAN_FILES this->AdditionalCleanFiles(); } diff --git a/Source/cmNinjaUtilityTargetGenerator.cxx b/Source/cmNinjaUtilityTargetGenerator.cxx index 1225cbd..e774b53 100644 --- a/Source/cmNinjaUtilityTargetGenerator.cxx +++ b/Source/cmNinjaUtilityTargetGenerator.cxx @@ -135,6 +135,9 @@ void cmNinjaUtilityTargetGenerator::Generate() gg->WriteBuild(this->GetBuildFileStream(), phonyBuild); } + // Find ADDITIONAL_CLEAN_FILES + this->AdditionalCleanFiles(); + // Add an alias for the logical target name regardless of what directory // contains it. Skip this for GLOBAL_TARGET because they are meant to // be per-directory and have one at the top-level anyway. diff --git a/Tests/MakeClean/ToClean/CMakeLists.txt b/Tests/MakeClean/ToClean/CMakeLists.txt index 6f16d12..a05c38b 100644 --- a/Tests/MakeClean/ToClean/CMakeLists.txt +++ b/Tests/MakeClean/ToClean/CMakeLists.txt @@ -15,42 +15,45 @@ function(writeCleanFile FILENAME) file(WRITE "${FILENAME}" ${CLEAN_FILE_CONTENT}) endfunction() +set(DUMMY_CONTENT_FILE ${CSD}/toclean.cxx) + # Build a simple project whose compiled objects should be cleaned. add_executable(toclean toclean.cxx) -addCleanFile("${CBD}${CMAKE_FILES_DIRECTORY}/toclean.dir/toclean.cxx${CMAKE_CXX_OUTPUT_EXTENSION}") +addCleanFile( + "${CBD}${CMAKE_FILES_DIRECTORY}/toclean.dir/toclean.cxx${CMAKE_CXX_OUTPUT_EXTENSION}") -# Create a post build custom command that copies the toclean output executable +# Create a post build custom command that copies a dummy file # to a custom location -function(addToCleanPostBuildCopy FILENAME) - add_custom_command(TARGET toclean POST_BUILD +function(addPostBuildFile TARGET FILENAME) + add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_COMMAND} - ARGS -E copy $<TARGET_FILE:toclean> ${FILENAME}) + ARGS -E copy ${DUMMY_CONTENT_FILE} ${FILENAME}) endfunction() # Create a custom command whose output should be cleaned. set(CustomCommandFile "${CBD}/CustomCommandFile.txt") add_custom_command(OUTPUT ${CustomCommandFile} - DEPENDS ${CSD}/toclean.cxx + DEPENDS ${DUMMY_CONTENT_FILE} COMMAND ${CMAKE_COMMAND} - ARGS -E copy ${CSD}/toclean.cxx ${CustomCommandFile}) -add_custom_target(generate ALL DEPENDS ${CustomCommandFile}) + ARGS -E copy ${DUMMY_CONTENT_FILE} ${CustomCommandFile}) +add_custom_target(customTarget ALL DEPENDS ${CustomCommandFile}) addCleanFile(${CustomCommandFile}) ### Tests ADDITIONAL_MAKE_CLEAN_FILES directory property if("${CMAKE_GENERATOR}" MATCHES "Makefile") # Create a file that must be registered for cleaning. - set(MakeDirPropFile "${CBD}/MakeDirPropFile.txt") - writeCleanFile("${MakeDirPropFile}") - set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${MakeDirPropFile}") - addCleanFile(${MakeDirPropFile}) + set(MakeDirPropFileAbs "${CBD}/MakeDirPropFile.txt") + writeCleanFile("${MakeDirPropFileAbs}") + set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${MakeDirPropFileAbs}") + addCleanFile(${MakeDirPropFileAbs}) # 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}") - addToCleanPostBuildCopy("${MakeDirPropExpFile}") - set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${MakeDirPropExpFile}) + set(MakeDirPropExpFileAbs "$<TARGET_FILE_DIR:toclean>/${MakeDirPropExpFileRel}") + addPostBuildFile(toclean "${MakeDirPropExpFileAbs}") + set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${MakeDirPropExpFileAbs}) addCleanFile("${CBD}/${MakeDirPropExpFileRel}") endif() @@ -72,34 +75,43 @@ addCleanFile("${DirPropFileAbs}") # Create a custom command whose output should be cleaned, but whose name # is not known until generate-time set(DirPropExpFileRel "DirProp_copy${CMAKE_EXECUTABLE_SUFFIX}") -set(DirPropExpFile "$<TARGET_FILE_DIR:toclean>/${DirPropExpFileRel}") -addToCleanPostBuildCopy("${DirPropExpFile}") -set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${DirPropExpFile}) +set(DirPropExpFileAbs "$<TARGET_FILE_DIR:toclean>/${DirPropExpFileRel}") +addPostBuildFile(toclean "${DirPropExpFileAbs}") +set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${DirPropExpFileAbs}) addCleanFile("${CBD}/${DirPropExpFileRel}") ### Tests ADDITIONAL_CLEAN_FILES target property -# Register a file path relative to the build directory -set(TgtPropFileRel "TargetPropFileRel.txt") -writeCleanFile("${CBD}/${TgtPropFileRel}") -set_target_properties(toclean PROPERTIES ADDITIONAL_CLEAN_FILES ${TgtPropFileRel}) -addCleanFile("${CBD}/${TgtPropFileRel}") - -# Register an absolute file path -set(TgtPropFileAbs "${CBD}/TargetPropFileAbs.txt") -writeCleanFile("${TgtPropFileAbs}") -set_property(TARGET toclean APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${TgtPropFileAbs}) -addCleanFile("${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}") -addToCleanPostBuildCopy("${TgtPropExpFile}") -set_property(TARGET toclean APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${TgtPropExpFile}) -addCleanFile("${CBD}/${TgtPropExpFileRel}") +function(test_target_property TARGET) + # Register a file path relative to the build directory + set(TgtPropFileRel "${TARGET}_TargetPropFileRel.txt") + writeCleanFile("${CBD}/${TgtPropFileRel}") + set_target_properties(${TARGET} PROPERTIES ADDITIONAL_CLEAN_FILES ${TgtPropFileRel}) + addCleanFile("${CBD}/${TgtPropFileRel}") + + # Register an absolute file path + set(TgtPropFileAbs "${CBD}/${TARGET}_TargetPropFileAbs.txt") + writeCleanFile("${TgtPropFileAbs}") + set_property(TARGET ${TARGET} APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${TgtPropFileAbs}) + addCleanFile("${TgtPropFileAbs}") + + # Create a custom command whose output should be cleaned, but whose name + # is not known until generate-time + set(TgtPropExpFileRel "${TARGET}_TargetPropGenExp.txt") + set(TgtPropExpFileAbs "$<TARGET_FILE_DIR:toclean>/${TgtPropExpFileRel}") + addPostBuildFile(${TARGET} "${TgtPropExpFileAbs}") + set_property(TARGET ${TARGET} APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${TgtPropExpFileAbs}) + addCleanFile("${CBD}/${TgtPropExpFileRel}") +endfunction() +# Test target property for various target types +add_executable(acf_exec toclean.cxx) +test_target_property(acf_exec) +add_library(acf_lib toclean.cxx) +test_target_property(acf_lib) +add_custom_target(acf_custom ALL DEPENDS ${CustomCommandFile}) +test_target_property(acf_custom) # Process subdirectory without targets add_subdirectory(EmptySubDir) |