summaryrefslogtreecommitdiffstats
path: root/bootstrap
blob: 31e9b898a224af8405cabde3a958f7291394169c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
#!/bin/sh
#=============================================================================
# CMake - Cross Platform Makefile Generator
# Copyright 2000-2011 Kitware, Inc., Insight Software Consortium
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================

die() {
  echo "$@" 1>&2 ; exit 1
}

# Version number extraction function.
cmake_version_component()
{
  cat "${cmake_source_dir}/Source/CMakeVersion.cmake" | sed -n "
/^set(CMake_VERSION_${1}/ {s/set(CMake_VERSION_${1} *\([0-9]*\))/\1/;p;}
"
}

# Install destination extraction function.
cmake_install_dest_default()
{
  cat "${cmake_source_dir}/Source/CMakeInstallDestinations.cmake" | sed -n '
/^ *set(CMAKE_'"${1}"'_DIR_DEFAULT.*) # '"${2}"'$/ {
  s/^ *set(CMAKE_'"${1}"'_DIR_DEFAULT *"\([^"]*\)").*$/\1/
  s/${CMake_VERSION_MAJOR}/'"${cmake_version_major}"'/
  s/${CMake_VERSION_MINOR}/'"${cmake_version_minor}"'/
  s/${CMake_VERSION_PATCH}/'"${cmake_version_patch}"'/
  p
  q
}
'
}

cmake_toupper()
{
    echo "$1" | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'
}

# Detect system and directory information.
cmake_system=`uname`
cmake_source_dir=`cd "\`dirname \"$0\"\`";pwd`
cmake_binary_dir=`pwd`

# Load version information.
cmake_version_major="`cmake_version_component MAJOR`"
cmake_version_minor="`cmake_version_component MINOR`"
cmake_version_patch="`cmake_version_component PATCH`"
cmake_version="${cmake_version_major}.${cmake_version_minor}.${cmake_version_patch}"
cmake_version_rc="`cmake_version_component RC`"
if [ "$cmake_version_rc" != "" ]; then
  cmake_version="${cmake_version}-rc${cmake_version_rc}"
fi

cmake_copyright="`grep '^Copyright .* Kitware' "${cmake_source_dir}/Copyright.txt"`"

cmake_data_dir_keyword="OTHER"
cmake_doc_dir_keyword="OTHER"
cmake_man_dir_keyword="OTHER"
cmake_data_dir=""
cmake_doc_dir=""
cmake_man_dir=""
cmake_init_file=""
cmake_bootstrap_system_libs=""
cmake_bootstrap_qt_gui=""
cmake_bootstrap_qt_qmake=""
cmake_sphinx_man=""
cmake_sphinx_html=""
cmake_sphinx_qthelp=""
cmake_sphinx_build=""
cmake_sphinx_flags=""

# Determine whether this is a Cygwin environment.
if echo "${cmake_system}" | grep CYGWIN >/dev/null 2>&1; then
  cmake_system_cygwin=true
  cmake_doc_dir_keyword="CYGWIN"
  cmake_man_dir_keyword="CYGWIN"
else
  cmake_system_cygwin=false
fi

# Determine whether this is a MinGW environment.
if echo "${cmake_system}" | grep MINGW >/dev/null 2>&1; then
  cmake_system_mingw=true
else
  cmake_system_mingw=false
fi

# Determine whether this is OS X
if echo "${cmake_system}" | grep Darwin >/dev/null 2>&1; then
  cmake_system_darwin=true
else
  cmake_system_darwin=false
fi

# Determine whether this is BeOS
if echo "${cmake_system}" | grep BeOS >/dev/null 2>&1; then
  cmake_system_beos=true
  cmake_doc_dir_keyword="HAIKU"
  cmake_man_dir_keyword="HAIKU"
else
  cmake_system_beos=false
fi

# Determine whether this is Haiku
if echo "${cmake_system}" | grep Haiku >/dev/null 2>&1; then
  cmake_system_haiku=true
  cmake_doc_dir_keyword="HAIKU"
  cmake_man_dir_keyword="HAIKU"
else
  cmake_system_haiku=false
fi

# Determine whether this is OpenVMS
if echo "${cmake_system}" | grep OpenVMS >/dev/null 2>&1; then
  cmake_system_openvms=true
else
  cmake_system_openvms=false
fi

# Determine whether this is HP-UX
if echo "${cmake_system}" | grep HP-UX >/dev/null 2>&1; then
  cmake_system_hpux=true
else
  cmake_system_hpux=false
fi

# Determine whether this is Linux
if echo "${cmake_system}" | grep Linux >/dev/null 2>&1; then
  cmake_system_linux=true
else
  cmake_system_linux=false
 fi

# Determine whether this is a PA-RISC machine
# This only works for Linux or HP-UX, not other PA-RISC OSs (BSD maybe?). Also
# may falsely detect parisc on HP-UX m68k
cmake_machine_parisc=false
if ${cmake_system_linux}; then
  if uname -m | grep parisc >/dev/null 2>&1; then
    cmake_machine_parisc=true
  fi
elif ${cmake_system_hpux}; then
  if uname -m | grep ia64 >/dev/null 2>&1; then : ; else
    cmake_machine_parisc=true
  fi
fi

# Choose the generator to use for bootstrapping.
if ${cmake_system_mingw}; then
  # Bootstrapping from an MSYS prompt.
  cmake_bootstrap_generator="MSYS Makefiles"
else
  # Bootstrapping from a standard UNIX prompt.
  cmake_bootstrap_generator="Unix Makefiles"
fi

# Choose tools and extensions for this platform.
if ${cmake_system_openvms}; then
  _tmp="_tmp"
  _cmk="_cmk"
  _diff=`which diff`
else
  _tmp=".tmp"
  _cmk=".cmk"
  _diff="diff"
fi

# Construct bootstrap directory name.
cmake_bootstrap_dir="${cmake_binary_dir}/Bootstrap${_cmk}"

# Helper function to fix windows paths.
case "${cmake_system}" in
*MINGW*)
  cmake_fix_slashes()
  {
    cmd //c echo "$(echo "$1" | sed 's/\\/\//g')" | sed 's/^"//;s/" *$//'
  }
  ;;
*)
  cmake_fix_slashes()
  {
    echo "$1" | sed 's/\\/\//g'
  }
  ;;
esac

# Choose the default install prefix.
if ${cmake_system_mingw}; then
  if [ "x${PROGRAMFILES}" != "x" ]; then
    cmake_default_prefix=`cmake_fix_slashes "${PROGRAMFILES}/CMake"`
  elif [ "x${ProgramFiles}" != "x" ]; then
    cmake_default_prefix=`cmake_fix_slashes "${ProgramFiles}/CMake"`
  elif [ "x${SYSTEMDRIVE}" != "x" ]; then
    cmake_default_prefix=`cmake_fix_slashes "${SYSTEMDRIVE}/Program Files/CMake"`
  elif [ "x${SystemDrive}" != "x" ]; then
    cmake_default_prefix=`cmake_fix_slashes "${SystemDrive}/Program Files/CMake"`
  else
    cmake_default_prefix="c:/Program Files/CMake"
  fi
elif ${cmake_system_haiku}; then
  cmake_default_prefix=`finddir B_COMMON_DIRECTORY`
else
  cmake_default_prefix="/usr/local"
fi

# Lookup default install destinations.
cmake_data_dir_default="`cmake_install_dest_default DATA ${cmake_data_dir_keyword}`"
cmake_doc_dir_default="`cmake_install_dest_default DOC ${cmake_doc_dir_keyword}`"
cmake_man_dir_default="`cmake_install_dest_default MAN ${cmake_man_dir_keyword}`"

CMAKE_KNOWN_C_COMPILERS="cc gcc xlc icc tcc"
CMAKE_KNOWN_CXX_COMPILERS="aCC xlC CC g++ c++ icc como "
CMAKE_KNOWN_MAKE_PROCESSORS="gmake make"

CMAKE_PROBLEMATIC_FILES="\
  CMakeCache.txt \
  CMakeSystem.cmake \
  CMakeCCompiler.cmake \
  CMakeCXXCompiler.cmake \
  */CMakeSystem.cmake \
  */CMakeCCompiler.cmake \
  */CMakeCXXCompiler.cmake \
  Source/cmConfigure.h \
  Source/CTest/Curl/config.h \
  Utilities/cmexpat/expatConfig.h \
  Utilities/cmexpat/expatDllConfig.h \
  "

CMAKE_UNUSED_SOURCES="\
  cmGlobalXCodeGenerator \
  cmLocalXCodeGenerator \
  cmXCodeObject \
  cmXCode21Object \
  cmSourceGroup \
"

CMAKE_CXX_SOURCES="\
  cmake  \
  cmakemain \
  cmcmd  \
  cmCommandArgumentLexer \
  cmCommandArgumentParser \
  cmCommandArgumentParserHelper \
  cmCommonTargetGenerator \
  cmCPackPropertiesGenerator \
  cmDefinitions \
  cmDepends \
  cmDependsC \
  cmDocumentationFormatter \
  cmPolicies \
  cmProperty \
  cmPropertyMap \
  cmPropertyDefinition \
  cmPropertyDefinitionMap \
  cmMakeDepend \
  cmMakefile \
  cmExportFileGenerator \
  cmExportInstallFileGenerator \
  cmExportTryCompileFileGenerator \
  cmExportSet \
  cmExportSetMap \
  cmExternalMakefileProjectGenerator \
  cmGeneratorExpressionEvaluationFile \
  cmGeneratedFileStream \
  cmGeneratorTarget \
  cmGeneratorExpressionContext \
  cmGeneratorExpressionDAGChecker \
  cmGeneratorExpressionEvaluator \
  cmGeneratorExpressionLexer \
  cmGeneratorExpressionNode \
  cmGeneratorExpressionParser \
  cmGeneratorExpression \
  cmGlobalCommonGenerator \
  cmGlobalGenerator \
  cmInstallDirectoryGenerator \
  cmLocalCommonGenerator \
  cmLocalGenerator \
  cmInstalledFile \
  cmInstallGenerator \
  cmInstallExportGenerator \
  cmInstallFilesGenerator \
  cmInstallScriptGenerator \
  cmInstallTargetGenerator \
  cmScriptGenerator \
  cmSourceFile \
  cmSourceFileLocation \
  cmState \
  cmSystemTools \
  cmTestGenerator \
  cmVersion \
  cmFileTimeComparison \
  cmGlobalUnixMakefileGenerator3 \
  cmLocalUnixMakefileGenerator3 \
  cmMakefileExecutableTargetGenerator \
  cmMakefileLibraryTargetGenerator \
  cmMakefileTargetGenerator \
  cmMakefileUtilityTargetGenerator \
  cmOutputConverter \
  cmOSXBundleGenerator \
  cmNewLineStyle \
  cmBootstrapCommands1 \
  cmBootstrapCommands2 \
  cmCommandsForBootstrap \
  cmTarget \
  cmTest \
  cmCustomCommand \
  cmCustomCommandGenerator \
  cmCacheManager \
  cmListFileCache \
  cmComputeLinkDepends \
  cmComputeLinkInformation \
  cmOrderDirectories \
  cmComputeTargetDepends \
  cmComputeComponentGraph \
  cmExprLexer \
  cmExprParser \
  cmExprParserHelper \
"

if ${cmake_system_mingw}; then
  CMAKE_CXX_SOURCES="${CMAKE_CXX_SOURCES}\
    cmGlobalMSYSMakefileGenerator \
    cmGlobalMinGWMakefileGenerator"
fi

CMAKE_C_SOURCES="\
  cmListFileLexer \
  "

if ${cmake_system_mingw}; then
  KWSYS_C_SOURCES="\
    EncodingC \
    ProcessWin32 \
    String \
    System \
    Terminal"
else
  KWSYS_C_SOURCES="\
    EncodingC \
    ProcessUNIX \
    String \
    System \
    Terminal"
fi

KWSYS_CXX_SOURCES="\
  Directory \
  EncodingCXX \
  FStream \
  Glob \
  RegularExpression \
  SystemTools"

KWSYS_FILES="\
  auto_ptr.hxx \
  Directory.hxx \
  Encoding.h \
  Encoding.hxx \
  FStream.hxx \
  Glob.hxx \
  Process.h \
  RegularExpression.hxx \
  String.h \
  String.hxx \
  System.h \
  SystemTools.hxx \
  Terminal.h"

KWIML_FILES='
  ABI.h
  INT.h
'

# Display CMake bootstrap usage
cmake_usage()
{
echo '
Usage: '"$0"' [<options>...] [-- <cmake-options>...]
Options: [defaults in brackets after descriptions]
Configuration:
  --help                  print this message
  --version               only print version information
  --verbose               display more information
  --parallel=n            bootstrap cmake in parallel, where n is
                          number of nodes [1]
  --enable-ccache         Enable ccache when building cmake
  --init=FILE             load FILE as script to populate cache
  --system-libs           use all system-installed third-party libraries
                          (for use only by package maintainers)
  --no-system-libs        use all cmake-provided third-party libraries
                          (default)
  --system-curl           use system-installed curl library
  --no-system-curl        use cmake-provided curl library (default)
  --system-expat          use system-installed expat library
  --no-system-expat       use cmake-provided expat library (default)
  --system-jsoncpp        use system-installed jsoncpp library
  --no-system-jsoncpp     use cmake-provided jsoncpp library (default)
  --system-zlib           use system-installed zlib library
  --no-system-zlib        use cmake-provided zlib library (default)
  --system-bzip2          use system-installed bzip2 library
  --no-system-bzip2       use cmake-provided bzip2 library (default)
  --system-libarchive     use system-installed libarchive library
  --no-system-libarchive  use cmake-provided libarchive library (default)

  --qt-gui                build the Qt-based GUI (requires Qt >= 4.2)
  --no-qt-gui             do not build the Qt-based GUI (default)
  --qt-qmake=<qmake>      use <qmake> as the qmake executable to find Qt

  --sphinx-man            build man pages with Sphinx
  --sphinx-html           build html help with Sphinx
  --sphinx-qthelp         build qch help with Sphinx
  --sphinx-build=<sb>     use <sb> as the sphinx-build executable
  --sphinx-flags=<flags>  pass <flags> to sphinx-build executable

Directory and file names:
  --prefix=PREFIX         install files in tree rooted at PREFIX
                          ['"${cmake_default_prefix}"']
  --datadir=DIR           install data files in PREFIX/DIR
                          ['"${cmake_data_dir_default}"']
  --docdir=DIR            install documentation files in PREFIX/DIR
                          ['"${cmake_doc_dir_default}"']
  --mandir=DIR            install man pages files in PREFIX/DIR/manN
                          ['"${cmake_man_dir_default}"']
'
  exit 10
}

# Display CMake bootstrap usage
cmake_version_display()
{
  echo "CMake ${cmake_version}, ${cmake_copyright}"
}

# Display CMake bootstrap error, display the log file and exit
cmake_error()
{
  res=$1
  shift 1
  echo "---------------------------------------------"
  echo "Error when bootstrapping CMake:"
  echo "$*"
  echo "---------------------------------------------"
  if [ -f cmake_bootstrap.log ]; then
    echo "Log of errors: `pwd`/cmake_bootstrap.log"
    #cat cmake_bootstrap.log
    echo "---------------------------------------------"
  fi
  exit ${res}
}

# Replace KWSYS_NAMESPACE with cmsys
cmake_replace_string ()
{
  INFILE="$1"
  OUTFILE="$2"
  SEARCHFOR="$3"
  REPLACEWITH="$4"
  if [ -f "${INFILE}" ] || ${cmake_system_openvms}; then
    cat "${INFILE}" |
      sed "s/\@${SEARCHFOR}\@/${REPLACEWITH}/g" > "${OUTFILE}${_tmp}"
    if [ -f "${OUTFILE}${_tmp}" ]; then
      if "${_diff}" "${OUTFILE}" "${OUTFILE}${_tmp}" > /dev/null 2> /dev/null ; then
        #echo "Files are the same"
        rm -f "${OUTFILE}${_tmp}"
      else
        mv -f "${OUTFILE}${_tmp}" "${OUTFILE}"
      fi
    fi
  else
    cmake_error 1 "Cannot find file ${INFILE}"
  fi
}

cmake_kwsys_config_replace_string ()
{
  INFILE="$1"
  OUTFILE="$2"
  shift 2
  APPEND="$*"
  if [ -f "${INFILE}" ] || ${cmake_system_openvms}; then
    echo "${APPEND}" > "${OUTFILE}${_tmp}"
    cat "${INFILE}" |
      sed "/./ {s/\@KWSYS_NAMESPACE\@/cmsys/g;
                s/@KWSYS_BUILD_SHARED@/${KWSYS_BUILD_SHARED}/g;
                s/@KWSYS_LFS_AVAILABLE@/${KWSYS_LFS_AVAILABLE}/g;
                s/@KWSYS_LFS_REQUESTED@/${KWSYS_LFS_REQUESTED}/g;
                s/@KWSYS_NAME_IS_KWSYS@/${KWSYS_NAME_IS_KWSYS}/g;
                s/@KWSYS_STL_HAS_WSTRING@/${KWSYS_STL_HAS_WSTRING}/g;
                s/@KWSYS_STAT_HAS_ST_MTIM@/${KWSYS_STAT_HAS_ST_MTIM}/g;}" >> "${OUTFILE}${_tmp}"
    if [ -f "${OUTFILE}${_tmp}" ]; then
      if "${_diff}" "${OUTFILE}" "${OUTFILE}${_tmp}" > /dev/null 2> /dev/null ; then
        #echo "Files are the same"
        rm -f "${OUTFILE}${_tmp}"
      else
        mv -f "${OUTFILE}${_tmp}" "${OUTFILE}"
      fi
    fi
  else
    cmake_error 2 "Cannot find file ${INFILE}"
  fi
}
# Write string into a file
cmake_report ()
{
  FILE=$1
  shift
  echo "$*" >> ${FILE}
}

# Escape spaces in strings
cmake_escape ()
{
  echo $1 | sed "s/ /\\\\ /g"
}

# Strip prefix from argument
cmake_arg ()
{
  echo "$1" | sed "s/^${2-[^=]*=}//"
}

# Write message to the log
cmake_log ()
{
  echo "$*" >> cmake_bootstrap.log
}

# Return temp file
cmake_tmp_file ()
{
  echo "cmake_bootstrap_$$_test"
}

# Run a compiler test. First argument is compiler, second one are compiler
# flags, third one is test source file to be compiled
cmake_try_run ()
{
  COMPILER=$1
  FLAGS=$2
  TESTFILE=$3
  if [ ! -f "${TESTFILE}" ]; then
    echo "Test file ${TESTFILE} missing. Please verify your CMake source tree."
    exit 4
  fi
  TMPFILE=`cmake_tmp_file`
  echo "Try: ${COMPILER}"
  echo "Line: ${COMPILER} ${FLAGS} ${TESTFILE} -o ${TMPFILE}"
  echo "----------  file   -----------------------"
  cat "${TESTFILE}"
  echo "------------------------------------------"
  "${COMPILER}" ${FLAGS} "${TESTFILE}" -o "${TMPFILE}"
  RES=$?
  if [ "${RES}" -ne "0" ]; then
    echo "Test failed to compile"
    return 1
  fi
  if [ ! -f "${TMPFILE}" ] && [ ! -f "${TMPFILE}.exe" ]; then
    echo "Test failed to produce executable"
    return 2
  fi
  ./${TMPFILE}
  RES=$?
  rm -f "${TMPFILE}"
  if [ "${RES}" -ne "0" ]; then
    echo "Test produced non-zero return code"
    return 3
  fi
  echo "Test succeded"
  return 0
}

# Run a make test. First argument is the make interpreter.
cmake_try_make ()
{
  MAKE_PROC="$1"
  MAKE_FLAGS="$2"
  echo "Try: ${MAKE_PROC}"
  "${MAKE_PROC}" ${MAKE_FLAGS}
  RES=$?
  if [ "${RES}" -ne "0" ]; then
    echo "${MAKE_PROC} does not work"
    return 1
  fi
  if [ ! -f "test" ] && [ ! -f "test.exe" ]; then
    echo "${COMPILER} does not produce output"
    return 2
  fi
  ./test
  RES=$?
  rm -f "test"
  if [ "${RES}" -ne "0" ]; then
    echo "${MAKE_PROC} produces strange executable"
    return 3
  fi
  echo "${MAKE_PROC} works"
  return 0
}

# Parse arguments
cmake_verbose=
cmake_parallel_make=
cmake_ccache_enabled=
cmake_prefix_dir="${cmake_default_prefix}"
while test $# != 0; do
  case "$1" in
  --prefix=*) dir=`cmake_arg "$1"`
              cmake_prefix_dir=`cmake_fix_slashes "$dir"` ;;
  --parallel=*) cmake_parallel_make=`cmake_arg "$1"` ;;
  --datadir=*) cmake_data_dir=`cmake_arg "$1"` ;;
  --docdir=*) cmake_doc_dir=`cmake_arg "$1"` ;;
  --mandir=*) cmake_man_dir=`cmake_arg "$1"` ;;
  --init=*) cmake_init_file=`cmake_arg "$1"` ;;
  --system-libs) cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARIES=1" ;;
  --no-system-libs) cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARIES=0" ;;
  --system-bzip2|--system-curl|--system-expat|--system-jsoncpp|--system-libarchive|--system-zlib)
    lib=`cmake_arg "$1" "--system-"`
    cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARY_`cmake_toupper $lib`=1" ;;
  --no-system-bzip2|--no-system-curl|--no-system-expat|--no-system-jsoncpp|--no-system-libarchive|--no-system-zlib)
    lib=`cmake_arg "$1" "--no-system-"`
    cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARY_`cmake_toupper $lib`=0" ;;
  --qt-gui) cmake_bootstrap_qt_gui="1" ;;
  --no-qt-gui) cmake_bootstrap_qt_gui="0" ;;
  --qt-qmake=*) cmake_bootstrap_qt_qmake=`cmake_arg "$1"` ;;
  --sphinx-man) cmake_sphinx_man="1" ;;
  --sphinx-html) cmake_sphinx_html="1" ;;
  --sphinx-qthelp) cmake_sphinx_qthelp="1" ;;
  --sphinx-build=*) cmake_sphinx_build=`cmake_arg "$1"` ;;
  --sphinx-flags=*) cmake_sphinx_flags=`cmake_arg "$1"` ;;
  --help) cmake_usage ;;
  --version) cmake_version_display ; exit 2 ;;
  --verbose) cmake_verbose=TRUE ;;
  --enable-ccache) cmake_ccache_enabled=TRUE ;;
  --) shift; break ;;
  *) die "Unknown option: $1" ;;
  esac
  shift
done

# If verbose, display some information about bootstrap
if [ -n "${cmake_verbose}" ]; then
  echo "---------------------------------------------"
  echo "Source directory: ${cmake_source_dir}"
  echo "Binary directory: ${cmake_binary_dir}"
  echo "Prefix directory: ${cmake_prefix_dir}"
  echo "System:           ${cmake_system}"
  if [ "x${cmake_parallel_make}" != "x" ]; then
    echo "Doing parallel make: ${cmake_parallel_make}"
  fi
  echo ""
fi

echo "---------------------------------------------"
# Get CMake version
echo "`cmake_version_display`"

# Check for in-source build
cmake_in_source_build=
if [ -f "${cmake_binary_dir}/Source/cmake.cxx" -a \
     -f "${cmake_binary_dir}/Source/cmake.h" ]; then
  if [ -n "${cmake_verbose}" ]; then
    echo "Warning: This is an in-source build"
  fi
  cmake_in_source_build=TRUE
fi

# If this is not an in-source build, then Bootstrap stuff should not exist.
if [ -z "${cmake_in_source_build}" ]; then
  # Did somebody bootstrap in the source tree?
  if [ -d "${cmake_source_dir}/Bootstrap${_cmk}" ]; then
    cmake_error 10 "Found directory \"${cmake_source_dir}/Bootstrap${_cmk}\".
Looks like somebody did bootstrap CMake in the source tree, but now you are
trying to do bootstrap in the binary tree. Please remove Bootstrap${_cmk}
directory from the source tree."
  fi
  # Is there a cache in the source tree?
  for cmake_problematic_file in ${CMAKE_PROBLEMATIC_FILES}; do
    if [ -f "${cmake_source_dir}/${cmake_problematic_file}" ]; then
      cmake_error 10 "Found \"${cmake_source_dir}/${cmake_problematic_file}\".
Looks like somebody tried to build CMake in the source tree, but now you are
trying to do bootstrap in the binary tree. Please remove \"${cmake_problematic_file}\"
from the source tree."
    fi
  done
fi

# Make bootstrap directory
[ -d "${cmake_bootstrap_dir}" ] || mkdir "${cmake_bootstrap_dir}"
if [ ! -d "${cmake_bootstrap_dir}" ]; then
  cmake_error 3 "Cannot create directory ${cmake_bootstrap_dir} to bootstrap CMake."
fi
cd "${cmake_bootstrap_dir}"

[ -d "cmsys" ] || mkdir "cmsys"
if [ ! -d "cmsys" ]; then
  cmake_error 4 "Cannot create directory ${cmake_bootstrap_dir}/cmsys"
fi

for a in stl ios; do
  [ -d "cmsys/${a}" ] || mkdir "cmsys/${a}"
  if [ ! -d "cmsys/${a}" ]; then
    cmake_error 5 "Cannot create directory ${cmake_bootstrap_dir}/cmsys/${a}"
  fi
done

[ -d "cmIML" ] || mkdir "cmIML"
if [ ! -d "cmIML" ]; then
  cmake_error 12 "Cannot create directory ${cmake_bootstrap_dir}/cmIML"
fi

# Delete all the bootstrap files
rm -f "${cmake_bootstrap_dir}/cmake_bootstrap.log"
rm -f "${cmake_bootstrap_dir}/cmConfigure.h${_tmp}"
rm -f "${cmake_bootstrap_dir}/cmVersionConfig.h${_tmp}"

# If exist compiler flags, set them
cmake_c_flags=${CFLAGS}
cmake_cxx_flags=${CXXFLAGS}
cmake_ld_flags=${LDFLAGS}

# Add Cygwin-specific flags
if ${cmake_system_cygwin}; then
  cmake_ld_flags="${LDFLAGS} -Wl,--enable-auto-import"
fi

# Add CoreFoundation framework on Darwin
if ${cmake_system_darwin}; then
  cmake_ld_flags="${LDFLAGS} -framework CoreFoundation"
fi

# Add BeOS toolkits...
if ${cmake_system_beos}; then
  cmake_ld_flags="${LDFLAGS} -lroot -lbe"
fi

# Add Haiku toolkits...
if ${cmake_system_haiku}; then
  cmake_ld_flags="${LDFLAGS} -lroot -lbe"
fi

# Workaround for short jump tables on PA-RISC
if ${cmake_machine_parisc}; then
  if ${cmake_c_compiler_is_gnu}; then
    cmake_c_flags="${CFLAGS} -mlong-calls"
  fi
  if ${cmake_cxx_compiler_is_gnu}; then
    cmake_cxx_flags="${CXXFLAGS} -mlong-calls"
  fi
fi

#-----------------------------------------------------------------------------
# Detect known toolchains on some platforms.
cmake_toolchains=''
case "${cmake_system}" in
  *AIX*)   cmake_toolchains='XL GNU' ;;
  *CYGWIN*) cmake_toolchains='GNU' ;;
  *Darwin*) cmake_toolchains='GNU Clang' ;;
  *Linux*) cmake_toolchains='GNU Clang XL PGI PathScale' ;;
  *MINGW*) cmake_toolchains='GNU' ;;
esac

# Toolchain compiler name table.
cmake_toolchain_Clang_CC='clang'
cmake_toolchain_Clang_CXX='clang++'
cmake_toolchain_GNU_CC='gcc'
cmake_toolchain_GNU_CXX='g++'
cmake_toolchain_PGI_CC='pgcc'
cmake_toolchain_PGI_CXX='pgCC'
cmake_toolchain_PathScale_CC='pathcc'
cmake_toolchain_PathScale_CXX='pathCC'
cmake_toolchain_XL_CC='xlc'
cmake_toolchain_XL_CXX='xlC'

cmake_toolchain_try()
{
  tc="$1"
  TMPFILE=`cmake_tmp_file`

  eval "tc_CC=\${cmake_toolchain_${tc}_CC}"
  echo 'int main() { return 0; }' > "${TMPFILE}.c"
  cmake_try_run "$tc_CC" "" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1
  tc_result_CC="$?"
  rm -f "${TMPFILE}.c"
  test "${tc_result_CC}" = "0" || return 1

  eval "tc_CXX=\${cmake_toolchain_${tc}_CXX}"
  echo 'int main() { return 0; }' > "${TMPFILE}.cpp"
  cmake_try_run "$tc_CXX" "" "${TMPFILE}.cpp" >> cmake_bootstrap.log 2>&1
  tc_result_CXX="$?"
  rm -f "${TMPFILE}.cpp"
  test "${tc_result_CXX}" = "0" || return 1

  cmake_toolchain="$tc"
}

cmake_toolchain_detect()
{
  cmake_toolchain=
  for tc in ${cmake_toolchains}; do
    echo "Checking for $tc toolchain" >> cmake_bootstrap.log 2>&1
    cmake_toolchain_try "$tc" &&
    echo "Found $tc toolchain" &&
    break
  done
}

if [ -z "${CC}" -a -z "${CXX}" ]; then
  cmake_toolchain_detect
fi

#-----------------------------------------------------------------------------
# Test C compiler
cmake_c_compiler=

# If CC is set, use that for compiler, otherwise use list of known compilers
if [ -n "${cmake_toolchain}" ]; then
  eval cmake_c_compilers="\${cmake_toolchain_${cmake_toolchain}_CC}"
elif [ -n "${CC}" ]; then
  cmake_c_compilers="${CC}"
else
  cmake_c_compilers="${CMAKE_KNOWN_C_COMPILERS}"
fi

# Check if C compiler works
TMPFILE=`cmake_tmp_file`
echo '
#ifdef __cplusplus
# error "The CMAKE_C_COMPILER is set to a C++ compiler"
#endif

#include<stdio.h>

#if defined(__CLASSIC_C__)
int main(argc, argv)
  int argc;
  char* argv[];
#else
int main(int argc, char* argv[])
#endif
{
  printf("%d%c", (argv != 0), (char)0x0a);
  return argc-1;
}
' > "${TMPFILE}.c"
for a in ${cmake_c_compilers}; do
  if [ -z "${cmake_c_compiler}" ] && \
    cmake_try_run "${a}" "${cmake_c_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
    cmake_c_compiler="${a}"
  fi
done
rm -f "${TMPFILE}.c"

if [ -z "${cmake_c_compiler}" ]; then
  cmake_error 6 "Cannot find appropriate C compiler on this system.
Please specify one using environment variable CC.
See cmake_bootstrap.log for compilers attempted.
"
fi
echo "C compiler on this system is: ${cmake_c_compiler} ${cmake_c_flags}"

#-----------------------------------------------------------------------------
# Test CXX compiler
cmake_cxx_compiler=

# On Mac OSX, CC is the same as cc, so make sure not to try CC as c++ compiler.

# If CC is set, use that for compiler, otherwise use list of known compilers
if [ -n "${cmake_toolchain}" ]; then
  eval cmake_cxx_compilers="\${cmake_toolchain_${cmake_toolchain}_CXX}"
elif [ -n "${CXX}" ]; then
  cmake_cxx_compilers="${CXX}"
else
  cmake_cxx_compilers="${CMAKE_KNOWN_CXX_COMPILERS}"
fi

# Check if C++ compiler works
TMPFILE=`cmake_tmp_file`
echo '
#if defined(TEST1)
# include <iostream>
#else
# include <iostream.h>
#endif

class NeedCXX
{
public:
  NeedCXX() { this->Foo = 1; }
  int GetFoo() { return this->Foo; }
private:
  int Foo;
};
int main()
{
  NeedCXX c;
#ifdef TEST3
  cout << c.GetFoo() << endl;
#else
  std::cout << c.GetFoo() << std::endl;
#endif
  return 0;
}
' > "${TMPFILE}.cxx"
for a in ${cmake_cxx_compilers}; do
  for b in 1 2 3; do
    if [ -z "${cmake_cxx_compiler}" ] && \
      cmake_try_run "${a}" "${cmake_cxx_flags} -DTEST${b}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
      cmake_cxx_compiler="${a}"
    fi
  done
done
rm -f "${TMPFILE}.cxx"

if [ -z "${cmake_cxx_compiler}" ]; then
  cmake_error 7 "Cannot find appropriate C++ compiler on this system.
Please specify one using environment variable CXX.
See cmake_bootstrap.log for compilers attempted."
fi
echo "C++ compiler on this system is: ${cmake_cxx_compiler} ${cmake_cxx_flags}"

#-----------------------------------------------------------------------------
# Test Make

cmake_make_processor=
cmake_make_flags=

# If MAKE is set, use that for make processor, otherwise use list of known make
if [ -n "${MAKE}" ]; then
  cmake_make_processors="${MAKE}"
else
  cmake_make_processors="${CMAKE_KNOWN_MAKE_PROCESSORS}"
fi

TMPFILE="`cmake_tmp_file`_dir"
rm -rf "${cmake_bootstrap_dir}/${TMPFILE}"
mkdir "${cmake_bootstrap_dir}/${TMPFILE}"
cd "${cmake_bootstrap_dir}/${TMPFILE}"
echo '
test: test.c
	"'"${cmake_c_compiler}"'" '"${cmake_ld_flags} ${cmake_c_flags}"' -o test test.c
'>"Makefile"
echo '
#include <stdio.h>
int main(){ printf("1%c", (char)0x0a); return 0; }
' > "test.c"
cmake_original_make_flags="${cmake_make_flags}"
if [ "x${cmake_parallel_make}" != "x" ]; then
  cmake_make_flags="${cmake_make_flags} -j ${cmake_parallel_make}"
fi
for a in ${cmake_make_processors}; do
  if [ -z "${cmake_make_processor}" ] && cmake_try_make "${a}" "${cmake_make_flags}" >> ../cmake_bootstrap.log 2>&1; then
    cmake_make_processor="${a}"
  fi
done
cmake_full_make_flags="${cmake_make_flags}"
if [ "x${cmake_original_make_flags}" != "x${cmake_make_flags}" ]; then
  if [ -z "${cmake_make_processor}" ]; then
    cmake_make_flags="${cmake_original_make_flags}"
    for a in ${cmake_make_processors}; do
      if [ -z "${cmake_make_processor}" ] && cmake_try_make "${a}" "${cmake_make_flags}" >> ../cmake_bootstrap.log 2>&1; then
        cmake_make_processor="${a}"
      fi
    done
  fi
fi
cd "${cmake_bootstrap_dir}"

if [ -z "${cmake_make_processor}" ]; then
  cmake_error 8 "Cannot find appropriate Makefile processor on this system.
Please specify one using environment variable MAKE."
fi
rm -rf "${cmake_bootstrap_dir}/${TMPFILE}"
echo "Makefile processor on this system is: ${cmake_make_processor}"
if [ "x${cmake_full_make_flags}" != "x${cmake_make_flags}" ]; then
  echo "---------------------------------------------"
  echo "Makefile processor ${cmake_make_processor} does not support parallel build"
  echo "---------------------------------------------"
fi

# Ok, we have CC, CXX, and MAKE.

# Test C++ compiler features

# Are we GCC?

TMPFILE=`cmake_tmp_file`
echo '
#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
#include <iostream>
int main() { std::cout << "This is GNU" << std::endl; return 0;}
#endif
' > ${TMPFILE}.cxx
cmake_cxx_compiler_is_gnu=0
if cmake_try_run "${cmake_cxx_compiler}" \
  "${cmake_cxx_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
  cmake_cxx_compiler_is_gnu=1
fi
if [ "x${cmake_cxx_compiler_is_gnu}" = "x1" ]; then
  echo "${cmake_cxx_compiler} is GNU compiler"
else
  echo "${cmake_cxx_compiler} is not GNU compiler"
fi
rm -f "${TMPFILE}.cxx"

if [ "x${cmake_cxx_compiler_is_gnu}" != "x1" ]; then
  # Check for non-GNU compiler flags

  # If we are on IRIX, check for -LANG:std
  cmake_test_flags="-LANG:std"
  if [ "x${cmake_system}" = "xIRIX64" ]; then
    TMPFILE=`cmake_tmp_file`
    echo '
    #include <iostream>
    int main() { std::cout << "No need for '"${cmake_test_flags}"'" << std::endl; return 0;}
' > ${TMPFILE}.cxx
    cmake_need_lang_std=0
    if cmake_try_run "${cmake_cxx_compiler}" \
      "${cmake_cxx_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
      :
    else
      if cmake_try_run "${cmake_cxx_compiler}" \
        "${cmake_cxx_flags} ${cmake_test_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
        cmake_need_lang_std=1
      fi
    fi
    if [ "x${cmake_need_lang_std}" = "x1" ]; then
      cmake_cxx_flags="${cmake_cxx_flags} ${cmake_test_flags}"
      echo "${cmake_cxx_compiler} needs ${cmake_test_flags}"
    else
      echo "${cmake_cxx_compiler} does not need ${cmake_test_flags}"
    fi
    rm -f "${TMPFILE}.cxx"
  fi
  cmake_test_flags=

  # If we are on OSF, check for -timplicit_local -no_implicit_include
  cmake_test_flags="-timplicit_local -no_implicit_include"
  if [ "x${cmake_system}" = "xOSF1" ]; then
    TMPFILE=`cmake_tmp_file`
    echo '
    #include <iostream>
    int main() { std::cout << "We need '"${cmake_test_flags}"'" << std::endl; return 0;}
' > ${TMPFILE}.cxx
    cmake_need_flags=1
    if cmake_try_run "${cmake_cxx_compiler}" \
      "${cmake_cxx_flags} ${cmake_test_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
      :
    else
      cmake_need_flags=0
    fi
    if [ "x${cmake_need_flags}" = "x1" ]; then
      cmake_cxx_flags="${cmake_cxx_flags} ${cmake_test_flags}"
      echo "${cmake_cxx_compiler} needs ${cmake_test_flags}"
    else
      echo "${cmake_cxx_compiler} does not need ${cmake_test_flags}"
    fi
    rm -f "${TMPFILE}.cxx"
  fi
  cmake_test_flags=

  # If we are on OSF, check for -std strict_ansi -nopure_cname
  cmake_test_flags="-std strict_ansi -nopure_cname"
  if [ "x${cmake_system}" = "xOSF1" ]; then
    TMPFILE=`cmake_tmp_file`
    echo '
    #include <iostream>
    int main() { std::cout << "We need '"${cmake_test_flags}"'" << std::endl; return 0;}
' > ${TMPFILE}.cxx
    cmake_need_flags=1
    if cmake_try_run "${cmake_cxx_compiler}" \
      "${cmake_cxx_flags} ${cmake_test_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
      :
    else
      cmake_need_flags=0
    fi
    if [ "x${cmake_need_flags}" = "x1" ]; then
      cmake_cxx_flags="${cmake_cxx_flags} ${cmake_test_flags}"
      echo "${cmake_cxx_compiler} needs ${cmake_test_flags}"
    else
      echo "${cmake_cxx_compiler} does not need ${cmake_test_flags}"
    fi
    rm -f "${TMPFILE}.cxx"
  fi
  cmake_test_flags=

  # If we are on HP-UX, check for -Ae for the C compiler.
  if [ "x${cmake_system}" = "xHP-UX" ]; then
    cmake_test_flags="-Ae"
    TMPFILE=`cmake_tmp_file`
    echo '
    int main(int argc, char** argv) { (void)argc; (void)argv; return 0; }
' > ${TMPFILE}.c
    cmake_need_Ae=0
    if cmake_try_run "${cmake_c_compiler}" "${cmake_c_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
      :
    else
      if cmake_try_run "${cmake_c_compiler}" \
        "${cmake_c_flags} ${cmake_test_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
        cmake_need_Ae=1
      fi
    fi
    if [ "x${cmake_need_Ae}" = "x1" ]; then
      cmake_c_flags="${cmake_c_flags} ${cmake_test_flags}"
      echo "${cmake_c_compiler} needs ${cmake_test_flags}"
    else
      echo "${cmake_c_compiler} does not need ${cmake_test_flags}"
    fi
    rm -f "${TMPFILE}.c"
    echo '
    #include <iostream>
    int main(int argc, char** argv) {
    for(int i=0; i < 1; ++i);
    for(int i=0; i < 1; ++i);
    (void)argc; (void)argv; return 0; }
' > ${TMPFILE}.cxx
    cmake_need_AAstd98=0
    cmake_test_flags="-AA +hpxstd98"
    if cmake_try_run "${cmake_cxx_compiler}" "${cmake_cxx_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
      :
    else
      if cmake_try_run "${cmake_cxx_compiler}" \
        "${cmake_cxx_flags} ${cmake_test_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
        cmake_need_AAstd98=1
      fi
    fi
    if [ "x${cmake_need_AAstd98}" = "x1" ]; then
      cmake_cxx_flags="${cmake_cxx_flags} ${cmake_test_flags}"
      echo "${cmake_cxx_compiler} needs ${cmake_test_flags}"
    else
      echo "${cmake_cxx_compiler} does not need ${cmake_test_flags}"
    fi
  fi
  cmake_test_flags=
fi


if [ "x${cmake_cxx_compiler_is_gnu}" != "x1" ]; then
  # Are we SolarisStudio?

  TMPFILE=`cmake_tmp_file`
  echo '
  #if defined(__SUNPRO_CC)
  #include <iostream>
  int main() { std::cout << "This is SolarisStudio" << std::endl; return 0;}
  #endif
  ' > ${TMPFILE}.cxx
  cmake_cxx_compiler_is_solarisstudio=0
  if cmake_try_run "${cmake_cxx_compiler}" \
    "${cmake_cxx_flags} " "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
    cmake_cxx_compiler_is_solarisstudio=1
  fi
  if [ "x${cmake_cxx_compiler_is_solarisstudio}" = "x1" ]; then
    echo "${cmake_cxx_compiler} is SolarisStudio compiler"
  else
    echo "${cmake_cxx_compiler} is not SolarisStudio compiler"
  fi
  rm -f "${TMPFILE}.cxx"

  if [ "x${cmake_cxx_compiler_is_solarisstudio}" = "x1" ]; then
    cmake_cxx_flags="${cmake_cxx_flags} -library=stlport4"
  fi
fi


# Test for kwsys features
KWSYS_NAME_IS_KWSYS=0
KWSYS_BUILD_SHARED=0
KWSYS_LFS_AVAILABLE=0
KWSYS_LFS_REQUESTED=0
KWSYS_STAT_HAS_ST_MTIM=0
KWSYS_STL_HAS_WSTRING=0
KWSYS_CXX_HAS_SETENV=0
KWSYS_CXX_HAS_UNSETENV=0
KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H=0
KWSYS_CXX_HAS_UTIMENSAT=0
KWSYS_CXX_HAS_UTIMES=0

if cmake_try_run "${cmake_cxx_compiler}" \
  "${cmake_cxx_flags} -DTEST_KWSYS_CXX_HAS_SETENV" \
  "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
  KWSYS_CXX_HAS_SETENV=1
  echo "${cmake_cxx_compiler} has setenv"
else
  echo "${cmake_cxx_compiler} does not have setenv"
fi

if cmake_try_run "${cmake_cxx_compiler}" \
  "${cmake_cxx_flags} -DTEST_KWSYS_CXX_HAS_UNSETENV" \
  "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
  KWSYS_CXX_HAS_UNSETENV=1
  echo "${cmake_cxx_compiler} has unsetenv"
else
  echo "${cmake_cxx_compiler} does not have unsetenv"
fi

if cmake_try_run "${cmake_cxx_compiler}" \
  "${cmake_cxx_flags} -DTEST_KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H" \
  "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
  KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H=1
  echo "${cmake_cxx_compiler} has environ in stdlib.h"
else
  echo "${cmake_cxx_compiler} does not have environ in stdlib.h"
fi

if cmake_try_run "${cmake_cxx_compiler}" \
  "${cmake_cxx_flags} -DTEST_KWSYS_STL_HAS_WSTRING" \
  "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
  KWSYS_STL_HAS_WSTRING=1
  echo "${cmake_cxx_compiler} has stl wstring"
else
  echo "${cmake_cxx_compiler} does not have stl wstring"
fi

if cmake_try_run "${cmake_cxx_compiler}" \
  "${cmake_cxx_flags} -DTEST_KWSYS_STAT_HAS_ST_MTIM" \
  "${cmake_source_dir}/Source/kwsys/kwsysPlatformTestsCXX.cxx" >> cmake_bootstrap.log 2>&1; then
  KWSYS_STAT_HAS_ST_MTIM=1
  echo "${cmake_cxx_compiler} has struct stat with st_mtim member"
else
  echo "${cmake_cxx_compiler} does not have struct stat with st_mtim member"
fi

# Just to be safe, let us store compiler and flags to the header file

cmake_bootstrap_version='$Revision$'
cmake_compiler_settings_comment="/*
 * Generated by ${cmake_source_dir}/bootstrap
 * Version:     ${cmake_bootstrap_version}
 *
 * Source directory: ${cmake_source_dir}
 * Binary directory: ${cmake_bootstrap_dir}
 *
 * C compiler:   ${cmake_c_compiler}
 * C flags:      ${cmake_c_flags}
 *
 * C++ compiler: ${cmake_cxx_compiler}
 * C++ flags:    ${cmake_cxx_flags}
 *
 * Make:         ${cmake_make_processor}
 *
 * Sources:
 * ${CMAKE_CXX_SOURCES} ${CMAKE_C_SOURCES}
 * kwSys Sources:
 * ${KWSYS_CXX_SOURCES} ${KWSYS_C_SOURCES}
 */
"

cmake_report cmConfigure.h${_tmp} "${cmake_compiler_settings_comment}"

# When bootstrapping on MinGW with MSYS we must convert the source
# directory to a windows path.
if ${cmake_system_mingw}; then
    CMAKE_BOOTSTRAP_SOURCE_DIR=`cd "${cmake_source_dir}"; pwd -W`
    CMAKE_BOOTSTRAP_BINARY_DIR=`cd "${cmake_binary_dir}"; pwd -W`
else
    CMAKE_BOOTSTRAP_SOURCE_DIR="${cmake_source_dir}"
    CMAKE_BOOTSTRAP_BINARY_DIR="${cmake_binary_dir}"
fi

# Write CMake version
cmake_report cmVersionConfig.h${_tmp} "#define CMake_VERSION_MAJOR ${cmake_version_major}"
cmake_report cmVersionConfig.h${_tmp} "#define CMake_VERSION_MINOR ${cmake_version_minor}"
cmake_report cmVersionConfig.h${_tmp} "#define CMake_VERSION_PATCH ${cmake_version_patch}"
cmake_report cmVersionConfig.h${_tmp} "#define CMake_VERSION \"${cmake_version}\""
cmake_report cmConfigure.h${_tmp} "#define CMAKE_BOOTSTRAP_SOURCE_DIR \"${CMAKE_BOOTSTRAP_SOURCE_DIR}\""
cmake_report cmConfigure.h${_tmp} "#define CMAKE_BOOTSTRAP_BINARY_DIR \"${CMAKE_BOOTSTRAP_BINARY_DIR}\""
cmake_report cmConfigure.h${_tmp} "#define CMAKE_DATA_DIR \"/bootstrap-not-insalled\""
cmake_report cmConfigure.h${_tmp} "#define CMAKE_BOOTSTRAP"

# Regenerate configured headers
for h in Configure VersionConfig; do
  if "${_diff}" cm${h}.h cm${h}.h${_tmp} > /dev/null 2> /dev/null; then
    rm -f cm${h}.h${_tmp}
  else
    mv -f cm${h}.h${_tmp} cm${h}.h
  fi
done

# Prepare KWSYS
cmake_kwsys_config_replace_string \
  "${cmake_source_dir}/Source/kwsys/Configure.hxx.in" \
  "${cmake_bootstrap_dir}/cmsys/Configure.hxx" \
  "${cmake_compiler_settings_comment}"
cmake_kwsys_config_replace_string \
  "${cmake_source_dir}/Source/kwsys/Configure.h.in" \
  "${cmake_bootstrap_dir}/cmsys/Configure.h" \
  "${cmake_compiler_settings_comment}"

for a in ${KWSYS_FILES}; do
  cmake_replace_string "${cmake_source_dir}/Source/kwsys/${a}.in" \
     "${cmake_bootstrap_dir}/cmsys/${a}" KWSYS_NAMESPACE cmsys
done

for a in ${KWIML_FILES}; do
  cmake_replace_string "${cmake_source_dir}/Utilities/KWIML/${a}.in" \
     "${cmake_bootstrap_dir}/cmIML/${a}" KWIML cmIML
done

# Generate Makefile
dep="cmConfigure.h cmsys/*.hxx cmsys/*.h `cmake_escape \"${cmake_source_dir}\"`/Source/*.h"
objs=""
for a in ${CMAKE_CXX_SOURCES} ${CMAKE_C_SOURCES} ${KWSYS_CXX_SOURCES} ${KWSYS_C_SOURCES}; do
  objs="${objs} ${a}.o"
done

# Generate dependencies for cmBootstrapCommands1.cxx
for file in `grep "#include.*cm[^.]*.cxx" "${cmake_source_dir}/Source/cmBootstrapCommands1.cxx" | sed "s/.* \"\(.*\)\"/\1/"`; do
  cmBootstrapCommands1Deps="${cmBootstrapCommands1Deps} `cmake_escape "${cmake_source_dir}/Source/$file"`"
done
cmBootstrapCommands1Deps=`echo $cmBootstrapCommands1Deps`
for file in `grep "#include.*cm[^.]*.cxx" "${cmake_source_dir}/Source/cmBootstrapCommands2.cxx" | sed "s/.* \"\(.*\)\"/\1/"`; do
  cmBootstrapCommands2Deps="${cmBootstrapCommands2Deps} `cmake_escape "${cmake_source_dir}/Source/$file"`"
done
cmBootstrapCommands2Deps=`echo $cmBootstrapCommands2Deps`

if [ "x${cmake_ansi_cxx_flags}" != "x" ]; then
  cmake_cxx_flags="${cmake_ansi_cxx_flags} ${cmake_cxx_flags}"
fi

if [ "x${cmake_c_flags}" != "x" ]; then
  cmake_c_flags="${cmake_c_flags} "
fi

if [ "x${cmake_cxx_flags}" != "x" ]; then
  cmake_cxx_flags="${cmake_cxx_flags} "
fi

cmake_c_flags_String="-DKWSYS_STRING_C"
if ${cmake_system_mingw}; then
  cmake_c_flags_EncodingC="-DKWSYS_ENCODING_DEFAULT_CODEPAGE=CP_ACP"
fi
cmake_cxx_flags_SystemTools="
  -DKWSYS_CXX_HAS_SETENV=${KWSYS_CXX_HAS_SETENV}
  -DKWSYS_CXX_HAS_UNSETENV=${KWSYS_CXX_HAS_UNSETENV}
  -DKWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H=${KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H}
  -DKWSYS_CXX_HAS_UTIMENSAT=${KWSYS_CXX_HAS_UTIMENSAT}
  -DKWSYS_CXX_HAS_UTIMES=${KWSYS_CXX_HAS_UTIMES}
"
cmake_c_flags="${cmake_c_flags}-I`cmake_escape \"${cmake_bootstrap_dir}\"` -I`cmake_escape \"${cmake_source_dir}/Source\"` \
  -I`cmake_escape \"${cmake_bootstrap_dir}\"`"
cmake_cxx_flags="${cmake_cxx_flags} -I`cmake_escape \"${cmake_bootstrap_dir}\"` -I`cmake_escape \"${cmake_source_dir}/Source\"` \
  -I`cmake_escape \"${cmake_bootstrap_dir}\"`"
echo "cmake: ${objs}" > "${cmake_bootstrap_dir}/Makefile"
echo "	${cmake_cxx_compiler} ${cmake_ld_flags} ${cmake_cxx_flags} ${objs} -o cmake" >> "${cmake_bootstrap_dir}/Makefile"
for a in ${CMAKE_CXX_SOURCES}; do
  src=`cmake_escape "${cmake_source_dir}/Source/${a}.cxx"`
  echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
  echo "	${cmake_cxx_compiler} ${cmake_cxx_flags} -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
done
echo "cmBootstrapCommands1.o : $cmBootstrapCommands1Deps" >> "${cmake_bootstrap_dir}/Makefile"
echo "cmBootstrapCommands2.o : $cmBootstrapCommands2Deps" >> "${cmake_bootstrap_dir}/Makefile"
for a in ${CMAKE_C_SOURCES}; do
  src=`cmake_escape "${cmake_source_dir}/Source/${a}.c"`
  echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
  echo "	${cmake_c_compiler} ${cmake_c_flags} -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
done
for a in ${KWSYS_C_SOURCES}; do
  src=`cmake_escape "${cmake_source_dir}/Source/kwsys/${a}.c"`
  src_flags=`eval echo \\${cmake_c_flags_\${a}}`
  echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
  echo "	${cmake_c_compiler} ${cmake_c_flags} -DKWSYS_NAMESPACE=cmsys ${src_flags} -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
done
for a in ${KWSYS_CXX_SOURCES}; do
  src=`cmake_escape "${cmake_source_dir}/Source/kwsys/${a}.cxx"`
  src_flags=`eval echo \\${cmake_cxx_flags_\${a}}`
  echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
  echo "	${cmake_cxx_compiler} ${cmake_cxx_flags} -DKWSYS_NAMESPACE=cmsys ${src_flags} -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
done
echo '
rebuild_cache:
	cd "${cmake_binary_dir}" && "${cmake_source_dir}/bootstrap"
' >> "${cmake_bootstrap_dir}/Makefile"

# Write our default settings to Bootstrap${_cmk}/InitialCacheFlags.cmake.
echo '
# Generated by '"${cmake_source_dir}"'/bootstrap
# Default cmake settings.  These may be overridden any settings below.
set (CMAKE_INSTALL_PREFIX "'"${cmake_prefix_dir}"'" CACHE PATH "Install path prefix, prepended onto install directories." FORCE)
set (CMAKE_DOC_DIR "'"${cmake_doc_dir}"'" CACHE PATH "Install location for documentation (relative to prefix)." FORCE)
set (CMAKE_MAN_DIR "'"${cmake_man_dir}"'" CACHE PATH "Install location for man pages (relative to prefix)." FORCE)
set (CMAKE_DATA_DIR "'"${cmake_data_dir}"'" CACHE PATH "Install location for data (relative to prefix)." FORCE)
' > "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"

# Add configuration settings given as command-line options.
if [ "x${cmake_bootstrap_qt_gui}" != "x" ]; then
  echo '
set (BUILD_QtDialog '"${cmake_bootstrap_qt_gui}"' CACHE BOOL "Build Qt dialog for CMake" FORCE)
' >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
fi
if [ "x${cmake_bootstrap_qt_qmake}" != "x" ]; then
  echo '
set (QT_QMAKE_EXECUTABLE "'"${cmake_bootstrap_qt_qmake}"'" CACHE FILEPATH "Location of Qt qmake" FORCE)
' >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
fi
if [ "x${cmake_sphinx_man}" != "x" ]; then
  echo '
set (SPHINX_MAN "'"${cmake_sphinx_man}"'" CACHE BOOL "Build man pages with Sphinx" FORCE)
' >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
fi
if [ "x${cmake_sphinx_html}" != "x" ]; then
  echo '
set (SPHINX_HTML "'"${cmake_sphinx_html}"'" CACHE BOOL "Build html help with Sphinx" FORCE)
' >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
fi
if [ "x${cmake_sphinx_qthelp}" != "x" ]; then
  echo '
set (SPHINX_QTHELP "'"${cmake_sphinx_qthelp}"'" CACHE BOOL "Build qch help with Sphinx" FORCE)
' >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
fi
if [ "x${cmake_sphinx_build}" != "x" ]; then
  echo '
set (SPHINX_EXECUTABLE "'"${cmake_sphinx_build}"'" CACHE FILEPATH "Location of Qt sphinx-build" FORCE)
' >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
fi
if [ "x${cmake_sphinx_flags}" != "x" ]; then
  echo '
set (SPHINX_FLAGS [==['"${cmake_sphinx_flags}"']==] CACHE STRING "Flags to pass to sphinx-build" FORCE)
' >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
fi

# Add user-specified settings.  Handle relative-path case for
# specification of cmake_init_file.
(
cd "${cmake_binary_dir}"
if [ -f "${cmake_init_file}" ]; then
  cat "${cmake_init_file}" >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
fi
)

echo "---------------------------------------------"

# Run make to build bootstrap cmake
if [ "x${cmake_parallel_make}" != "x" ]; then
  ${cmake_make_processor} ${cmake_make_flags}
else
  ${cmake_make_processor}
fi
RES=$?
if [ "${RES}" -ne "0" ]; then
  cmake_error 9 "Problem while running ${cmake_make_processor}"
fi
cd "${cmake_binary_dir}"

# Set C, CXX, and MAKE environment variables, so that real real cmake will be
# build with same compiler and make
CC="${cmake_c_compiler}"
CXX="${cmake_cxx_compiler}"
if [ -n "${cmake_ccache_enabled}" ]; then
  CC="ccache ${CC}"
  CXX="ccache ${CXX}"
fi
MAKE="${cmake_make_processor}"
export CC
export CXX
export MAKE

# Run bootstrap CMake to configure real CMake
cmake_options="-DCMAKE_BOOTSTRAP=1"
if [ -n "${cmake_verbose}" ]; then
  cmake_options="${cmake_options} -DCMAKE_VERBOSE_MAKEFILE=1"
fi
"${cmake_bootstrap_dir}/cmake" "${cmake_source_dir}" "-C${cmake_bootstrap_dir}/InitialCacheFlags.cmake" "-G${cmake_bootstrap_generator}" ${cmake_options} ${cmake_bootstrap_system_libs} "$@"
RES=$?
if [ "${RES}" -ne "0" ]; then
  cmake_error 11 "Problem while running initial CMake"
fi

echo "---------------------------------------------"

# And we are done. Now just run make
echo "CMake has bootstrapped.  Now run ${cmake_make_processor}."
a> 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/


#include <QtGui/QtGui>
#include <QtTest/QtTest>
#include "../../shared/util.h"
#include "private/qapplication_p.h"

//TESTED_CLASS=
//TESTED_FILES=

// Will try to wait for the condition while allowing event processing
// for a maximum of 2 seconds.
#define WAIT_FOR_CONDITION(expr, expected) \
    do { \
        const int step = 100; \
        for (int i = 0; i < 2000 && expr != expected; i+=step) { \
            QTest::qWait(step); \
        } \
    } while(0)

typedef QList<int> IntList;
Q_DECLARE_METATYPE(IntList)

typedef QList<bool> BoolList;
Q_DECLARE_METATYPE(BoolList)

class tst_QTableView : public QObject
{
    Q_OBJECT

public:
    tst_QTableView();
    virtual ~tst_QTableView();

public slots:
    void initTestCase();
    void cleanupTestCase();
    void init();
    void cleanup();

private slots:
    void getSetCheck();

    void noDelegate();
    void noModel();
    void emptyModel();

    void removeRows_data();
    void removeRows();

    void removeColumns_data();
    void removeColumns();

    void keyboardNavigation_data();
    void keyboardNavigation();

    void headerSections_data();
    void headerSections();

    void moveCursor_data();
    void moveCursor();

    void hideRows_data();
    void hideRows();

    void hideColumns_data();
    void hideColumns();

    void selection_data();
    void selection();

    void selectRow_data();
    void selectRow();

    void selectColumn_data();
    void selectColumn();

    void visualRect_data();
    void visualRect();

    void fetchMore();
    void setHeaders();

    void resizeRowsToContents_data();
    void resizeRowsToContents();

    void resizeColumnsToContents_data();
    void resizeColumnsToContents();

    void rowViewportPosition_data();
    void rowViewportPosition();

    void rowAt_data();
    void rowAt();

    void rowHeight_data();
    void rowHeight();

    void columnViewportPosition_data();
    void columnViewportPosition();

    void columnAt_data();
    void columnAt();

    void columnWidth_data();
    void columnWidth();

    void hiddenRow_data();
    void hiddenRow();

    void hiddenColumn_data();
    void hiddenColumn();

    void sortingEnabled_data();
    void sortingEnabled();

    void scrollTo_data();
    void scrollTo();

    void indexAt_data();
    void indexAt();

    void span_data();
    void span();
    void spans();
    void spans_data();

    void checkHeaderReset();
    void checkHeaderMinSize();

    void resizeToContents();

    void tabFocus();
    void bigModel();
    void selectionSignal();

    // task-specific tests:
    void task173773_updateVerticalHeader();
    void task227953_setRootIndex();
    void task240266_veryBigColumn();
    void task248688_autoScrollNavigation();
    void task259308_scrollVerticalHeaderSwappedSections();
    void task191545_dragSelectRows();

    void mouseWheel_data();
    void mouseWheel();

    void addColumnWhileEditing();
};

// Testing get/set functions
void tst_QTableView::getSetCheck()
{
    QTableView obj1;

    obj1.setSortingEnabled(false);
    QCOMPARE(false, obj1.isSortingEnabled());
    obj1.setSortingEnabled(true);
    QCOMPARE(true, obj1.isSortingEnabled());

    obj1.setShowGrid(false);
    QCOMPARE(false, obj1.showGrid());
    obj1.setShowGrid(true);
    QCOMPARE(true, obj1.showGrid());

    obj1.setGridStyle(Qt::NoPen);
    QCOMPARE(Qt::NoPen, obj1.gridStyle());
    obj1.setGridStyle(Qt::SolidLine);
    QCOMPARE(Qt::SolidLine, obj1.gridStyle());

    obj1.setRootIndex(QModelIndex());
    QCOMPARE(QModelIndex(), obj1.rootIndex());
    QStandardItemModel model(10, 10);
    obj1.setModel(&model);
    QModelIndex index = model.index(0, 0);
    obj1.setRootIndex(index);
    QCOMPARE(index, obj1.rootIndex());

    QHeaderView *var1 = new QHeaderView(Qt::Horizontal);
    obj1.setHorizontalHeader(var1);
    QCOMPARE(var1, obj1.horizontalHeader());
    obj1.setHorizontalHeader((QHeaderView *)0);
    QCOMPARE(var1, obj1.horizontalHeader());
    delete var1;

    QHeaderView *var2 = new QHeaderView(Qt::Vertical);
    obj1.setVerticalHeader(var2);
    QCOMPARE(var2, obj1.verticalHeader());
    obj1.setVerticalHeader((QHeaderView *)0);
    QCOMPARE(var2, obj1.verticalHeader());
    delete var2;

    QCOMPARE(obj1.isCornerButtonEnabled(), true);
    obj1.setCornerButtonEnabled(false);
    QCOMPARE(obj1.isCornerButtonEnabled(), false);
}

class QtTestTableModel: public QAbstractTableModel
{
    Q_OBJECT

signals:
    void invalidIndexEncountered() const;

public:
    QtTestTableModel(int rows = 0, int columns = 0, QObject *parent = 0)
        : QAbstractTableModel(parent),
          row_count(rows),
          column_count(columns),
          can_fetch_more(false),
          fetch_more_count(0) {}

    int rowCount(const QModelIndex& = QModelIndex()) const { return row_count; }
    int columnCount(const QModelIndex& = QModelIndex()) const { return column_count; }
    bool isEditable(const QModelIndex &) const { return true; }

    QVariant data(const QModelIndex &idx, int role) const
    {
        if (!idx.isValid() || idx.row() >= row_count || idx.column() >= column_count) {
            qWarning() << "Invalid modelIndex [%d,%d,%p]" << idx;
            emit invalidIndexEncountered();
            return QVariant();
        }

        if (role == Qt::DisplayRole || role == Qt::EditRole)
            return QString("[%1,%2,%3]").arg(idx.row()).arg(idx.column()).arg(0);

        return QVariant();
    }

    void removeLastRow()
    {
        beginRemoveRows(QModelIndex(), row_count - 1, row_count - 1);
        --row_count;
        endRemoveRows();
    }

    void removeAllRows()
    {
        beginRemoveRows(QModelIndex(), 0, row_count - 1);
        row_count = 0;
        endRemoveRows();
    }

    void removeLastColumn()
    {
        beginRemoveColumns(QModelIndex(), column_count - 1, column_count - 1);
        --column_count;
        endRemoveColumns();
    }

    void removeAllColumns()
    {
        beginRemoveColumns(QModelIndex(), 0, column_count - 1);
        column_count = 0;
        endRemoveColumns();
    }

    bool canFetchMore(const QModelIndex &) const
    {
        return can_fetch_more;
    }

    void fetchMore(const QModelIndex &)
    {
        ++fetch_more_count;
    }

    void reset()
    {
        QAbstractTableModel::reset();
    }

    int row_count;
    int column_count;
    bool can_fetch_more;
    int fetch_more_count;
};

class QtTestTableView : public QTableView
{
Q_OBJECT

public:
    QtTestTableView(QWidget *parent = 0) : QTableView(parent), checkSignalOrder(false), hasCurrentChanged(0), hasSelectionChanged(0) {}

    void setModel(QAbstractItemModel *model)
    {
        QTableView::setModel(model);
        connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
                     this, SLOT(currentChanged(QModelIndex,QModelIndex)));
        connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
                     this, SLOT(itemSelectionChanged(QItemSelection,QItemSelection)));
    }

    enum CursorAction {
        MoveUp       = QAbstractItemView::MoveUp,
        MoveDown     = QAbstractItemView::MoveDown,
        MoveLeft     = QAbstractItemView::MoveLeft,
        MoveRight    = QAbstractItemView::MoveRight,
        MoveHome     = QAbstractItemView::MoveHome,
        MoveEnd      = QAbstractItemView::MoveEnd,
        MovePageUp   = QAbstractItemView::MovePageUp,
        MovePageDown = QAbstractItemView::MovePageDown,
        MoveNext     = QAbstractItemView::MoveNext,
        MovePrevious = QAbstractItemView::MovePrevious
    };

    QModelIndex moveCursor(QtTestTableView::CursorAction cursorAction,
                           Qt::KeyboardModifiers modifiers)
    {
        return QTableView::moveCursor((QAbstractItemView::CursorAction)cursorAction, modifiers);
    }

    int columnWidthHint(int column) const
    {
        return sizeHintForColumn(column);
    }

    int rowHeightHint(int row) const
    {
        return sizeHintForRow(row);
    }

    bool isIndexHidden(const QModelIndex &index) const
    {
        return QTableView::isIndexHidden(index);
    }

    void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)
    {
        QTableView::setSelection(rect, command);
    }

    QModelIndexList selectedIndexes() const
    {
        return QTableView::selectedIndexes();
    }

    bool checkSignalOrder;
    using QTableView::wheelEvent;
public slots:
    void currentChanged(QModelIndex , QModelIndex ) {
        hasCurrentChanged++;
        if (checkSignalOrder)
            QVERIFY(hasCurrentChanged > hasSelectionChanged);
    }

    void itemSelectionChanged(QItemSelection , QItemSelection ) {
        hasSelectionChanged++;
        if (checkSignalOrder)
            QVERIFY(hasCurrentChanged >= hasSelectionChanged);
    }
private:
    int hasCurrentChanged;
    int hasSelectionChanged;

};

class QtTestItemDelegate : public QItemDelegate
{
public:
    QSize sizeHint(const QStyleOptionViewItem&, const QModelIndex&) const
    {
        return hint;
    }

    QSize hint;
};

tst_QTableView::tst_QTableView()
{
}

tst_QTableView::~tst_QTableView()
{
}

void tst_QTableView::initTestCase()
{
#ifdef Q_OS_WINCE //disable magic for WindowsCE
    qApp->setAutoMaximizeThreshold(-1);
#endif
}

void tst_QTableView::cleanupTestCase()
{
}

void tst_QTableView::init()
{
}

void tst_QTableView::cleanup()
{
}

void tst_QTableView::noDelegate()
{
    QtTestTableModel model(3, 3);
    QTableView view;
    view.setModel(&model);
    view.setItemDelegate(0);
    view.show();
}

void tst_QTableView::noModel()
{
    QTableView view;
    view.show();
}

void tst_QTableView::emptyModel()
{
    QtTestTableModel model;
    QTableView view;
    QSignalSpy spy(&model, SIGNAL(invalidIndexEncountered()));
    view.setModel(&model);
    view.show();
    QCOMPARE(spy.count(), 0);
}

void tst_QTableView::removeRows_data()
{
    QTest::addColumn<int>("rowCount");
    QTest::addColumn<int>("columnCount");

    QTest::newRow("2x2") << 2 << 2;
    QTest::newRow("10x10") << 10  << 10;
}

void tst_QTableView::removeRows()
{
    QFETCH(int, rowCount);
    QFETCH(int, columnCount);

    QtTestTableModel model(rowCount, columnCount);
    QSignalSpy spy(&model, SIGNAL(invalidIndexEncountered()));

    QTableView view;
    view.setModel(&model);
    view.show();

    model.removeLastRow();
    QCOMPARE(spy.count(), 0);

    model.removeAllRows();
    QCOMPARE(spy.count(), 0);
}

void tst_QTableView::removeColumns_data()
{
    QTest::addColumn<int>("rowCount");
    QTest::addColumn<int>("columnCount");

    QTest::newRow("2x2") << 2 << 2;
    QTest::newRow("10x10") << 10  << 10;
}

void tst_QTableView::removeColumns()
{
    QFETCH(int, rowCount);
    QFETCH(int, columnCount);

    QtTestTableModel model(rowCount, columnCount);
    QSignalSpy spy(&model, SIGNAL(invalidIndexEncountered()));

    QTableView view;
    view.setModel(&model);
    view.show();

    model.removeLastColumn();
    QCOMPARE(spy.count(), 0);

    model.removeAllColumns();
    QCOMPARE(spy.count(), 0);
}

void tst_QTableView::keyboardNavigation_data()
{
    QTest::addColumn<int>("rowCount");
    QTest::addColumn<int>("columnCount");
    QTest::addColumn<bool>("tabKeyNavigation");
    QTest::addColumn<IntList>("keyPresses");

    QTest::newRow("16x16 model") << 16  << 16 << true
                                 << (IntList()
                                     << Qt::Key_Up
                                     << Qt::Key_Up
                                     << Qt::Key_Right
                                     << Qt::Key_Right
                                     << Qt::Key_Up
                                     << Qt::Key_Left
                                     << Qt::Key_Left
                                     << Qt::Key_Up
                                     << Qt::Key_Down
                                     << Qt::Key_Up
                                     << Qt::Key_Up
                                     << Qt::Key_Up
                                     << Qt::Key_Up
                                     << Qt::Key_Up
                                     << Qt::Key_Up
                                     << Qt::Key_Left
                                     << Qt::Key_Left
                                     << Qt::Key_Up
                                     << Qt::Key_Down
                                     << Qt::Key_Down
                                     << Qt::Key_Tab
                                     << Qt::Key_Backtab);


    QTest::newRow("no tab") << 8  << 8 <<  false
                                 << (IntList()
                                     << Qt::Key_Up
                                     << Qt::Key_Up
                                     << Qt::Key_Right
                                     << Qt::Key_Right
                                     << Qt::Key_Up
                                     << Qt::Key_Left
                                     << Qt::Key_Left
                                     << Qt::Key_Up
                                     << Qt::Key_Down
                                     << Qt::Key_Up
                                     << Qt::Key_Up
                                     << Qt::Key_Up
                                     << Qt::Key_Up
                                     << Qt::Key_Up
                                     << Qt::Key_Up
                                     << Qt::Key_Left
                                     << Qt::Key_Left
                                     << Qt::Key_Up
                                     << Qt::Key_Down
                                     << Qt::Key_Down
                                     << Qt::Key_Tab
                                     << Qt::Key_Backtab);
}

void tst_QTableView::keyboardNavigation()
{
    QFETCH(int, rowCount);
    QFETCH(int, columnCount);
    QFETCH(bool, tabKeyNavigation);
    QFETCH(IntList, keyPresses);

    QtTestTableModel model(rowCount, columnCount);
    QTableView view;
    view.setModel(&model);

    view.setTabKeyNavigation(tabKeyNavigation);
    QModelIndex index = model.index(rowCount - 1, columnCount - 1);
    view.setCurrentIndex(index);

    view.show();
    QTest::qWaitForWindowShown(&view);
    qApp->setActiveWindow(&view);

    int row = rowCount - 1;
    int column = columnCount - 1;
    for (int i = 0; i < keyPresses.count(); ++i) {

        Qt::Key key = (Qt::Key)keyPresses.at(i);

        switch (key) {
        case Qt::Key_Up:
            row = qMax(0, row - 1);
            break;
        case Qt::Key_Down:
            row = qMin(rowCount - 1, row + 1);
            break;
        case Qt::Key_Backtab:
            if (!tabKeyNavigation)
                break;
        case Qt::Key_Left:
            column = qMax(0, column - 1);
            break;
        case Qt::Key_Tab:
            if (!tabKeyNavigation)
                break;
        case Qt::Key_Right:
            column = qMin(columnCount - 1, column + 1);
            break;
        default:
            break;
        }

        QTest::keyClick(&view, key);
        QApplication::processEvents();

        QModelIndex index = model.index(row, column);
        QCOMPARE(view.currentIndex(), index);
    }
}

void tst_QTableView::headerSections_data()
{
    QTest::addColumn<int>("rowCount");
    QTest::addColumn<int>("columnCount");
    QTest::addColumn<int>("row");
    QTest::addColumn<int>("column");
    QTest::addColumn<int>("rowHeight");
    QTest::addColumn<int>("columnWidth");

    QTest::newRow("") << 10 << 10 << 5 << 5 << 30 << 30;
}

void tst_QTableView::headerSections()
{
    QFETCH(int, rowCount);
    QFETCH(int, columnCount);
    QFETCH(int, row);
    QFETCH(int, column);
    QFETCH(int, rowHeight);
    QFETCH(int, columnWidth);

    QtTestTableModel model(rowCount, columnCount);

    QTableView view;
    QHeaderView *hheader = view.horizontalHeader();
    QHeaderView *vheader = view.verticalHeader();

    view.setModel(&model);
    view.show();

    hheader->doItemsLayout();
    vheader->doItemsLayout();

    QCOMPARE(hheader->count(), model.columnCount());
    QCOMPARE(vheader->count(), model.rowCount());

    view.setRowHeight(row, rowHeight);
    QCOMPARE(view.rowHeight(row), rowHeight);
    view.hideRow(row);
    QCOMPARE(view.rowHeight(row), 0);
    view.showRow(row);
    QCOMPARE(view.rowHeight(row), rowHeight);

    view.setColumnWidth(column, columnWidth);
    QCOMPARE(view.columnWidth(column), columnWidth);
    view.hideColumn(column);
    QCOMPARE(view.columnWidth(column), 0);
    view.showColumn(column);
    QCOMPARE(view.columnWidth(column), columnWidth);
}

typedef QPair<int,int> IntPair;
Q_DECLARE_METATYPE(IntPair)

void tst_QTableView::moveCursor_data()
{
    QTest::addColumn<int>("rowCount");
    QTest::addColumn<int>("columnCount");
    QTest::addColumn<int>("hideRow");
    QTest::addColumn<int>("hideColumn");

    QTest::addColumn<int>("startRow");
    QTest::addColumn<int>("startColumn");

    QTest::addColumn<int>("cursorMoveAction");
    QTest::addColumn<int>("modifier");

    QTest::addColumn<int>("expectedRow");
    QTest::addColumn<int>("expectedColumn");
    QTest::addColumn<IntPair>("moveRow");
    QTest::addColumn<IntPair>("moveColumn");

    // MoveRight
    QTest::newRow("MoveRight (0,0)")
        << 4 << 4 << -1 << -1
        << 0 << 0
        << int(QtTestTableView::MoveRight) << int(Qt::NoModifier)
        << 0 << 1 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveRight (3,0)")
        << 4 << 4 << -1 << -1
        << 3 << 0
        << int(QtTestTableView::MoveRight) << int(Qt::NoModifier)
        << 3 << 1 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveRight (3,3)")
        << 4 << 4 << -1 << -1
        << 3 << 3
        << int(QtTestTableView::MoveRight) << int(Qt::NoModifier)
        << 3 << 3 << IntPair(0,0) << IntPair(0,0); // ###

    QTest::newRow("MoveRight, hidden column 1 (0,0)")
        << 4 << 4 << -1 << 1
        << 0 << 0
        << int(QtTestTableView::MoveRight) << int(Qt::NoModifier)
        << 0 << 2 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveRight, hidden column 3 (0,2)")
        << 4 << 4 << -1 << 3
        << 0 << 2
        << int(QtTestTableView::MoveRight) << int(Qt::NoModifier)
        << 0 << 2 << IntPair(0,0) << IntPair(0,0); // ###

    // MoveNext should in addition wrap
    QTest::newRow("MoveNext (0,0)")
        << 4 << 4 << -1 << -1
        << 0 << 0
        << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
        << 0 << 1 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveNext (0,2)")
        << 4 << 4 << -1 << -1
        << 0 << 2
        << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
        << 0 << 3 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveNext, wrap (0,3)")
        << 4 << 4 << -1 << -1
        << 0 << 3
        << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
        << 1 << 0 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveNext, wrap (3,3)")
        << 4 << 4 << -1 << -1
        << 3 << 3
        << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
        << 0 << 0 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveNext, hidden column 1 (0,0)")
        << 4 << 4 << -1 << 1
        << 0 << 0
        << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
        << 0 << 2 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveNext, wrap, hidden column 3 (0,2)")
        << 4 << 4 << -1 << 3
        << 0 << 2
        << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
        << 1 << 0 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveNext, wrap, hidden column 3 (3,2)")
        << 4 << 4 << -1 << 3
        << 3 << 2
        << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
        << 0 << 0 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveNext, wrapy, wrapx, hidden column 3, hidden row 3 (2,2)")
        << 4 << 4 << 3 << 3
        << 2 << 2
        << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
        << 0 << 0 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveNext, wrap, hidden column 2, moved column from 3 to 0. (0,2)")
        << 4 << 4 << -1 << 2
        << 0 << 2
        << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
        << 1 << 0 << IntPair(0,0) << IntPair(3,0);

    // MoveLeft
    QTest::newRow("MoveLeft (0,0)")
        << 4 << 4 << -1 << -1
        << 0 << 0
        << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier)
        << 0 << 0 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveLeft (0,3)")
        << 4 << 4 << -1 << -1
        << 0 << 3
        << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier)
        << 0 << 2 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveLeft (1,0)")
        << 4 << 4 << -1 << -1
        << 1 << 0
        << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier)
        << 1 << 0 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveLeft, hidden column 0 (0,2)")
        << 4 << 4 << -1 << 1
        << 0 << 2
        << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier)
        << 0 << 0 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveLeft, hidden column 0 (0,1)")
        << 4 << 4 << -1 << 0
        << 0 << 1
        << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier)
        << 0 << 1 << IntPair(0,0) << IntPair(0,0);

    // MovePrevious should in addition wrap
    QTest::newRow("MovePrevious (0,3)")
        << 4 << 4 << -1 << -1
        << 0 << 3
        << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
        << 0 << 2 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MovePrevious (0,1)")
        << 4 << 4 << -1 << -1
        << 0 << 1
        << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
        << 0 << 0 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MovePrevious, wrap (1,0)")
        << 4 << 4 << -1 << -1
        << 1 << 0
        << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
        << 0 << 3 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MovePrevious, wrap, (0,0)")
        << 4 << 4 << -1 << -1
        << 0 << 0
        << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
        << 3 << 3 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MovePrevious, hidden column 1 (0,2)")
        << 4 << 4 << -1 << 1
        << 0 << 2
        << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
        << 0 << 0 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MovePrevious, wrap, hidden column 3 (0,2)")
        << 4 << 4 << -1 << 3
        << 0 << 2
        << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
        << 0 << 1 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MovePrevious, wrapy, hidden column 0 (0,1)")
        << 4 << 4 << -1 << 0
        << 0 << 1
        << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
        << 3 << 3 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MovePrevious, wrap, hidden column 0, hidden row 0 (1,1)")
        << 4 << 4 << 0 << 0
        << 1 << 1
        << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
        << 3 << 3 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MovePrevious, wrap, hidden column 1, moved column from 0 to 3. (1,2)")
        << 4 << 4 << -1 << 1
        << 1 << 2
        << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
        << 0 << 0 << IntPair(0,0) << IntPair(0,3);

    // MoveDown
    QTest::newRow("MoveDown (0,0)")
        << 4 << 4 << -1 << -1
        << 0 << 0
        << int(QtTestTableView::MoveDown) << int(Qt::NoModifier)
        << 1 << 0 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveDown (3,0)")
        << 4 << 4 << -1 << -1
        << 3 << 0
        << int(QtTestTableView::MoveDown) << int(Qt::NoModifier)
        << 3 << 0 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveDown (3,3)")
        << 4 << 4 << -1 << -1
        << 3 << 3
        << int(QtTestTableView::MoveDown) << int(Qt::NoModifier)
        << 3 << 3 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveDown, hidden row 1 (0,0)")
        << 4 << 4 << 1 << -1
        << 0 << 0
        << int(QtTestTableView::MoveDown) << int(Qt::NoModifier)
        << 2 << 0 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveDown, hidden row 3 (2,0)")
        << 4 << 4 << 3 << -1
        << 2 << 0
        << int(QtTestTableView::MoveDown) << int(Qt::NoModifier)
        << 2 << 0 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveDown, hidden row 0 hidden column 0 (0,0)")
        << 4 << 4 << 0 << 0
        << 0 << 0
        << int(QtTestTableView::MoveDown) << int(Qt::NoModifier)
        << 1 << 1 << IntPair(0,0) << IntPair(0,0);

    // MoveUp
    QTest::newRow("MoveUp (0,0)")
        << 4 << 4 << -1 << -1
        << 0 << 0
        << int(QtTestTableView::MoveUp) << int(Qt::NoModifier)
        << 0 << 0 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveUp (3, 0)")
        << 4 << 4 << -1 << -1
        << 3 << 0
        << int(QtTestTableView::MoveUp) << int(Qt::NoModifier)
        << 2 << 0 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveUp (0,1)")
        << 4 << 4 << -1 << -1
        << 0 << 1
        << int(QtTestTableView::MoveUp) << int(Qt::NoModifier)
        << 0 << 1 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveUp, hidden row 1 (2,0)")
        << 4 << 4 << 1 << -1
        << 2 << 0
        << int(QtTestTableView::MoveUp) << int(Qt::NoModifier)
        << 0 << 0 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveUp, hidden row (1,0)")
        << 4 << 4 << 0 << -1
        << 1 << 0
        << int(QtTestTableView::MoveUp) << int(Qt::NoModifier)
        << 1 << 0 << IntPair(0,0) << IntPair(0,0);

    // MoveHome
    QTest::newRow("MoveHome (0,0)")
        << 4 << 4 << -1 << -1
        << 0 << 0
        << int(QtTestTableView::MoveHome) << int(Qt::NoModifier)
        << 0 << 0 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveHome (3,3)")
        << 4 << 4 << -1 << -1
        << 3 << 3
        << int(QtTestTableView::MoveHome) << int(Qt::NoModifier)
        << 3 << 0 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveHome, hidden column 0 (3,3)")
        << 4 << 4 << -1 << 0
        << 3 << 3
        << int(QtTestTableView::MoveHome) << int(Qt::NoModifier)
        << 3 << 1 << IntPair(0,0) << IntPair(0,0);

    // Use Ctrl modifier
    QTest::newRow("MoveHome + Ctrl (0,0)")
        << 4 << 4 << -1 << -1
        << 0 << 0
        << int(QtTestTableView::MoveHome) << int(Qt::ControlModifier)
        << 0 << 0 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveHome + Ctrl (3,3)")
        << 4 << 4 << -1 << -1
        << 3 << 3
        << int(QtTestTableView::MoveHome) << int(Qt::ControlModifier)
        << 0 << 0 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveHome + Ctrl, hidden column 0, hidden row 0 (3,3)")
        << 4 << 4 << 0 << 0
        << 3 << 3
        << int(QtTestTableView::MoveHome) << int(Qt::ControlModifier)
        << 1 << 1 << IntPair(0,0) << IntPair(0,0);

    // MoveEnd
    QTest::newRow("MoveEnd (0,0)")
        << 4 << 4 << -1 << -1
        << 0 << 0
        << int(QtTestTableView::MoveEnd) << int(Qt::NoModifier)
        << 0 << 3 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveEnd (3,3)")
        << 4 << 4 << -1 << -1
        << 3 << 3
        << int(QtTestTableView::MoveEnd) << int(Qt::NoModifier)
        << 3 << 3 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveEnd, hidden column (0,0)")
        << 4 << 4 << -1 << 3
        << 0 << 0
        << int(QtTestTableView::MoveEnd) << int(Qt::NoModifier)
        << 0<< 2 << IntPair(0,0) << IntPair(0,0);

    // Use Ctrl modifier
    QTest::newRow("MoveEnd + Ctrl (0,0)")
        << 4 << 4 << -1 << -1
        << 0 << 0
        << int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier)
        << 3 << 3 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveEnd + Ctrl (3,3)")
        << 4 << 4 << -1 << -1
        << 3 << 3
        << int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier)
        << 3 << 3 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveEnd + Ctrl, hidden column 3 (0,0)")
        << 4 << 4 << -1 << 3
        << 0 << 0
        << int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier)
        << 3 << 2 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MoveEnd + Ctrl, hidden column 3, hidden row 3 (0,0)")
        << 4 << 4 << 3 << 3
        << 0 << 0
        << int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier)
        << 2 << 2 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MovePageUp (0,0)")
        << 4 << 4 << -1 << -1
        << 0 << 0
        << int(QtTestTableView::MovePageUp) << 0
        << 0 << 0 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MovePageUp (3,3)")
        << 4 << 4 << -1 << -1
        << 3 << 3
        << int(QtTestTableView::MovePageUp) << 0
        << 0 << 3 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MovePageDown (3, 3)")
        << 4 << 4 << -1 << -1
        << 3 << 3
        << int(QtTestTableView::MovePageDown) << 0
        << 3 << 3 << IntPair(0,0) << IntPair(0,0);

    QTest::newRow("MovePageDown (0, 3)")
        << 4 << 4 << -1 << -1
        << 0 << 3
        << int(QtTestTableView::MovePageDown) << 0
        << 3 << 3 << IntPair(0,0) << IntPair(0,0);
}

void tst_QTableView::moveCursor()
{
    QFETCH(int, rowCount);
    QFETCH(int, columnCount);
    QFETCH(int, hideRow);
    QFETCH(int, hideColumn);
    QFETCH(int, startRow);
    QFETCH(int, startColumn);
    QFETCH(int, cursorMoveAction);
    QFETCH(int, modifier);
    QFETCH(int, expectedRow);
    QFETCH(int, expectedColumn);
    QFETCH(IntPair, moveRow);
    QFETCH(IntPair, moveColumn);

    QtTestTableModel model(rowCount, columnCount);
    QtTestTableView view;

    view.setModel(&model);
    view.hideRow(hideRow);
    view.hideColumn(hideColumn);
    if (moveColumn.first != moveColumn.second)
        view.horizontalHeader()->moveSection(moveColumn.first, moveColumn.second);
    if (moveRow.first != moveRow.second)
        view.verticalHeader()->moveSection(moveRow.first, moveRow.second);

    view.show();

    QModelIndex index = model.index(startRow, startColumn);
    view.setCurrentIndex(index);

    QModelIndex newIndex = view.moveCursor((QtTestTableView::CursorAction)cursorMoveAction,
                                           (Qt::KeyboardModifiers)modifier);
    // expected fails, task 119433
    if(newIndex.row() == -1)
        return;
    QCOMPARE(newIndex.row(), expectedRow);
    QCOMPARE(newIndex.column(), expectedColumn);
}

void tst_QTableView::hideRows_data()
{
    QTest::addColumn<int>("rowCount");
    QTest::addColumn<int>("columnCount");
    QTest::addColumn<int>("showRow"); // hide, then show
    QTest::addColumn<int>("hideRow"); // hide only
    QTest::addColumn<int>("row");
    QTest::addColumn<int>("column");
    QTest::addColumn<int>("rowSpan");
    QTest::addColumn<int>("columnSpan");

    QTest::newRow("show row 0, hide row 3, no span")
      << 10 << 10
      << 0
      << 3
      << -1 << -1
      << 1 << 1;

    QTest::newRow("show row 0, hide row 3, span")
      << 10 << 10
      << 0
      << 3
      << 0 << 0
      << 3 << 2;
}

void tst_QTableView::hideRows()
{
    QFETCH(int, rowCount);
    QFETCH(int, columnCount);
    QFETCH(int, showRow);
    QFETCH(int, hideRow);
    QFETCH(int, row);
    QFETCH(int, column);
    QFETCH(int, rowSpan);
    QFETCH(int, columnSpan);

    QtTestTableModel model(rowCount, columnCount);
    QTableView view;

    view.setModel(&model);
    view.setSpan(row, column, rowSpan, columnSpan);

    view.hideRow(showRow);
    QVERIFY(view.isRowHidden(showRow));

    view.hideRow(hideRow);
    QVERIFY(view.isRowHidden(hideRow));

    view.showRow(showRow);
    QVERIFY(!view.isRowHidden(showRow));
    QVERIFY(view.isRowHidden(hideRow));
}

void tst_QTableView::hideColumns_data()
{
    QTest::addColumn<int>("rowCount");
    QTest::addColumn<int>("columnCount");
    QTest::addColumn<int>("showColumn"); // hide, then show
    QTest::addColumn<int>("hideColumn"); // hide only
    QTest::addColumn<int>("row");
    QTest::addColumn<int>("column");
    QTest::addColumn<int>("rowSpan");
    QTest::addColumn<int>("columnSpan");

    QTest::newRow("show col 0, hide col 3, no span")
      << 10 << 10
      << 0
      << 3
      << -1 << -1
      << 1 << 1;

    QTest::newRow("show col 0, hide col 3, span")
      << 10 << 10
      << 0
      << 3
      << 0 << 0
      << 3 << 2;
}

void tst_QTableView::hideColumns()
{
    QFETCH(int, rowCount);
    QFETCH(int, columnCount);
    QFETCH(int, showColumn);
    QFETCH(int, hideColumn);
    QFETCH(int, row);
    QFETCH(int, column);
    QFETCH(int, rowSpan);
    QFETCH(int, columnSpan);

    QtTestTableModel model(rowCount, columnCount);

    QTableView view;
    view.setModel(&model);
    view.setSpan(row, column, rowSpan, columnSpan);

    view.hideColumn(showColumn);
    QVERIFY(view.isColumnHidden(showColumn));

    view.hideColumn(hideColumn);
    QVERIFY(view.isColumnHidden(hideColumn));

    view.showColumn(showColumn);
    QVERIFY(!view.isColumnHidden(showColumn));
    QVERIFY(view.isColumnHidden(hideColumn));
}

void tst_QTableView::selection_data()
{
    QTest::addColumn<int>("rowCount");