generate-configure-options.tcl 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/usr/bin/tclsh
  2. set cachefile [lindex $argv 0]
  3. if { $cachefile == "" } {
  4. puts stderr "Usage: [file tail $argv0] <existing CMakeCache.txt file>"
  5. exit 1
  6. }
  7. set struct {
  8. name
  9. type
  10. value
  11. description
  12. }
  13. set fd [open $cachefile r]
  14. set cached ""
  15. set dbase ""
  16. while {[gets $fd line] != -1 } {
  17. set line [string trim $line]
  18. # Hash comment
  19. if { [string index $line 0] == "#" } {
  20. continue
  21. }
  22. # empty line
  23. if { $line == "" } {
  24. set cached ""
  25. continue
  26. }
  27. if { [string range $line 0 1] == "//" } {
  28. set linepart [string range $line 2 end]
  29. # Variable description. Add to cache.
  30. if { $cached != "" && [string index $cached end] != " " && [string index $linepart 0] != " " } {
  31. append cached " "
  32. }
  33. append cached $linepart
  34. }
  35. # Possibly a variable
  36. if [string is alpha [string index $line 0]] {
  37. # Note: this skips variables starting grom underscore.
  38. if { [string range $line 0 5] == "CMAKE_" } {
  39. # Skip variables with CMAKE_ prefix, they are internal.
  40. continue
  41. }
  42. lassign [split $line =] vartype value
  43. lassign [split $vartype :] var type
  44. # Store the variable now
  45. set storage [list $var $type $value $cached]
  46. set cached ""
  47. lappend dbase $storage
  48. continue
  49. }
  50. #puts stderr "Ignored line: $line"
  51. # Ignored.
  52. }
  53. # Now look over the stored variables
  54. set lenlimit 80
  55. foreach stor $dbase {
  56. lassign $stor {*}$struct
  57. if { [string length $description] > $lenlimit } {
  58. set description [string range $description 0 $lenlimit-2]...
  59. }
  60. if { $type in {STATIC INTERNAL} } {
  61. continue
  62. }
  63. # Check special case of CXX to turn back to c++.
  64. set pos [string first CXX $name]
  65. if { $pos != -1 } {
  66. # Check around, actually after XX should be no letter.
  67. if { $pos+3 >= [string length $name] || ![string is alpha [string index $name $pos+3]] } {
  68. set name [string replace $name $pos $pos+2 C++]
  69. }
  70. }
  71. set optname [string tolower [string map {_ -} $name]]
  72. # Variables of type bool are just empty.
  73. # Variables of other types must have =<value> added.
  74. # Lowercase cmake type will be used here.
  75. set optassign ""
  76. set def ""
  77. if { $type != "BOOL" } {
  78. set optassign "=<[string tolower $type]>"
  79. } else {
  80. # Supply default for boolean option
  81. set def " (default: $value)"
  82. }
  83. puts " $optname$optassign \"$description$def\""
  84. }