string.rst 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. string
  2. ------
  3. String operations.
  4. ::
  5. string(REGEX MATCH <regular_expression>
  6. <output variable> <input> [<input>...])
  7. string(REGEX MATCHALL <regular_expression>
  8. <output variable> <input> [<input>...])
  9. string(REGEX REPLACE <regular_expression>
  10. <replace_expression> <output variable>
  11. <input> [<input>...])
  12. string(REPLACE <match_string>
  13. <replace_string> <output variable>
  14. <input> [<input>...])
  15. string(CONCAT <output variable> [<input>...])
  16. string(<MD5|SHA1|SHA224|SHA256|SHA384|SHA512>
  17. <output variable> <input>)
  18. string(COMPARE EQUAL <string1> <string2> <output variable>)
  19. string(COMPARE NOTEQUAL <string1> <string2> <output variable>)
  20. string(COMPARE LESS <string1> <string2> <output variable>)
  21. string(COMPARE GREATER <string1> <string2> <output variable>)
  22. string(ASCII <number> [<number> ...] <output variable>)
  23. string(CONFIGURE <string1> <output variable>
  24. [@ONLY] [ESCAPE_QUOTES])
  25. string(TOUPPER <string1> <output variable>)
  26. string(TOLOWER <string1> <output variable>)
  27. string(LENGTH <string> <output variable>)
  28. string(SUBSTRING <string> <begin> <length> <output variable>)
  29. string(STRIP <string> <output variable>)
  30. string(RANDOM [LENGTH <length>] [ALPHABET <alphabet>]
  31. [RANDOM_SEED <seed>] <output variable>)
  32. string(FIND <string> <substring> <output variable> [REVERSE])
  33. string(TIMESTAMP <output variable> [<format string>] [UTC])
  34. string(MAKE_C_IDENTIFIER <input string> <output variable>)
  35. string(GENEX_STRIP <input string> <output variable>)
  36. string(UUID <output variable> NAMESPACE <namespace> NAME <name>
  37. TYPE <MD5|SHA1> [UPPER])
  38. REGEX MATCH will match the regular expression once and store the match
  39. in the output variable.
  40. REGEX MATCHALL will match the regular expression as many times as
  41. possible and store the matches in the output variable as a list.
  42. REGEX REPLACE will match the regular expression as many times as
  43. possible and substitute the replacement expression for the match in
  44. the output. The replace expression may refer to paren-delimited
  45. subexpressions of the match using \1, \2, ..., \9. Note that two
  46. backslashes (\\1) are required in CMake code to get a backslash
  47. through argument parsing.
  48. REPLACE will replace all occurrences of match_string in the input with
  49. replace_string and store the result in the output.
  50. CONCAT will concatenate all the input arguments together and store
  51. the result in the named output variable.
  52. MD5, SHA1, SHA224, SHA256, SHA384, and SHA512 will compute a
  53. cryptographic hash of the input string.
  54. COMPARE EQUAL/NOTEQUAL/LESS/GREATER will compare the strings and store
  55. true or false in the output variable.
  56. ASCII will convert all numbers into corresponding ASCII characters.
  57. CONFIGURE will transform a string like CONFIGURE_FILE transforms a
  58. file.
  59. TOUPPER/TOLOWER will convert string to upper/lower characters.
  60. LENGTH will return a given string's length.
  61. SUBSTRING will return a substring of a given string. If length is -1
  62. the remainder of the string starting at begin will be returned.
  63. STRIP will return a substring of a given string with leading and
  64. trailing spaces removed.
  65. RANDOM will return a random string of given length consisting of
  66. characters from the given alphabet. Default length is 5 characters
  67. and default alphabet is all numbers and upper and lower case letters.
  68. If an integer RANDOM_SEED is given, its value will be used to seed the
  69. random number generator.
  70. FIND will return the position where the given substring was found in
  71. the supplied string. If the REVERSE flag was used, the command will
  72. search for the position of the last occurrence of the specified
  73. substring.
  74. The following characters have special meaning in regular expressions:
  75. ::
  76. ^ Matches at beginning of input
  77. $ Matches at end of input
  78. . Matches any single character
  79. [ ] Matches any character(s) inside the brackets
  80. [^ ] Matches any character(s) not inside the brackets
  81. - Inside brackets, specifies an inclusive range between
  82. characters on either side e.g. [a-f] is [abcdef]
  83. To match a literal - using brackets, make it the first
  84. or the last character e.g. [+*/-] matches basic
  85. mathematical operators.
  86. * Matches preceding pattern zero or more times
  87. + Matches preceding pattern one or more times
  88. ? Matches preceding pattern zero or once only
  89. | Matches a pattern on either side of the |
  90. () Saves a matched subexpression, which can be referenced
  91. in the REGEX REPLACE operation. Additionally it is saved
  92. by all regular expression-related commands, including
  93. e.g. if( MATCHES ), in the variables CMAKE_MATCH_(0..9).
  94. ``*``, ``+`` and ``?`` have higher precedence than concatenation. | has lower
  95. precedence than concatenation. This means that the regular expression
  96. "^ab+d$" matches "abbd" but not "ababd", and the regular expression
  97. "^(ab|cd)$" matches "ab" but not "abd".
  98. TIMESTAMP will write a string representation of the current date
  99. and/or time to the output variable.
  100. Should the command be unable to obtain a timestamp the output variable
  101. will be set to the empty string "".
  102. The optional UTC flag requests the current date/time representation to
  103. be in Coordinated Universal Time (UTC) rather than local time.
  104. The optional <format string> may contain the following format
  105. specifiers:
  106. ::
  107. %d The day of the current month (01-31).
  108. %H The hour on a 24-hour clock (00-23).
  109. %I The hour on a 12-hour clock (01-12).
  110. %j The day of the current year (001-366).
  111. %m The month of the current year (01-12).
  112. %M The minute of the current hour (00-59).
  113. %S The second of the current minute.
  114. 60 represents a leap second. (00-60)
  115. %U The week number of the current year (00-53).
  116. %w The day of the current week. 0 is Sunday. (0-6)
  117. %y The last two digits of the current year (00-99)
  118. %Y The current year.
  119. Unknown format specifiers will be ignored and copied to the output
  120. as-is.
  121. If no explicit <format string> is given it will default to:
  122. ::
  123. %Y-%m-%dT%H:%M:%S for local time.
  124. %Y-%m-%dT%H:%M:%SZ for UTC.
  125. MAKE_C_IDENTIFIER will write a string which can be used as an
  126. identifier in C.
  127. ``GENEX_STRIP`` will strip any
  128. :manual:`generator expressions <cmake-generator-expressions(7)>` from the
  129. ``input string`` and store the result in the ``output variable``.
  130. UUID creates a univerally unique identifier (aka GUID) as per RFC4122
  131. based on the hash of the combined values of <namespace>
  132. (which itself has to be a valid UUID) and <name>.
  133. The hash algorithm can be either ``MD5`` (Version 3 UUID) or
  134. ``SHA1`` (Version 5 UUID).
  135. A UUID has the format ``xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx``
  136. where each `x` represents a lower case hexadecimal character.
  137. Where required an uppercase representation can be requested
  138. with the optional ``UPPER`` flag.