add_custom_target.rst 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. add_custom_target
  2. -----------------
  3. Add a target with no output so it will always be built.
  4. ::
  5. add_custom_target(Name [ALL] [command1 [args1...]]
  6. [COMMAND command2 [args2...] ...]
  7. [DEPENDS depend depend depend ... ]
  8. [WORKING_DIRECTORY dir]
  9. [COMMENT comment] [VERBATIM]
  10. [SOURCES src1 [src2...]])
  11. Adds a target with the given name that executes the given commands.
  12. The target has no output file and is *always considered out of date*
  13. even if the commands try to create a file with the name of the target.
  14. Use the :command:`add_custom_command` command to generate a file with
  15. dependencies. By default nothing depends on the custom target. Use
  16. the :command:`add_dependencies` command to add dependencies to or
  17. from other targets.
  18. The options are:
  19. ``ALL``
  20. Indicate that this target should be added to the default build
  21. target so that it will be run every time (the command cannot be
  22. called ``ALL``).
  23. ``COMMAND``
  24. Specify the command-line(s) to execute at build time.
  25. If more than one ``COMMAND`` is specified they will be executed in order,
  26. but *not* necessarily composed into a stateful shell or batch script.
  27. (To run a full script, use the :command:`configure_file` command or the
  28. :command:`file(GENERATE)` command to create it, and then specify
  29. a ``COMMAND`` to launch it.)
  30. If ``COMMAND`` specifies an executable target (created by the
  31. :command:`add_executable` command) it will automatically be replaced
  32. by the location of the executable created at build time.
  33. Additionally a target-level dependency will be added so that the
  34. executable target will be built before this custom target.
  35. Arguments to ``COMMAND`` may use
  36. :manual:`generator expressions <cmake-generator-expressions(7)>`.
  37. References to target names in generator expressions imply target-level
  38. dependencies.
  39. The command and arguments are optional and if not specified an empty
  40. target will be created.
  41. ``COMMENT``
  42. Display the given message before the commands are executed at
  43. build time.
  44. ``DEPENDS``
  45. Reference files and outputs of custom commands created with
  46. :command:`add_custom_command` command calls in the same directory
  47. (``CMakeLists.txt`` file). They will be brought up to date when
  48. the target is built.
  49. ``SOURCES``
  50. Specify additional source files to be included in the custom target.
  51. Specified source files will be added to IDE project files for
  52. convenience in editing even if they have no build rules.
  53. ``VERBATIM``
  54. All arguments to the commands will be escaped properly for the
  55. build tool so that the invoked command receives each argument
  56. unchanged. Note that one level of escapes is still used by the
  57. CMake language processor before ``add_custom_target`` even sees
  58. the arguments. Use of ``VERBATIM`` is recommended as it enables
  59. correct behavior. When ``VERBATIM`` is not given the behavior
  60. is platform specific because there is no protection of
  61. tool-specific special characters.
  62. ``WORKING_DIRECTORY``
  63. Execute the command with the given current working directory.
  64. If it is a relative path it will be interpreted relative to the
  65. build tree directory corresponding to the current source directory.