TargetOrder.cmake 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. # Add a target that requires step1 to run first but enforces
  2. # it only by target-level ordering dependency.
  3. add_custom_command(
  4. OUTPUT step2.txt
  5. COMMAND ${CMAKE_COMMAND} -E copy step1.txt step2.txt
  6. )
  7. add_custom_target(step2 DEPENDS step2.txt)
  8. add_dependencies(step2 step1)
  9. # Add a target that requires step1 and step2 to work,
  10. # only depends on step1 transitively through step2, but
  11. # also gets a copy of step2's custom command.
  12. # The Ninja generator in particular must be careful with
  13. # this case because it needs to compute the proper set of
  14. # target ordering dependencies for the step2 custom command
  15. # even though it appears in both the step2 and step3
  16. # targets due to dependency propagation.
  17. add_custom_command(
  18. OUTPUT step3.txt
  19. COMMAND ${CMAKE_COMMAND} -E copy step1.txt step3-1.txt
  20. COMMAND ${CMAKE_COMMAND} -E copy step2.txt step3.txt
  21. DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/step2.txt
  22. )
  23. add_custom_target(step3 ALL DEPENDS step3.txt)
  24. add_dependencies(step3 step2)
  25. # We want this target to always run first. Add it last so
  26. # that serial builds require dependencies to order it first.
  27. add_custom_target(step1
  28. COMMAND ${CMAKE_COMMAND} -E touch step1.txt
  29. )