Imported Upstream version 3.25.0
[platform/upstream/cmake.git] / Tests / ComplexOneConfig / Executable / complex.cxx
1 #include "cmTestConfigure.h"
2 #include "cmTestConfigureEscape.h"
3 #include "cmTestGeneratedHeader.h"
4 #include "cmVersion.h"
5
6 #include "Aout.h"
7 #include "ExtraSources/file1.h"
8 #include "file2.h"
9 #include "sharedFile.h"
10 extern "C" {
11 #include "testConly.h"
12 }
13 #include <iostream>
14 #include <string>
15 #include <vector>
16
17 #include <stdio.h>
18 #include <string.h>
19
20 #include <sys/stat.h>
21 #if !defined(S_ISDIR)
22 #  define S_ISDIR(mode) ((mode)&_S_IFDIR)
23 #endif
24
25 #ifdef COMPLEX_TEST_LINK_STATIC
26 extern "C" {
27 int TestLinkGetType();
28 }
29 #endif
30
31 int cm_passed = 0;
32 int cm_failed = 0;
33 // ======================================================================
34
35 void cmFailed(const char* Message, const char* m2 = "", const char* m3 = "")
36 {
37   std::cout << "FAILED: " << Message << m2 << m3 << "\n";
38   cm_failed++;
39 }
40
41 // ======================================================================
42
43 void cmPassed(const char* Message, const char* m2 = "")
44 {
45   std::cout << "Passed: " << Message << m2 << "\n";
46   cm_passed++;
47 }
48
49 #ifndef COMPLEX_DEFINED_PRE
50 #  error "COMPLEX_DEFINED_PRE not defined!"
51 #endif
52
53 #ifdef COMPLEX_DEFINED
54 #  error "COMPLEX_DEFINED is defined but it should not!"
55 #endif
56
57 #ifndef COMPLEX_DEFINED_POST
58 #  error "COMPLEX_DEFINED_POST not defined!"
59 #endif
60
61 #ifndef CMAKE_IS_REALLY_FUN
62 #  error This is a problem. Looks like ADD_DEFINITIONS and REMOVE_DEFINITIONS does not work
63 #endif
64
65 #if defined(COMPLEX_NDEBUG) && !defined(CMAKE_IS_FUN_IN_RELEASE_MODE)
66 #  error Per-configuration directory-level definition not inherited.
67 #endif
68
69 // ======================================================================
70
71 void TestAndRemoveFile(const char* filename)
72 {
73   struct stat st;
74   if (stat(filename, &st) < 0) {
75     cmFailed("Could not find file: ", filename);
76   } else {
77     if (remove(filename) < 0) {
78       cmFailed("Unable to remove file. It does not imply that this test "
79                "failed, but it *will* be corrupted thereafter if this file is "
80                "not removed: ",
81                filename);
82     } else {
83       cmPassed("Find and remove file: ", filename);
84     }
85   }
86 }
87
88 // ======================================================================
89
90 void TestDir(const char* filename)
91 {
92   struct stat st;
93   if (stat(filename, &st) < 0 || !S_ISDIR(st.st_mode)) {
94     cmFailed("Could not find dir: ", filename);
95   } else {
96     cmPassed("Find dir: ", filename);
97   }
98 }
99
100 // Here is a stupid function that tries to use std::string methods
101 // so that the dec cxx compiler will instantiate the stuff that
102 // we are using from the CMakeLib library....
103 void ForceStringUse()
104 {
105   std::vector<std::string> v;
106   std::vector<std::string> v2;
107   v = v2;
108   std::string cachetest = CACHE_TEST_VAR_INTERNAL;
109   v.push_back(cachetest);
110   v2 = v;
111   std::string x(5, 'x');
112   char buff[5];
113   x.copy(buff, 1, 0);
114   x[0] = 'a';
115   std::string::size_type pos = 0;
116   x.replace(pos, pos, pos, 'x');
117   std::string copy = cachetest;
118   cachetest.find("bar");
119   cachetest.rfind("bar");
120   copy.append(cachetest);
121   copy = cachetest.substr(0, cachetest.size());
122 }
123
124 // defined in testcflags.c
125 extern "C" int TestCFlags(char* m);
126 extern "C" int TestTargetCompileFlags(char* m);
127
128 #if 0
129 // defined in  Sub1/NameConflictTest.c
130 extern "C" int NameConflictTest1();
131 // defined in  Sub2/NameConflictTest.c
132 extern "C" int NameConflictTest2();
133 #endif
134
135 // ======================================================================
136
137 int main()
138 {
139 #if 0
140   if(NameConflictTest1() == 0 && NameConflictTest2() == 0)
141     {
142     cmPassed("Sub dir with same named source works");
143     }
144   else
145     {
146     cmFailed("Sub dir with same named source fails");
147     }
148 #endif
149   if (file1() != 1) {
150     cmFailed("Call to file1 function from library failed.");
151   } else {
152     cmPassed("Call to file1 function returned 1.");
153   }
154 #ifndef COMPLEX_TARGET_FLAG
155   cmFailed("COMPILE_FLAGS did not work with SET_TARGET_PROPERTIES");
156 #else
157   cmPassed("COMPILE_FLAGS did work with SET_TARGET_PROPERTIES");
158 #endif
159
160 #ifdef ELSEIF_RESULT
161   cmPassed("ELSEIF did work");
162 #else
163   cmFailed("ELSEIF did not work");
164 #endif
165
166 #ifdef CONDITIONAL_PARENTHESES
167   cmPassed("CONDITIONAL_PARENTHESES did work");
168 #else
169   cmFailed("CONDITIONAL_PARENTHESES did not work");
170 #endif
171
172   if (file2() != 1) {
173     cmFailed("Call to file2 function from library failed.");
174   } else {
175     cmPassed("Call to file2 function returned 1.");
176   }
177 #ifndef TEST_CXX_FLAGS
178   cmFailed("CMake CMAKE_CXX_FLAGS is not being passed to the compiler!");
179 #else
180   cmPassed("CMake CMAKE_CXX_FLAGS is being passed to the compiler.");
181 #endif
182   std::string gen = CMAKE_GENERATOR;
183   // visual studio is currently broken for c flags
184   char msg[1024];
185   if (gen.find("Visual") == gen.npos) {
186 #ifdef TEST_C_FLAGS
187     cmFailed(
188       "CMake CMAKE_C_FLAGS are being passed to c++ files the compiler!");
189 #else
190     cmPassed("CMake CMAKE_C_FLAGS are not being passed to c++ files.");
191 #endif
192     if (TestCFlags(msg)) {
193       cmPassed("CMake CMAKE_C_FLAGS are being passed to c files and CXX flags "
194                "are not.");
195     } else {
196       cmFailed(msg);
197     }
198   }
199   if (TestTargetCompileFlags(msg)) {
200     cmPassed(msg);
201   } else {
202     cmFailed(msg);
203   }
204
205   // ----------------------------------------------------------------------
206   // Test ADD_DEFINITIONS
207
208 #ifndef CMAKE_IS_FUN
209   cmFailed("CMake is not fun, so it is broken and should be fixed.");
210 #else
211   cmPassed("CMAKE_IS_FUN is defined.");
212 #endif
213
214 #if defined(CMAKE_ARGV1) && defined(CMAKE_ARGV2) && defined(CMAKE_ARGV3) &&   \
215   defined(CMAKE_ARGV4)
216   cmPassed("Variable args for MACROs are working.");
217 #else
218   cmFailed("Variable args for MACROs are failing.");
219 #endif
220
221 // ----------------------------------------------------------------------
222 // Test GET_SOURCE_FILE_PROPERTY for location
223 #ifndef CMAKE_FOUND_ACXX
224   cmFailed("CMake did not get the location of A.cxx correctly");
225 #else
226   cmPassed("CMake found A.cxx properly");
227 #endif
228
229 // ----------------------------------------------------------------------
230 // Test GET_DIRECTORY_PROPERTY for parent
231 #ifndef CMAKE_FOUND_PARENT
232   cmFailed("CMake did not get the location of the parent directory properly");
233 #else
234   cmPassed("CMake found the parent directory properly");
235 #endif
236
237 // ----------------------------------------------------------------------
238 // Test GET_DIRECTORY_PROPERTY for listfiles
239 #ifndef CMAKE_FOUND_LISTFILE_STACK
240   cmFailed("CMake did not get the listfile stack properly");
241 #else
242   cmPassed("CMake found the listfile stack properly");
243 #endif
244
245   // ----------------------------------------------------------------------
246   // Test SET, VARIABLE_REQUIRES
247
248 #ifdef SHOULD_NOT_BE_DEFINED
249   cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED is defined.");
250 #else
251   cmPassed("SHOULD_NOT_BE_DEFINED is not defined.");
252 #endif
253
254 #ifndef SHOULD_BE_DEFINED
255   cmFailed("IF or SET is broken, SHOULD_BE_DEFINED is not defined.\n");
256 #else
257   cmPassed("SHOULD_BE_DEFINED is defined.");
258 #endif
259
260 #ifndef ONE_VAR
261   cmFailed("cmakedefine is broken, ONE_VAR is not defined.");
262 #else
263   cmPassed("ONE_VAR is defined.");
264 #endif
265
266 #ifndef ONE_VAR_AND_INDENTED
267   cmFailed("cmakedefine is broken, ONE_VAR_AND_INDENTED is not defined.");
268 #else
269   cmPassed("ONE_VAR_AND_INDENTED is defined.");
270 #endif
271
272 #ifndef ONE_VAR_IS_DEFINED
273   cmFailed("cmakedefine, SET or VARIABLE_REQUIRES is broken, "
274            "ONE_VAR_IS_DEFINED is not defined.");
275 #else
276   cmPassed("ONE_VAR_IS_DEFINED is defined.");
277 #endif
278
279 #ifdef ZERO_VAR
280   cmFailed("cmakedefine is broken, ZERO_VAR is defined.");
281 #else
282   cmPassed("ZERO_VAR is not defined.");
283 #endif
284
285 #ifdef ZERO_VAR_AND_INDENTED
286   cmFailed("cmakedefine is broken, ZERO_VAR_AND_INDENTED is defined.");
287 #else
288   cmPassed("ZERO_VAR_AND_INDENTED is not defined.");
289 #endif
290
291 #ifndef STRING_VAR
292   cmFailed("the CONFIGURE_FILE command is broken, STRING_VAR is not defined.");
293 #else
294   if (strcmp(STRING_VAR, "CMake is great") != 0) {
295     cmFailed("the SET or CONFIGURE_FILE command is broken. STRING_VAR == ",
296              STRING_VAR);
297   } else {
298     cmPassed("STRING_VAR == ", STRING_VAR);
299   }
300 #endif
301
302   // ----------------------------------------------------------------------
303   // Test various IF/ELSE combinations
304
305 #ifdef SHOULD_NOT_BE_DEFINED_NOT
306   cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_NOT is defined.");
307 #else
308   cmPassed("SHOULD_NOT_BE_DEFINED_NOT is not defined.");
309 #endif
310
311 #ifndef SHOULD_BE_DEFINED_NOT
312   cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_NOT is not defined.\n");
313 #else
314   cmPassed("SHOULD_BE_DEFINED_NOT is defined.");
315 #endif
316
317 #ifdef SHOULD_NOT_BE_DEFINED_NOT2
318   cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_NOT2 is defined.");
319 #else
320   cmPassed("SHOULD_NOT_BE_DEFINED_NOT2 is not defined.");
321 #endif
322
323 #ifndef SHOULD_BE_DEFINED_NOT2
324   cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_NOT2 is not defined.\n");
325 #else
326   cmPassed("SHOULD_BE_DEFINED_NOT2 is defined.");
327 #endif
328
329 #ifdef SHOULD_NOT_BE_DEFINED_AND
330   cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_AND is defined.");
331 #else
332   cmPassed("SHOULD_NOT_BE_DEFINED_AND is not defined.");
333 #endif
334
335 #ifndef SHOULD_BE_DEFINED_AND
336   cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_AND is not defined.\n");
337 #else
338   cmPassed("SHOULD_BE_DEFINED_AND is defined.");
339 #endif
340
341 #ifdef SHOULD_NOT_BE_DEFINED_AND2
342   cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_AND2 is defined.");
343 #else
344   cmPassed("SHOULD_NOT_BE_DEFINED_AND2 is not defined.");
345 #endif
346
347 #ifndef SHOULD_BE_DEFINED_AND2
348   cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_AND2 is not defined.\n");
349 #else
350   cmPassed("SHOULD_BE_DEFINED_AND2 is defined.");
351 #endif
352
353 #ifdef SHOULD_NOT_BE_DEFINED_OR
354   cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_OR is defined.");
355 #else
356   cmPassed("SHOULD_NOT_BE_DEFINED_OR is not defined.");
357 #endif
358
359 #ifndef SHOULD_BE_DEFINED_OR
360   cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_OR is not defined.\n");
361 #else
362   cmPassed("SHOULD_BE_DEFINED_OR is defined.");
363 #endif
364
365 #ifdef SHOULD_NOT_BE_DEFINED_OR2
366   cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_OR2 is defined.");
367 #else
368   cmPassed("SHOULD_NOT_BE_DEFINED_OR2 is not defined.");
369 #endif
370
371 #ifndef SHOULD_BE_DEFINED_OR2
372   cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_OR2 is not defined.\n");
373 #else
374   cmPassed("SHOULD_BE_DEFINED_OR2 is defined.");
375 #endif
376
377 #ifdef SHOULD_NOT_BE_DEFINED_MATCHES
378   cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_MATCHES is defined.");
379 #else
380   cmPassed("SHOULD_NOT_BE_DEFINED_MATCHES is not defined.");
381 #endif
382
383 #ifndef SHOULD_BE_DEFINED_MATCHES
384   cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_MATCHES is not defined.\n");
385 #else
386   cmPassed("SHOULD_BE_DEFINED_MATCHES is defined.");
387 #endif
388
389 #ifdef SHOULD_NOT_BE_DEFINED_MATCHES2
390   cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_MATCHES2 is defined.");
391 #else
392   cmPassed("SHOULD_NOT_BE_DEFINED_MATCHES2 is not defined.");
393 #endif
394
395 #ifndef SHOULD_BE_DEFINED_MATCHES2
396   cmFailed(
397     "IF or SET is broken, SHOULD_BE_DEFINED_MATCHES2 is not defined.\n");
398 #else
399   cmPassed("SHOULD_BE_DEFINED_MATCHES2 is defined.");
400 #endif
401
402 #ifdef SHOULD_NOT_BE_DEFINED_COMMAND
403   cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_COMMAND is defined.");
404 #else
405   cmPassed("SHOULD_NOT_BE_DEFINED_COMMAND is not defined.");
406 #endif
407
408 #ifndef SHOULD_BE_DEFINED_COMMAND
409   cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_COMMAND is not defined.\n");
410 #else
411   cmPassed("SHOULD_BE_DEFINED_COMMAND is defined.");
412 #endif
413
414 #ifdef SHOULD_NOT_BE_DEFINED_COMMAND2
415   cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_COMMAND2 is defined.");
416 #else
417   cmPassed("SHOULD_NOT_BE_DEFINED_COMMAND2 is not defined.");
418 #endif
419
420 #ifndef SHOULD_BE_DEFINED_COMMAND2
421   cmFailed(
422     "IF or SET is broken, SHOULD_BE_DEFINED_COMMAND2 is not defined.\n");
423 #else
424   cmPassed("SHOULD_BE_DEFINED_COMMAND2 is defined.");
425 #endif
426
427 #ifdef SHOULD_NOT_BE_DEFINED_EXISTS
428   cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_EXISTS is defined.");
429 #else
430   cmPassed("SHOULD_NOT_BE_DEFINED_EXISTS is not defined.");
431 #endif
432
433 #ifndef SHOULD_BE_DEFINED_EXISTS
434   cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_EXISTS is not defined.\n");
435 #else
436   cmPassed("SHOULD_BE_DEFINED_EXISTS is defined.");
437 #endif
438
439 #ifdef SHOULD_NOT_BE_DEFINED_EXISTS2
440   cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_EXISTS2 is defined.");
441 #else
442   cmPassed("SHOULD_NOT_BE_DEFINED_EXISTS2 is not defined.");
443 #endif
444
445 #ifndef SHOULD_BE_DEFINED_EXISTS2
446   cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_EXISTS2 is not defined.\n");
447 #else
448   cmPassed("SHOULD_BE_DEFINED_EXISTS2 is defined.");
449 #endif
450
451 #ifndef SHOULD_BE_DEFINED_IS_DIRECTORY
452   cmFailed(
453     "IF or SET is broken, SHOULD_BE_DEFINED_IS_DIRECTORY is not defined.\n");
454 #else
455   cmPassed("SHOULD_BE_DEFINED_IS_DIRECTORY is defined.");
456 #endif
457
458 #ifndef SHOULD_BE_DEFINED_IS_DIRECTORY2
459   cmFailed(
460     "IF or SET is broken, SHOULD_BE_DEFINED_IS_DIRECTORY2 is not defined.\n");
461 #else
462   cmPassed("SHOULD_BE_DEFINED_IS_DIRECTORY2 is defined.");
463 #endif
464
465 #ifdef SHOULD_NOT_BE_DEFINED_LESS
466   cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_LESS is defined.");
467 #else
468   cmPassed("SHOULD_NOT_BE_DEFINED_LESS is not defined.");
469 #endif
470
471 #ifndef SHOULD_BE_DEFINED_LESS
472   cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_LESS is not defined.\n");
473 #else
474   cmPassed("SHOULD_BE_DEFINED_LESS is defined.");
475 #endif
476
477 #ifdef SHOULD_NOT_BE_DEFINED_LESS2
478   cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_LESS2 is defined.");
479 #else
480   cmPassed("SHOULD_NOT_BE_DEFINED_LESS2 is not defined.");
481 #endif
482
483 #ifndef SHOULD_BE_DEFINED_LESS2
484   cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_LESS2 is not defined.\n");
485 #else
486   cmPassed("SHOULD_BE_DEFINED_LESS2 is defined.");
487 #endif
488
489 #ifdef SHOULD_NOT_BE_DEFINED_GREATER
490   cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_GREATER is defined.");
491 #else
492   cmPassed("SHOULD_NOT_BE_DEFINED_GREATER is not defined.");
493 #endif
494
495 #ifndef SHOULD_BE_DEFINED_GREATER
496   cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_GREATER is not defined.\n");
497 #else
498   cmPassed("SHOULD_BE_DEFINED_GREATER is defined.");
499 #endif
500
501 #ifdef SHOULD_NOT_BE_DEFINED_GREATER2
502   cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_GREATER2 is defined.");
503 #else
504   cmPassed("SHOULD_NOT_BE_DEFINED_GREATER2 is not defined.");
505 #endif
506
507 #ifndef SHOULD_BE_DEFINED_GREATER2
508   cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_GREATER2 is not defined.");
509 #else
510   cmPassed("SHOULD_BE_DEFINED_GREATER2 is defined.");
511 #endif
512
513 #ifdef SHOULD_NOT_BE_DEFINED_EQUAL
514   cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_EQUAL is defined.");
515 #else
516   cmPassed("SHOULD_NOT_BE_DEFINED_EQUAL is not defined.");
517 #endif
518
519 #ifndef SHOULD_BE_DEFINED_EQUAL
520   cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_EQUAL is not defined.\n");
521 #else
522   cmPassed("SHOULD_BE_DEFINED_EQUAL is defined.");
523 #endif
524
525 #ifdef SHOULD_NOT_BE_DEFINED_LESS_EQUAL
526   cmFailed(
527     "IF or SET is broken, SHOULD_NOT_BE_DEFINED_LESS_EQUAL is defined.");
528 #else
529   cmPassed("SHOULD_NOT_BE_DEFINED_LESS_EQUAL is not defined.");
530 #endif
531
532 #ifndef SHOULD_BE_DEFINED_LESS_EQUAL
533   cmFailed(
534     "IF or SET is broken, SHOULD_BE_DEFINED_LESS_EQUAL is not defined.");
535 #else
536   cmPassed("SHOULD_BE_DEFINED_LESS_EQUAL is defined.");
537 #endif
538
539 #ifdef SHOULD_NOT_BE_DEFINED_LESS_EQUAL2
540   cmFailed(
541     "IF or SET is broken, SHOULD_NOT_BE_DEFINED_LESS_EQUAL2 is defined.");
542 #else
543   cmPassed("SHOULD_NOT_BE_DEFINED_LESS_EQUAL2 is not defined.");
544 #endif
545
546 #ifndef SHOULD_BE_DEFINED_LESS_EQUAL2
547   cmFailed(
548     "IF or SET is broken, SHOULD_BE_DEFINED_LESS_EQUAL2 is not defined.");
549 #else
550   cmPassed("SHOULD_BE_DEFINED_LESS_EQUAL2 is defined.");
551 #endif
552
553 #ifdef SHOULD_NOT_BE_DEFINED_LESS_EQUAL3
554   cmFailed(
555     "IF or SET is broken, SHOULD_NOT_BE_DEFINED_LESS_EQUAL3 is defined.");
556 #else
557   cmPassed("SHOULD_NOT_BE_DEFINED_LESS_EQUAL3 is not defined.");
558 #endif
559
560 #ifndef SHOULD_BE_DEFINED_LESS_EQUAL3
561   cmFailed(
562     "IF or SET is broken, SHOULD_BE_DEFINED_LESS_EQUAL3 is not defined.");
563 #else
564   cmPassed("SHOULD_BE_DEFINED_LESS_EQUAL3 is defined.");
565 #endif
566
567 #ifdef SHOULD_NOT_BE_DEFINED_GREATER_EQUAL
568   cmFailed(
569     "IF or SET is broken, SHOULD_NOT_BE_DEFINED_GREATER_EQUAL is defined.");
570 #else
571   cmPassed("SHOULD_NOT_BE_DEFINED_GREATER_EQUAL is not defined.");
572 #endif
573
574 #ifndef SHOULD_BE_DEFINED_GREATER_EQUAL
575   cmFailed(
576     "IF or SET is broken, SHOULD_BE_DEFINED_GREATER_EQUAL is not defined.");
577 #else
578   cmPassed("SHOULD_BE_DEFINED_GREATER_EQUAL is defined.");
579 #endif
580
581 #ifdef SHOULD_NOT_BE_DEFINED_GREATER_EQUAL2
582   cmFailed(
583     "IF or SET is broken, SHOULD_NOT_BE_DEFINED_GREATER_EQUAL2 is defined.");
584 #else
585   cmPassed("SHOULD_NOT_BE_DEFINED_GREATER_EQUAL2 is not defined.");
586 #endif
587
588 #ifndef SHOULD_BE_DEFINED_GREATER_EQUAL2
589   cmFailed(
590     "IF or SET is broken, SHOULD_BE_DEFINED_GREATER_EQUAL2 is not defined.");
591 #else
592   cmPassed("SHOULD_BE_DEFINED_GREATER_EQUAL2 is defined.");
593 #endif
594
595 #ifdef SHOULD_NOT_BE_DEFINED_GREATER_EQUAL3
596   cmFailed(
597     "IF or SET is broken, SHOULD_NOT_BE_DEFINED_GREATER_EQUAL3 is defined.");
598 #else
599   cmPassed("SHOULD_NOT_BE_DEFINED_GREATER_EQUAL3 is not defined.");
600 #endif
601
602 #ifndef SHOULD_BE_DEFINED_GREATER_EQUAL3
603   cmFailed(
604     "IF or SET is broken, SHOULD_BE_DEFINED_GREATER_EQUAL3 is not defined.");
605 #else
606   cmPassed("SHOULD_BE_DEFINED_GREATER_EQUAL3 is defined.");
607 #endif
608
609 #ifdef SHOULD_NOT_BE_DEFINED_STRLESS
610   cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRLESS is defined.");
611 #else
612   cmPassed("SHOULD_NOT_BE_DEFINED_STRLESS is not defined.");
613 #endif
614
615 #ifndef SHOULD_BE_DEFINED_STRLESS
616   cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRLESS is not defined.");
617 #else
618   cmPassed("SHOULD_BE_DEFINED_STRLESS is defined.");
619 #endif
620
621 #ifdef SHOULD_NOT_BE_DEFINED_STRLESS2
622   cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRLESS2 is defined.");
623 #else
624   cmPassed("SHOULD_NOT_BE_DEFINED_STRLESS2 is not defined.");
625 #endif
626
627 #ifndef SHOULD_BE_DEFINED_STRLESS2
628   cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRLESS2 is not defined.");
629 #else
630   cmPassed("SHOULD_BE_DEFINED_STRLESS2 is defined.");
631 #endif
632
633 #ifdef SHOULD_NOT_BE_DEFINED_STRGREATER
634   cmFailed(
635     "IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRGREATER is defined.");
636 #else
637   cmPassed("SHOULD_NOT_BE_DEFINED_STRGREATER is not defined.");
638 #endif
639
640 #ifndef SHOULD_BE_DEFINED_STRGREATER
641   cmFailed(
642     "IF or SET is broken, SHOULD_BE_DEFINED_STRGREATER is not defined.");
643 #else
644   cmPassed("SHOULD_BE_DEFINED_STRGREATER is defined.");
645 #endif
646
647 #ifdef SHOULD_NOT_BE_DEFINED_STRGREATER2
648   cmFailed(
649     "IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRGREATER2 is defined.");
650 #else
651   cmPassed("SHOULD_NOT_BE_DEFINED_STRGREATER2 is not defined.");
652 #endif
653
654 #ifndef SHOULD_BE_DEFINED_STRGREATER2
655   cmFailed(
656     "IF or SET is broken, SHOULD_BE_DEFINED_STRGREATER2 is not defined.");
657 #else
658   cmPassed("SHOULD_BE_DEFINED_STRGREATER2 is defined.");
659 #endif
660
661 #ifdef SHOULD_NOT_BE_DEFINED_STRLESS_EQUAL
662   cmFailed(
663     "IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRLESS_EQUAL is defined.");
664 #else
665   cmPassed("SHOULD_NOT_BE_DEFINED_STRLESS_EQUAL is not defined.");
666 #endif
667
668 #ifndef SHOULD_BE_DEFINED_STRLESS_EQUAL
669   cmFailed(
670     "IF or SET is broken, SHOULD_BE_DEFINED_STRLESS_EQUAL is not defined.");
671 #else
672   cmPassed("SHOULD_BE_DEFINED_STRLESS_EQUAL is defined.");
673 #endif
674
675 #ifdef SHOULD_NOT_BE_DEFINED_STRLESS_EQUAL2
676   cmFailed(
677     "IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRLESS_EQUAL2 is defined.");
678 #else
679   cmPassed("SHOULD_NOT_BE_DEFINED_STRLESS_EQUAL2 is not defined.");
680 #endif
681
682 #ifndef SHOULD_BE_DEFINED_STRLESS_EQUAL2
683   cmFailed(
684     "IF or SET is broken, SHOULD_BE_DEFINED_STRLESS_EQUAL2 is not defined.");
685 #else
686   cmPassed("SHOULD_BE_DEFINED_STRLESS_EQUAL2 is defined.");
687 #endif
688
689 #ifdef SHOULD_NOT_BE_DEFINED_STRLESS_EQUAL3
690   cmFailed(
691     "IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRLESS_EQUAL3 is defined.");
692 #else
693   cmPassed("SHOULD_NOT_BE_DEFINED_STRLESS_EQUAL3 is not defined.");
694 #endif
695
696 #ifndef SHOULD_BE_DEFINED_STRLESS_EQUAL3
697   cmFailed(
698     "IF or SET is broken, SHOULD_BE_DEFINED_STRLESS_EQUAL3 is not defined.");
699 #else
700   cmPassed("SHOULD_BE_DEFINED_STRLESS_EQUAL3 is defined.");
701 #endif
702
703 #ifdef SHOULD_NOT_BE_DEFINED_STRGREATER_EQUAL
704   cmFailed(
705     "IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRGREATER_EQUAL is defined.");
706 #else
707   cmPassed("SHOULD_NOT_BE_DEFINED_STRGREATER_EQUAL is not defined.");
708 #endif
709
710 #ifndef SHOULD_BE_DEFINED_STRGREATER_EQUAL
711   cmFailed(
712     "IF or SET is broken, SHOULD_BE_DEFINED_STRGREATER_EQUAL is not defined.");
713 #else
714   cmPassed("SHOULD_BE_DEFINED_STRGREATER_EQUAL is defined.");
715 #endif
716
717 #ifdef SHOULD_NOT_BE_DEFINED_STRGREATER_EQUAL2
718   cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRGREATER_EQUAL2 is "
719            "defined.");
720 #else
721   cmPassed("SHOULD_NOT_BE_DEFINED_STRGREATER_EQUAL2 is not defined.");
722 #endif
723
724 #ifndef SHOULD_BE_DEFINED_STRGREATER_EQUAL2
725   cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRGREATER_EQUAL2 is not "
726            "defined.");
727 #else
728   cmPassed("SHOULD_BE_DEFINED_STRGREATER_EQUAL2 is defined.");
729 #endif
730
731 #ifdef SHOULD_NOT_BE_DEFINED_STRGREATER_EQUAL3
732   cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRGREATER_EQUAL3 is "
733            "defined.");
734 #else
735   cmPassed("SHOULD_NOT_BE_DEFINED_STRGREATER_EQUAL3 is not defined.");
736 #endif
737
738 #ifndef SHOULD_BE_DEFINED_STRGREATER_EQUAL3
739   cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRGREATER_EQUAL3 is not "
740            "defined.");
741 #else
742   cmPassed("SHOULD_BE_DEFINED_STRGREATER_EQUAL3 is defined.");
743 #endif
744
745   // ----------------------------------------------------------------------
746   // Test FOREACH
747
748 #ifndef FOREACH_VAR1
749   cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
750            "FOREACH_VAR1 is not defined.");
751 #else
752   if (strcmp(FOREACH_VAR1, "VALUE1") != 0) {
753     cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
754              "FOREACH_VAR1 == ",
755              FOREACH_VAR1);
756   } else {
757     cmPassed("FOREACH_VAR1 == ", FOREACH_VAR1);
758   }
759 #endif
760
761 #ifndef FOREACH_VAR2
762   cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
763            "FOREACH_VAR2 is not defined.");
764 #else
765   if (strcmp(FOREACH_VAR2, "VALUE2") != 0) {
766     cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
767              "FOREACH_VAR2 == ",
768              FOREACH_VAR2);
769   } else {
770     cmPassed("FOREACH_VAR2 == ", FOREACH_VAR2);
771   }
772 #endif
773
774 #ifndef FOREACH_CONCAT
775   cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
776            "FOREACH_CONCAT is not defined.");
777 #else
778   if (strcmp(FOREACH_CONCAT, "abcdefg") != 0) {
779     cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
780              "FOREACH_CONCAT == ",
781              FOREACH_CONCAT);
782   } else {
783     cmPassed("FOREACH_CONCAT == ", FOREACH_CONCAT);
784   }
785 #endif
786
787   // ----------------------------------------------------------------------
788   // Test WHILE
789
790   if (WHILE_VALUE != 1000) {
791     cmFailed("WHILE command is not working");
792   } else {
793     cmPassed("WHILE command is working");
794   }
795
796   // ----------------------------------------------------------------------
797   // Test LOAD_CACHE
798
799 #ifndef CACHE_TEST_VAR1
800   cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
801            "CACHE_TEST_VAR1 is not defined.");
802 #else
803   if (strcmp(CACHE_TEST_VAR1, "foo") != 0) {
804     cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
805              "CACHE_TEST_VAR1 == ",
806              CACHE_TEST_VAR1);
807   } else {
808     cmPassed("CACHE_TEST_VAR1 == ", CACHE_TEST_VAR1);
809   }
810 #endif
811
812 #ifndef CACHE_TEST_VAR2
813   cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
814            "CACHE_TEST_VAR2 is not defined.");
815 #else
816   if (strcmp(CACHE_TEST_VAR2, "bar") != 0) {
817     cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
818              "CACHE_TEST_VAR2 == ",
819              CACHE_TEST_VAR2);
820   } else {
821     cmPassed("CACHE_TEST_VAR2 == ", CACHE_TEST_VAR2);
822   }
823 #endif
824
825 #ifndef CACHE_TEST_VAR3
826   cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
827            "CACHE_TEST_VAR3 is not defined.");
828 #else
829   if (strcmp(CACHE_TEST_VAR3, "1") != 0) {
830     cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
831              "CACHE_TEST_VAR3 == ",
832              CACHE_TEST_VAR3);
833   } else {
834     cmPassed("CACHE_TEST_VAR3 == ", CACHE_TEST_VAR3);
835   }
836 #endif
837
838 #ifdef CACHE_TEST_VAR_EXCLUDED
839   cmFailed(
840     "the LOAD_CACHE or CONFIGURE_FILE command or cmakedefine is broken, "
841     "CACHE_TEST_VAR_EXCLUDED is defined (should not have been loaded).");
842 #else
843   cmPassed("CACHE_TEST_VAR_EXCLUDED is not defined.");
844 #endif
845
846 #ifndef CACHE_TEST_VAR_INTERNAL
847   cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
848            "CACHE_TEST_VAR_INTERNAL is not defined.");
849 #else
850   std::string cachetest = CACHE_TEST_VAR_INTERNAL;
851   if (cachetest != "bar") {
852     cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
853              "CACHE_TEST_VAR_INTERNAL == ",
854              CACHE_TEST_VAR_INTERNAL);
855   } else {
856     cmPassed("CACHE_TEST_VAR_INTERNAL == ", CACHE_TEST_VAR_INTERNAL);
857   }
858 #endif
859
860   // ----------------------------------------------------------------------
861   // Some pre-build/pre-link/post-build custom-commands have been
862   // attached to the lib (see Library/).
863   // Each runs ${CREATE_FILE_EXE} which will create a file.
864   // It also copies that file again using cmake -E.
865   // Similar rules have been added to this executable.
866   //
867   // WARNING: if you run 'complex' manually, this *will* fail, because
868   // the file was removed the last time 'complex' was run, and it is
869   // only created during a build.
870
871   TestAndRemoveFile("Library/prebuild.txt");
872   TestAndRemoveFile("Library/prelink.txt");
873   TestAndRemoveFile("Library/postbuild.txt");
874   TestAndRemoveFile("Library/postbuild2.txt");
875   TestAndRemoveFile("Executable/prebuild.txt");
876   TestAndRemoveFile("Executable/prelink.txt");
877   TestAndRemoveFile("Executable/postbuild.txt");
878   TestAndRemoveFile("Executable/postbuild2.txt");
879
880   // ----------------------------------------------------------------------
881   // A custom target has been created (see Library/).
882   // It runs ${CREATE_FILE_EXE} which will create a file.
883   //
884   // WARNING: if you run 'complex' manually, this *will* fail, because
885   // the file was removed the last time 'complex' was run, and it is
886   // only created during a build.
887
888   TestAndRemoveFile("Library/custom_target1.txt");
889
890   // ----------------------------------------------------------------------
891   // A directory has been created.
892
893   TestDir("make_dir");
894
895   // ----------------------------------------------------------------------
896   // Test OUTPUT_REQUIRED_FILES
897   // The files required by 'complex' have been output to a file.
898   // The contents of this file is not tested (absolute paths).
899   //
900   // WARNING: if you run 'complex' manually, this *will* fail, because
901   // the file was removed the last time 'complex' was run, and it is
902   // only created during a build.
903
904   TestAndRemoveFile("Executable/Temp/complex-required.txt");
905
906   // ----------------------------------------------------------------------
907   // Test FIND_LIBRARY
908
909 #ifndef FIND_DUMMY_LIB
910   cmFailed("the CONFIGURE_FILE command is broken, "
911            "FIND_DUMMY_LIB is not defined.");
912 #else
913   if (strstr(FIND_DUMMY_LIB, "dummylib") == NULL) {
914     cmFailed("the FIND_LIBRARY or CONFIGURE_FILE command is broken, "
915              "FIND_DUMMY_LIB == ",
916              FIND_DUMMY_LIB);
917   } else {
918     cmPassed("FIND_DUMMY_LIB == ", FIND_DUMMY_LIB);
919   }
920 #endif
921
922   // ----------------------------------------------------------------------
923   // Test SET_SOURCE_FILES_PROPERTIES
924
925 #ifndef FILE_HAS_EXTRA_COMPILE_FLAGS
926   cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting "
927            "FILE_HAS_EXTRA_COMPILE_FLAGS flag");
928 #else
929   cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting "
930            "FILE_HAS_EXTRA_COMPILE_FLAGS flag");
931 #endif
932
933 #if 0 // Disable until implemented everywhere.
934 #  ifndef FILE_DEFINE_STRING
935   cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting FILE_DEFINE_STRING flag");
936 #  else
937   if(strcmp(FILE_DEFINE_STRING, "hello") != 0)
938     {
939     cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting FILE_DEFINE_STRING flag correctly");
940     }
941   else
942     {
943     cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting FILE_DEFINE_STRING flag");
944     }
945 #  endif
946 #endif
947
948 #ifndef FILE_HAS_ABSTRACT
949   cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting ABSTRACT flag");
950 #else
951   cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting ABSTRACT flag");
952 #endif
953
954 #ifndef FILE_HAS_WRAP_EXCLUDE
955   cmFailed("FILE_HAS_WRAP_EXCLUDE failed at setting WRAP_EXCLUDE flag");
956 #else
957   cmPassed("FILE_HAS_WRAP_EXCLUDE succeeded in setting WRAP_EXCLUDE flag");
958 #endif
959
960 #ifndef FILE_COMPILE_FLAGS
961   cmFailed("the CONFIGURE_FILE command is broken, FILE_COMPILE_FLAGS is not "
962            "defined.");
963 #else
964   if (strcmp(FILE_COMPILE_FLAGS, "-foo -bar") != 0) {
965     cmFailed("the SET_SOURCE_FILES_PROPERTIES or CONFIGURE_FILE command is "
966              "broken. FILE_COMPILE_FLAGS == ",
967              FILE_COMPILE_FLAGS);
968   } else {
969     cmPassed(
970       "SET_SOURCE_FILES_PROPERTIES succeeded in setting extra flags == ",
971       FILE_COMPILE_FLAGS);
972   }
973 #endif
974
975 // ----------------------------------------------------------------------
976 // Test registry (win32)
977 #if defined(_WIN32) && !defined(__CYGWIN__)
978 #  ifndef REGISTRY_TEST_PATH
979   cmFailed("the CONFIGURE_FILE command is broken, REGISTRY_TEST_PATH is not "
980            "defined.");
981 #  else
982   std::cout << "REGISTRY_TEST_PATH == " << REGISTRY_TEST_PATH << "\n";
983   if (stricmp(REGISTRY_TEST_PATH, BINARY_DIR "/registry_dir") != 0) {
984     cmFailed("the 'read registry value' function or CONFIGURE_FILE command is "
985              "broken. REGISTRY_TEST_PATH == ",
986              REGISTRY_TEST_PATH, " is not " BINARY_DIR "/registry_dir");
987   } else {
988     cmPassed("REGISTRY_TEST_PATH == ", REGISTRY_TEST_PATH);
989   }
990 #  endif
991 #endif // defined(_WIN32) && !defined(__CYGWIN__)
992
993   if (strcmp(CMAKE_MINIMUM_REQUIRED_VERSION, "2.4") == 0) {
994     cmPassed("CMAKE_MINIMUM_REQUIRED_VERSION is set to 2.4");
995   } else {
996     cmFailed("CMAKE_MINIMUM_REQUIRED_VERSION is not set to the expected 2.4");
997   }
998
999   // ----------------------------------------------------------------------
1000   // Test REMOVE command
1001   if (strcmp("a;b;d", REMOVE_STRING) == 0) {
1002     cmPassed("REMOVE is working");
1003   } else {
1004     cmFailed("REMOVE is not working");
1005   }
1006
1007   // ----------------------------------------------------------------------
1008   // Test SEPARATE_ARGUMENTS
1009   if (strcmp("a;b;c", TEST_SEP) == 0) {
1010     cmPassed("SEPARATE_ARGUMENTS is working");
1011   } else {
1012     cmFailed("SEPARATE_ARGUMENTS is not working");
1013   }
1014
1015   // ----------------------------------------------------------------------
1016   // Test Escape Quotes
1017   if (strcmp("\"hello world\"", STRING_WITH_QUOTES) == 0) {
1018     cmPassed("ESCAPE_QUOTES is working");
1019   } else {
1020     cmFailed("ESCAPE_QUOTES is not working");
1021   }
1022
1023 // ----------------------------------------------------------------------
1024 // Test if IF command inside a FOREACH works.
1025 #if defined(IF_INSIDE_FOREACH_THEN_EXECUTED) &&                               \
1026   !defined(IF_INSIDE_FOREACH_ELSE_EXECUTED)
1027   cmPassed("IF inside a FOREACH block works");
1028 #else
1029   cmFailed("IF inside a FOREACH block is broken");
1030 #endif
1031
1032 #if defined(GENERATED_HEADER_INCLUDED)
1033   cmPassed("Generated header included by non-generated source works.");
1034 #else
1035   cmFailed("Generated header included by non-generated source failed.");
1036 #endif
1037   if (SHOULD_BE_ZERO == 0) {
1038     cmPassed("cmakedefine01 is working for 0");
1039   } else {
1040     cmFailed("cmakedefine01 is not working for 0");
1041   }
1042   if (SHOULD_BE_ONE == 1) {
1043     cmPassed("cmakedefine01 is working for 1");
1044   } else {
1045     cmFailed("cmakedefine01 is not working for 1");
1046   }
1047   if (SHOULD_BE_ZERO_AND_INDENTED == 0) {
1048     cmPassed("cmakedefine01 is working for 0 and indented");
1049   } else {
1050     cmFailed("cmakedefine01 is not working for 0 and indented");
1051   }
1052   if (SHOULD_BE_ONE_AND_INDENTED == 1) {
1053     cmPassed("cmakedefine01 is working for 1 and indented");
1054   } else {
1055     cmFailed("cmakedefine01 is not working for 1 and indented");
1056   }
1057 #ifdef FORCE_TEST
1058   cmFailed("CMake SET CACHE FORCE");
1059 #else
1060   cmPassed("CMake SET CACHE FORCE");
1061 #endif
1062
1063 #ifdef COMPLEX_TEST_LINK_STATIC
1064   if (TestLinkGetType()) {
1065     cmPassed("Link to static over shared worked.");
1066   } else {
1067     cmFailed("Link to static over shared failed.");
1068   }
1069 #endif
1070
1071 #if defined(A_VALUE) && A_VALUE == 10
1072   cmPassed("Single-character executable A worked.");
1073 #else
1074   cmFailed("Single-character executable A failed.");
1075 #endif
1076
1077   // ----------------------------------------------------------------------
1078   // Summary
1079
1080   std::cout << "Passed: " << cm_passed << "\n";
1081   if (cm_failed) {
1082     std::cout << "Failed: " << cm_failed << "\n";
1083     return cm_failed;
1084   }
1085   return 0;
1086 }