diff options
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/RunCMake/add_custom_target/RunCMakeTest.cmake | 14 | ||||
-rw-r--r-- | Tests/RunCMake/add_custom_target/TargetOrder.cmake | 31 |
2 files changed, 45 insertions, 0 deletions
diff --git a/Tests/RunCMake/add_custom_target/RunCMakeTest.cmake b/Tests/RunCMake/add_custom_target/RunCMakeTest.cmake index 92c4a38..6c4e91b 100644 --- a/Tests/RunCMake/add_custom_target/RunCMakeTest.cmake +++ b/Tests/RunCMake/add_custom_target/RunCMakeTest.cmake @@ -4,3 +4,17 @@ run_cmake(NoArguments) run_cmake(BadTargetName) run_cmake(ByproductsNoCommand) run_cmake(UsesTerminalNoCommand) + +function(run_TargetOrder) + # Use a single build tree for a few tests without cleaning. + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/TargetOrder-build) + set(RunCMake_TEST_NO_CLEAN 1) + file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") + file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + run_cmake(TargetOrder) + if(RunCMake_GENERATOR STREQUAL "Ninja") + set(build_flags -j 1 -v) + endif() + run_cmake_command(TargetOrder-build ${CMAKE_COMMAND} --build . -- ${build_flags}) +endfunction() +run_TargetOrder() diff --git a/Tests/RunCMake/add_custom_target/TargetOrder.cmake b/Tests/RunCMake/add_custom_target/TargetOrder.cmake new file mode 100644 index 0000000..21669c0 --- /dev/null +++ b/Tests/RunCMake/add_custom_target/TargetOrder.cmake @@ -0,0 +1,31 @@ +# Add a target that requires step1 to run first but enforces +# it only by target-level ordering dependency. +add_custom_command( + OUTPUT step2.txt + COMMAND ${CMAKE_COMMAND} -E copy step1.txt step2.txt + ) +add_custom_target(step2 DEPENDS step2.txt) +add_dependencies(step2 step1) + +# Add a target that requires step1 and step2 to work, +# only depends on step1 transitively through step2, but +# also gets a copy of step2's custom command. +# The Ninja generator in particular must be careful with +# this case because it needs to compute the proper set of +# target ordering dependencies for the step2 custom command +# even though it appears in both the step2 and step3 +# targets due to dependency propagation. +add_custom_command( + OUTPUT step3.txt + COMMAND ${CMAKE_COMMAND} -E copy step1.txt step3-1.txt + COMMAND ${CMAKE_COMMAND} -E copy step2.txt step3.txt + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/step2.txt + ) +add_custom_target(step3 ALL DEPENDS step3.txt) +add_dependencies(step3 step2) + +# We want this target to always run first. Add it last so +# that serial builds require dependencies to order it first. +add_custom_target(step1 + COMMAND ${CMAKE_COMMAND} -E touch step1.txt + ) |