separate_arguments.rst 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. separate_arguments
  2. ------------------
  3. Parse command-line arguments into a semicolon-separated list.
  4. .. code-block:: cmake
  5. separate_arguments(<variable> <mode> [PROGRAM [SEPARATE_ARGS]] <args>)
  6. Parses a space-separated string ``<args>`` into a list of items,
  7. and stores this list in semicolon-separated standard form in ``<variable>``.
  8. This function is intended for parsing command-line arguments.
  9. The entire command line must be passed as one string in the
  10. argument ``<args>``.
  11. The exact parsing rules depend on the operating system.
  12. They are specified by the ``<mode>`` argument which must
  13. be one of the following keywords:
  14. ``UNIX_COMMAND``
  15. Arguments are separated by unquoted whitespace.
  16. Both single-quote and double-quote pairs are respected.
  17. A backslash escapes the next literal character (``\"`` is ``"``);
  18. there are no special escapes (``\n`` is just ``n``).
  19. ``WINDOWS_COMMAND``
  20. A Windows command-line is parsed using the same
  21. syntax the runtime library uses to construct argv at startup. It
  22. separates arguments by whitespace that is not double-quoted.
  23. Backslashes are literal unless they precede double-quotes. See the
  24. MSDN article `Parsing C Command-Line Arguments`_ for details.
  25. ``NATIVE_COMMAND``
  26. Proceeds as in ``WINDOWS_COMMAND`` mode if the host system is Windows.
  27. Otherwise proceeds as in ``UNIX_COMMAND`` mode.
  28. ``PROGRAM``
  29. The first item in ``<args>`` is assumed to be an executable and will be
  30. searched in the system search path or left as a full path. If not found,
  31. ``<variable>`` will be empty. Otherwise, ``<variable>`` is a list of 2
  32. elements:
  33. 0. Absolute path of the program
  34. 1. Any command-line arguments present in ``<args>`` as a string
  35. For example:
  36. .. code-block:: cmake
  37. separate_arguments (out UNIX_COMMAND PROGRAM "cc -c main.c")
  38. * First element of the list: ``/path/to/cc``
  39. * Second element of the list: ``" -c main.c"``
  40. ``SEPARATE_ARGS``
  41. When this sub-option of ``PROGRAM`` option is specified, command-line
  42. arguments will be split as well and stored in ``<variable>``.
  43. For example:
  44. .. code-block:: cmake
  45. separate_arguments (out UNIX_COMMAND PROGRAM SEPARATE_ARGS "cc -c main.c")
  46. The contents of ``out`` will be: ``/path/to/cc;-c;main.c``
  47. .. _`Parsing C Command-Line Arguments`: https://msdn.microsoft.com/library/a1y7w461.aspx
  48. .. code-block:: cmake
  49. separate_arguments(<var>)
  50. Convert the value of ``<var>`` to a semi-colon separated list. All
  51. spaces are replaced with ';'. This helps with generating command
  52. lines.