mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-16 05:26:58 +08:00
Tests: Extend MakeClean test to test various target types
This extends the MakeClean test to test the target property `ADDITIONAL_CLEAN_FILES` on executable, library and custom targets.
This commit is contained in:

committed by
Brad King

parent
3ed8cffe73
commit
d040f3f1ee
@@ -15,42 +15,45 @@ function(writeCleanFile FILENAME)
|
|||||||
file(WRITE "${FILENAME}" ${CLEAN_FILE_CONTENT})
|
file(WRITE "${FILENAME}" ${CLEAN_FILE_CONTENT})
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
set(DUMMY_CONTENT_FILE ${CSD}/toclean.cxx)
|
||||||
|
|
||||||
# Build a simple project whose compiled objects should be cleaned.
|
# Build a simple project whose compiled objects should be cleaned.
|
||||||
add_executable(toclean toclean.cxx)
|
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
|
# to a custom location
|
||||||
function(addToCleanPostBuildCopy FILENAME)
|
function(addPostBuildFile TARGET FILENAME)
|
||||||
add_custom_command(TARGET toclean POST_BUILD
|
add_custom_command(TARGET ${TARGET} POST_BUILD
|
||||||
COMMAND ${CMAKE_COMMAND}
|
COMMAND ${CMAKE_COMMAND}
|
||||||
ARGS -E copy $<TARGET_FILE:toclean> ${FILENAME})
|
ARGS -E copy ${DUMMY_CONTENT_FILE} ${FILENAME})
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
# Create a custom command whose output should be cleaned.
|
# Create a custom command whose output should be cleaned.
|
||||||
set(CustomCommandFile "${CBD}/CustomCommandFile.txt")
|
set(CustomCommandFile "${CBD}/CustomCommandFile.txt")
|
||||||
add_custom_command(OUTPUT ${CustomCommandFile}
|
add_custom_command(OUTPUT ${CustomCommandFile}
|
||||||
DEPENDS ${CSD}/toclean.cxx
|
DEPENDS ${DUMMY_CONTENT_FILE}
|
||||||
COMMAND ${CMAKE_COMMAND}
|
COMMAND ${CMAKE_COMMAND}
|
||||||
ARGS -E copy ${CSD}/toclean.cxx ${CustomCommandFile})
|
ARGS -E copy ${DUMMY_CONTENT_FILE} ${CustomCommandFile})
|
||||||
add_custom_target(generate ALL DEPENDS ${CustomCommandFile})
|
add_custom_target(customTarget ALL DEPENDS ${CustomCommandFile})
|
||||||
addCleanFile(${CustomCommandFile})
|
addCleanFile(${CustomCommandFile})
|
||||||
|
|
||||||
|
|
||||||
### Tests ADDITIONAL_MAKE_CLEAN_FILES directory property
|
### Tests ADDITIONAL_MAKE_CLEAN_FILES directory property
|
||||||
if("${CMAKE_GENERATOR}" MATCHES "Makefile")
|
if("${CMAKE_GENERATOR}" MATCHES "Makefile")
|
||||||
# Create a file that must be registered for cleaning.
|
# Create a file that must be registered for cleaning.
|
||||||
set(MakeDirPropFile "${CBD}/MakeDirPropFile.txt")
|
set(MakeDirPropFileAbs "${CBD}/MakeDirPropFile.txt")
|
||||||
writeCleanFile("${MakeDirPropFile}")
|
writeCleanFile("${MakeDirPropFileAbs}")
|
||||||
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${MakeDirPropFile}")
|
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${MakeDirPropFileAbs}")
|
||||||
addCleanFile(${MakeDirPropFile})
|
addCleanFile(${MakeDirPropFileAbs})
|
||||||
|
|
||||||
# Create a custom command whose output should be cleaned, but whose name
|
# Create a custom command whose output should be cleaned, but whose name
|
||||||
# is not known until generate-time
|
# is not known until generate-time
|
||||||
set(MakeDirPropExpFileRel "MakeDirProp_copy${CMAKE_EXECUTABLE_SUFFIX}")
|
set(MakeDirPropExpFileRel "MakeDirProp_copy${CMAKE_EXECUTABLE_SUFFIX}")
|
||||||
set(MakeDirPropExpFile "$<TARGET_FILE_DIR:toclean>/${MakeDirPropExpFileRel}")
|
set(MakeDirPropExpFileAbs "$<TARGET_FILE_DIR:toclean>/${MakeDirPropExpFileRel}")
|
||||||
addToCleanPostBuildCopy("${MakeDirPropExpFile}")
|
addPostBuildFile(toclean "${MakeDirPropExpFileAbs}")
|
||||||
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${MakeDirPropExpFile})
|
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${MakeDirPropExpFileAbs})
|
||||||
addCleanFile("${CBD}/${MakeDirPropExpFileRel}")
|
addCleanFile("${CBD}/${MakeDirPropExpFileRel}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@@ -72,34 +75,43 @@ addCleanFile("${DirPropFileAbs}")
|
|||||||
# Create a custom command whose output should be cleaned, but whose name
|
# Create a custom command whose output should be cleaned, but whose name
|
||||||
# is not known until generate-time
|
# is not known until generate-time
|
||||||
set(DirPropExpFileRel "DirProp_copy${CMAKE_EXECUTABLE_SUFFIX}")
|
set(DirPropExpFileRel "DirProp_copy${CMAKE_EXECUTABLE_SUFFIX}")
|
||||||
set(DirPropExpFile "$<TARGET_FILE_DIR:toclean>/${DirPropExpFileRel}")
|
set(DirPropExpFileAbs "$<TARGET_FILE_DIR:toclean>/${DirPropExpFileRel}")
|
||||||
addToCleanPostBuildCopy("${DirPropExpFile}")
|
addPostBuildFile(toclean "${DirPropExpFileAbs}")
|
||||||
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${DirPropExpFile})
|
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${DirPropExpFileAbs})
|
||||||
addCleanFile("${CBD}/${DirPropExpFileRel}")
|
addCleanFile("${CBD}/${DirPropExpFileRel}")
|
||||||
|
|
||||||
|
|
||||||
### Tests ADDITIONAL_CLEAN_FILES target property
|
### Tests ADDITIONAL_CLEAN_FILES target property
|
||||||
|
|
||||||
# Register a file path relative to the build directory
|
function(test_target_property TARGET)
|
||||||
set(TgtPropFileRel "TargetPropFileRel.txt")
|
# Register a file path relative to the build directory
|
||||||
writeCleanFile("${CBD}/${TgtPropFileRel}")
|
set(TgtPropFileRel "${TARGET}_TargetPropFileRel.txt")
|
||||||
set_target_properties(toclean PROPERTIES ADDITIONAL_CLEAN_FILES ${TgtPropFileRel})
|
writeCleanFile("${CBD}/${TgtPropFileRel}")
|
||||||
addCleanFile("${CBD}/${TgtPropFileRel}")
|
set_target_properties(${TARGET} PROPERTIES ADDITIONAL_CLEAN_FILES ${TgtPropFileRel})
|
||||||
|
addCleanFile("${CBD}/${TgtPropFileRel}")
|
||||||
|
|
||||||
# Register an absolute file path
|
# Register an absolute file path
|
||||||
set(TgtPropFileAbs "${CBD}/TargetPropFileAbs.txt")
|
set(TgtPropFileAbs "${CBD}/${TARGET}_TargetPropFileAbs.txt")
|
||||||
writeCleanFile("${TgtPropFileAbs}")
|
writeCleanFile("${TgtPropFileAbs}")
|
||||||
set_property(TARGET toclean APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${TgtPropFileAbs})
|
set_property(TARGET ${TARGET} APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${TgtPropFileAbs})
|
||||||
addCleanFile("${TgtPropFileAbs}")
|
addCleanFile("${TgtPropFileAbs}")
|
||||||
|
|
||||||
# Create a custom command whose output should be cleaned, but whose name
|
# Create a custom command whose output should be cleaned, but whose name
|
||||||
# is not known until generate-time
|
# is not known until generate-time
|
||||||
set(TgtPropExpFileRel "TgtProp_copy${CMAKE_EXECUTABLE_SUFFIX}")
|
set(TgtPropExpFileRel "${TARGET}_TargetPropGenExp.txt")
|
||||||
set(TgtPropExpFile "$<TARGET_FILE_DIR:toclean>/${TgtPropExpFileRel}")
|
set(TgtPropExpFileAbs "$<TARGET_FILE_DIR:toclean>/${TgtPropExpFileRel}")
|
||||||
addToCleanPostBuildCopy("${TgtPropExpFile}")
|
addPostBuildFile(${TARGET} "${TgtPropExpFileAbs}")
|
||||||
set_property(TARGET toclean APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${TgtPropExpFile})
|
set_property(TARGET ${TARGET} APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${TgtPropExpFileAbs})
|
||||||
addCleanFile("${CBD}/${TgtPropExpFileRel}")
|
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
|
# Process subdirectory without targets
|
||||||
add_subdirectory(EmptySubDir)
|
add_subdirectory(EmptySubDir)
|
||||||
|
Reference in New Issue
Block a user