string.rst 6.1 KB

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