File: TargetOrder.cmake

package info (click to toggle)
cmake 4.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 152,344 kB
  • sloc: ansic: 403,894; cpp: 303,807; sh: 4,097; python: 3,582; yacc: 3,106; lex: 1,279; f90: 538; asm: 471; lisp: 375; cs: 270; java: 266; fortran: 239; objc: 215; perl: 213; xml: 198; makefile: 108; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22
file content (31 lines) | stat: -rw-r--r-- 1,180 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
  )