string.rst 5.9 KB

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