string.rst 6.3 KB

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