Commit d040f3f1 authored by Sebastian Holtermann's avatar Sebastian Holtermann Committed by Brad King

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.
parent 3ed8cffe
...@@ -15,42 +15,45 @@ function(writeCleanFile FILENAME) ...@@ -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}") ...@@ -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
set(TgtPropFileAbs "${CBD}/TargetPropFileAbs.txt") # Register an absolute file path
writeCleanFile("${TgtPropFileAbs}") set(TgtPropFileAbs "${CBD}/${TARGET}_TargetPropFileAbs.txt")
set_property(TARGET toclean APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${TgtPropFileAbs}) writeCleanFile("${TgtPropFileAbs}")
addCleanFile("${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 # Create a custom command whose output should be cleaned, but whose name
set(TgtPropExpFileRel "TgtProp_copy${CMAKE_EXECUTABLE_SUFFIX}") # is not known until generate-time
set(TgtPropExpFile "$<TARGET_FILE_DIR:toclean>/${TgtPropExpFileRel}") set(TgtPropExpFileRel "${TARGET}_TargetPropGenExp.txt")
addToCleanPostBuildCopy("${TgtPropExpFile}") set(TgtPropExpFileAbs "$<TARGET_FILE_DIR:toclean>/${TgtPropExpFileRel}")
set_property(TARGET toclean APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${TgtPropExpFile}) addPostBuildFile(${TARGET} "${TgtPropExpFileAbs}")
addCleanFile("${CBD}/${TgtPropExpFileRel}") 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 # Process subdirectory without targets
add_subdirectory(EmptySubDir) add_subdirectory(EmptySubDir)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment