separate_arguments.rst 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. separate_arguments
  2. ------------------
  3. Parse command-line arguments into a semicolon-separated list.
  4. .. code-block:: cmake
  5. separate_arguments(<variable> <mode> <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 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. .. _`Parsing C Command-Line Arguments`: https://msdn.microsoft.com/library/a1y7w461.aspx
  29. .. code-block:: cmake
  30. separate_arguments(<var>)
  31. Convert the value of ``<var>`` to a semi-colon separated list. All
  32. spaces are replaced with ';'. This helps with generating command
  33. lines.