add_custom_target.rst 3.4 KB

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