macro.rst 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. macro
  2. -----
  3. Start recording a macro for later invocation as a command.
  4. ::
  5. macro(<name> [arg1 [arg2 [arg3 ...]]])
  6. COMMAND1(ARGS ...)
  7. COMMAND2(ARGS ...)
  8. ...
  9. endmacro(<name>)
  10. Define a macro named <name> that takes arguments named arg1 arg2 arg3
  11. (...). Commands listed after macro, but before the matching endmacro,
  12. are not invoked until the macro is invoked. When it is invoked, the
  13. commands recorded in the macro are first modified by replacing formal
  14. parameters (${arg1}) with the arguments passed, and then invoked as
  15. normal commands. In addition to referencing the formal parameters you
  16. can reference the values ${ARGC} which will be set to the number of
  17. arguments passed into the function as well as ${ARGV0} ${ARGV1}
  18. ${ARGV2} ... which will have the actual values of the arguments
  19. passed in. This facilitates creating macros with optional arguments.
  20. Additionally ${ARGV} holds the list of all arguments given to the
  21. macro and ${ARGN} holds the list of arguments past the last expected
  22. argument. Note that the parameters to a macro and values such as ARGN
  23. are not variables in the usual CMake sense. They are string
  24. replacements much like the C preprocessor would do with a macro. If
  25. you want true CMake variables and/or better CMake scope control you
  26. should look at the function command.
  27. See the cmake_policy() command documentation for the behavior of
  28. policies inside macros.