Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Tests / ComplexOneConfig / Executable / complex.cxx
blob0ecd8fe2ee804a7e113a9618159908606226d7cd
1 #include "cmTestConfigure.h"
2 #include "cmTestConfigureEscape.h"
3 #include "cmTestGeneratedHeader.h"
4 #include "cmVersion.h"
5 #include "ExtraSources/file1.h"
6 #include "file2.h"
7 #include "sharedFile.h"
8 extern "C" {
9 #include "testConly.h"
11 #ifdef COMPLEX_TEST_CMAKELIB
12 #include "cmStandardIncludes.h"
13 #include "cmSystemTools.h"
14 #include "cmDynamicLoader.h"
15 #include "cmSystemTools.h"
16 #include "cmGeneratedFileStream.h"
17 #include <cmsys/DynamicLoader.hxx>
18 #else
19 #include <vector>
20 #include <string>
21 #include <iostream>
22 #include <string.h>
23 #endif
25 #ifdef COMPLEX_TEST_LINK_STATIC
26 extern "C"
28 int TestLinkGetType();
30 #endif
32 int cm_passed = 0;
33 int cm_failed = 0;
34 // ======================================================================
36 void cmFailed(const char* Message, const char* m2= "", const char* m3 = "")
38 std::cout << "FAILED: " << Message << m2 << m3 << "\n";
39 cm_failed++;
42 // ======================================================================
44 void cmPassed(const char* Message, const char* m2="")
46 std::cout << "Passed: " << Message << m2 << "\n";
47 cm_passed++;
50 #ifndef COMPLEX_DEFINED_PRE
51 # error "COMPLEX_DEFINED_PRE not defined!"
52 #endif
54 #ifdef COMPLEX_DEFINED
55 # error "COMPLEX_DEFINED is defined but it should not!"
56 #endif
58 #ifndef COMPLEX_DEFINED_POST
59 # error "COMPLEX_DEFINED_POST not defined!"
60 #endif
62 #ifndef CMAKE_IS_REALLY_FUN
63 # error This is a problem. Looks like ADD_DEFINITIONS and REMOVE_DEFINITIONS does not work
64 #endif
66 #if defined(NDEBUG) && !defined(CMAKE_IS_FUN_IN_RELEASE_MODE)
67 # error Per-configuration directory-level definition not inherited.
68 #endif
70 #ifdef COMPLEX_TEST_CMAKELIB
71 // ======================================================================
73 void TestAndRemoveFile(const char* filename)
75 if (!cmSystemTools::FileExists(filename))
77 cmFailed("Could not find file: ", filename);
79 else
81 if (!cmSystemTools::RemoveFile(filename))
83 cmFailed("Unable to remove file. It does not imply that this test failed, but it *will* be corrupted thereafter if this file is not removed: ", filename);
85 else
87 cmPassed("Find and remove file: ", filename);
92 // ======================================================================
94 void TestDir(const char* filename)
96 if (!cmSystemTools::FileExists(filename))
98 cmFailed("Could not find dir: ", filename);
100 else
102 if (!cmSystemTools::FileIsDirectory(filename))
104 cmFailed("Unable to check if file is a directory: ", filename);
106 else
108 cmPassed("Find dir: ", filename);
113 // ======================================================================
115 void TestCMGeneratedFileSTream()
117 cmGeneratedFileStream gm;
118 std::string file1 = std::string(BINARY_DIR) + std::string("/generatedFile1");
119 std::string file2 = std::string(BINARY_DIR) + std::string("/generatedFile2");
120 std::string file3 = std::string(BINARY_DIR) + std::string("/generatedFile3");
121 std::string file4 = std::string(BINARY_DIR) + std::string("/generatedFile4");
122 std::string file1tmp = file1 + ".tmp";
123 std::string file2tmp = file2 + ".tmp";
124 std::string file3tmp = file3 + ".tmp";
125 std::string file4tmp = file4 + ".tmp";
126 gm.Open(file1.c_str());
127 gm << "This is generated file 1";
128 gm.Close();
129 gm.Open(file2.c_str());
130 gm << "This is generated file 2";
131 gm.Close();
132 gm.Open(file3.c_str());
133 gm << "This is generated file 3";
134 gm.Close();
135 gm.Open(file4.c_str());
136 gm << "This is generated file 4";
137 gm.Close();
138 if ( cmSystemTools::FileExists(file1.c_str()) )
140 if ( cmSystemTools::FileExists(file2.c_str()) )
142 if ( cmSystemTools::FileExists(file3.c_str()) )
144 if ( cmSystemTools::FileExists(file4.c_str()) )
146 if ( cmSystemTools::FileExists(file1tmp.c_str()) )
148 cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file1tmp.c_str());
150 else if ( cmSystemTools::FileExists(file2tmp.c_str()) )
152 cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file2tmp.c_str());
154 else if ( cmSystemTools::FileExists(file3tmp.c_str()) )
156 cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file3tmp.c_str());
158 else if ( cmSystemTools::FileExists(file4tmp.c_str()) )
160 cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file4tmp.c_str());
162 else
164 cmPassed("cmGeneratedFileStream works.");
167 else
169 cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", file4.c_str());
172 else
174 cmFailed("Something wrong with cmGeneratedFileStream. Found file: ", file3.c_str());
177 else
179 cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", file2.c_str());
182 else
184 cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", file1.c_str());
186 cmSystemTools::RemoveFile(file1.c_str());
187 cmSystemTools::RemoveFile(file2.c_str());
188 cmSystemTools::RemoveFile(file3.c_str());
189 cmSystemTools::RemoveFile(file1tmp.c_str());
190 cmSystemTools::RemoveFile(file2tmp.c_str());
191 cmSystemTools::RemoveFile(file3tmp.c_str());
193 #endif
195 // Here is a stupid function that tries to use std::string methods
196 // so that the dec cxx compiler will instantiate the stuff that
197 // we are using from the CMakeLib library....
198 void ForceStringUse()
200 std::vector<std::string> v;
201 std::vector<std::string> v2;
202 v = v2;
203 std::string cachetest = CACHE_TEST_VAR_INTERNAL;
204 v.push_back(cachetest);
205 v2 = v;
206 std::string x(5,'x');
207 char buff[5];
208 x.copy(buff, 1, 0);
209 x[0] = 'a';
210 std::string::size_type pos = 0;
211 x.replace(pos, pos, pos, 'x');
212 std::string copy = cachetest;
213 cachetest.find("bar");
214 cachetest.rfind("bar");
215 copy.append(cachetest);
216 copy = cachetest.substr(0, cachetest.size());
220 // defined in testcflags.c
221 extern "C" int TestCFlags(char* m);
222 extern "C" int TestTargetCompileFlags(char* m);
224 #if 0
225 // defined in Sub1/NameConflictTest.c
226 extern "C" int NameConflictTest1();
227 // defined in Sub2/NameConflictTest.c
228 extern "C" int NameConflictTest2();
229 #endif
231 // ======================================================================
233 int main()
235 std::string lib = BINARY_DIR;
236 lib += "/lib/";
237 #ifdef CMAKE_INTDIR
238 lib += CMAKE_INTDIR;
239 lib += "/";
240 #endif
241 std::string exe = BINARY_DIR;
242 exe += "/bin/";
243 #ifdef CMAKE_INTDIR
244 exe += CMAKE_INTDIR;
245 exe += "/";
246 #endif
248 #ifdef COMPLEX_TEST_CMAKELIB
249 // Test a single character executable to test a: in makefiles
250 exe += "A";
251 exe += cmSystemTools::GetExecutableExtension();
252 int ret;
253 std::string errorMessage;
254 exe = cmSystemTools::ConvertToRunCommandPath(exe.c_str());
255 if(cmSystemTools::RunSingleCommand(exe.c_str(), 0, &ret))
257 if(ret != 10)
259 errorMessage += exe;
260 errorMessage += " did not return 10";
263 else
265 errorMessage += exe;
266 errorMessage += ": failed to run.";
268 if(errorMessage.size())
270 cmFailed(errorMessage.c_str());
272 else
274 cmPassed("run Single Character executable A returned 10 as expected.");
277 lib += CMAKE_SHARED_MODULE_PREFIX;
278 lib += "CMakeTestModule";
279 lib += CMAKE_SHARED_MODULE_SUFFIX;
280 cmsys::DynamicLoader::LibraryHandle handle = cmDynamicLoader::OpenLibrary(lib.c_str());
281 if(!handle)
283 std::string err = "Can not open CMakeTestModule:\n";
284 err += lib;
285 cmFailed(err.c_str());
287 else
289 cmsys::DynamicLoader::SymbolPointer fun =
290 cmsys::DynamicLoader::GetSymbolAddress(handle, "ModuleFunction");
291 if(!fun)
293 fun = cmsys::DynamicLoader::GetSymbolAddress(handle, "_ModuleFunction");
295 typedef int (*TEST_FUNCTION)();
296 TEST_FUNCTION testFun = (TEST_FUNCTION)fun;
297 if(!testFun)
299 cmFailed("Could not find symbol ModuleFunction in library ");
301 else
303 int ret = (*testFun)();
304 if(!ret)
306 cmFailed("ModuleFunction call did not return valid return.");
308 cmPassed("Module loaded and ModuleFunction called correctly.");
311 cmDynamicLoader::FlushCache(); // fix memory leaks
312 if(sharedFunction() != 1)
314 cmFailed("Call to sharedFunction from shared library failed.");
316 else
318 cmPassed("Call to sharedFunction from shared library worked.");
320 if(CsharedFunction() != 1)
322 cmFailed("Call to C sharedFunction from shared library failed.");
324 else
326 cmPassed("Call to C sharedFunction from shared library worked.");
329 // ----------------------------------------------------------------------
330 // Test cmSystemTools::UpperCase
331 std::string str = "abc";
332 std::string strupper = "ABC";
333 if(cmSystemTools::UpperCase(str) == strupper)
335 cmPassed("cmSystemTools::UpperCase is working");
337 else
339 cmFailed("cmSystemTools::UpperCase is working");
341 #endif
342 #if 0
343 if(NameConflictTest1() == 0 && NameConflictTest2() == 0)
345 cmPassed("Sub dir with same named source works");
347 else
349 cmFailed("Sub dir with same named source fails");
351 #endif
352 if(file1() != 1)
354 cmFailed("Call to file1 function from library failed.");
356 else
358 cmPassed("Call to file1 function returned 1.");
360 #ifndef COMPLEX_TARGET_FLAG
361 cmFailed("COMPILE_FLAGS did not work with SET_TARGET_PROPERTIES");
362 #else
363 cmPassed("COMPILE_FLAGS did work with SET_TARGET_PROPERTIES");
364 #endif
366 #ifdef ELSEIF_RESULT
367 cmPassed("ELSEIF did work");
368 #else
369 cmFailed("ELSEIF did not work");
370 #endif
372 #ifdef CONDITIONAL_PARENTHESES
373 cmPassed("CONDITIONAL_PARENTHESES did work");
374 #else
375 cmFailed("CONDITIONAL_PARENTHESES did not work");
376 #endif
378 if(file2() != 1)
380 cmFailed("Call to file2 function from library failed.");
382 else
384 cmPassed("Call to file2 function returned 1.");
386 #ifndef TEST_CXX_FLAGS
387 cmFailed("CMake CMAKE_CXX_FLAGS is not being passed to the compiler!");
388 #else
389 cmPassed("CMake CMAKE_CXX_FLAGS is being passed to the compiler.");
390 #endif
391 std::string gen = CMAKE_GENERATOR;
392 // visual studio is currently broken for c flags
393 char msg[1024];
394 if(gen.find("Visual") == gen.npos)
396 #ifdef TEST_C_FLAGS
397 cmFailed("CMake CMAKE_C_FLAGS are being passed to c++ files the compiler!");
398 #else
399 cmPassed("CMake CMAKE_C_FLAGS are not being passed to c++ files.");
400 #endif
401 if(TestCFlags(msg))
403 cmPassed(
404 "CMake CMAKE_C_FLAGS are being passed to c files and CXX flags are not.");
406 else
408 cmFailed(msg);
411 if(TestTargetCompileFlags(msg))
413 cmPassed(msg);
415 else
417 cmFailed(msg);
420 // ----------------------------------------------------------------------
421 // Test ADD_DEFINITIONS
423 #ifndef CMAKE_IS_FUN
424 cmFailed("CMake is not fun, so it is broken and should be fixed.");
425 #else
426 cmPassed("CMAKE_IS_FUN is defined.");
427 #endif
429 #if defined(CMAKE_ARGV1) && defined(CMAKE_ARGV2) && defined(CMAKE_ARGV3) && defined(CMAKE_ARGV4)
430 cmPassed("Variable args for MACROs are working.");
431 #else
432 cmFailed("Variable args for MACROs are failing.");
433 #endif
435 // ----------------------------------------------------------------------
436 // Test GET_SOURCE_FILE_PROPERTY for location
437 #ifndef CMAKE_FOUND_ACXX
438 cmFailed("CMake did not get the location of A.cxx correctly");
439 #else
440 cmPassed("CMake found A.cxx properly");
441 #endif
443 // ----------------------------------------------------------------------
444 // Test GET_DIRECTORY_PROPERTY for parent
445 #ifndef CMAKE_FOUND_PARENT
446 cmFailed("CMake did not get the location of the parent directory properly");
447 #else
448 cmPassed("CMake found the parent directory properly");
449 #endif
451 // ----------------------------------------------------------------------
452 // Test GET_DIRECTORY_PROPERTY for listfiles
453 #ifndef CMAKE_FOUND_LISTFILE_STACK
454 cmFailed("CMake did not get the listfile stack properly");
455 #else
456 cmPassed("CMake found the listfile stack properly");
457 #endif
459 // ----------------------------------------------------------------------
460 // Test SET, VARIABLE_REQUIRES
462 #ifdef SHOULD_NOT_BE_DEFINED
463 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED is defined.");
464 #else
465 cmPassed("SHOULD_NOT_BE_DEFINED is not defined.");
466 #endif
468 #ifndef SHOULD_BE_DEFINED
469 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED is not defined.\n");
470 #else
471 cmPassed("SHOULD_BE_DEFINED is defined.");
472 #endif
474 #ifndef ONE_VAR
475 cmFailed("cmakedefine is broken, ONE_VAR is not defined.");
476 #else
477 cmPassed("ONE_VAR is defined.");
478 #endif
480 #ifndef ONE_VAR_IS_DEFINED
481 cmFailed("cmakedefine, SET or VARIABLE_REQUIRES is broken, "
482 "ONE_VAR_IS_DEFINED is not defined.");
483 #else
484 cmPassed("ONE_VAR_IS_DEFINED is defined.");
485 #endif
487 #ifdef ZERO_VAR
488 cmFailed("cmakedefine is broken, ZERO_VAR is defined.");
489 #else
490 cmPassed("ZERO_VAR is not defined.");
491 #endif
493 #ifndef STRING_VAR
494 cmFailed("the CONFIGURE_FILE command is broken, STRING_VAR is not defined.");
495 #else
496 if(strcmp(STRING_VAR, "CMake is great") != 0)
498 cmFailed("the SET or CONFIGURE_FILE command is broken. STRING_VAR == ",
499 STRING_VAR);
501 else
503 cmPassed("STRING_VAR == ", STRING_VAR);
505 #endif
507 // ----------------------------------------------------------------------
508 // Test various IF/ELSE combinations
510 #ifdef SHOULD_NOT_BE_DEFINED_NOT
511 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_NOT is defined.");
512 #else
513 cmPassed("SHOULD_NOT_BE_DEFINED_NOT is not defined.");
514 #endif
516 #ifndef SHOULD_BE_DEFINED_NOT
517 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_NOT is not defined.\n");
518 #else
519 cmPassed("SHOULD_BE_DEFINED_NOT is defined.");
520 #endif
522 #ifdef SHOULD_NOT_BE_DEFINED_NOT2
523 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_NOT2 is defined.");
524 #else
525 cmPassed("SHOULD_NOT_BE_DEFINED_NOT2 is not defined.");
526 #endif
528 #ifndef SHOULD_BE_DEFINED_NOT2
529 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_NOT2 is not defined.\n");
530 #else
531 cmPassed("SHOULD_BE_DEFINED_NOT2 is defined.");
532 #endif
534 #ifdef SHOULD_NOT_BE_DEFINED_AND
535 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_AND is defined.");
536 #else
537 cmPassed("SHOULD_NOT_BE_DEFINED_AND is not defined.");
538 #endif
540 #ifndef SHOULD_BE_DEFINED_AND
541 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_AND is not defined.\n");
542 #else
543 cmPassed("SHOULD_BE_DEFINED_AND is defined.");
544 #endif
546 #ifdef SHOULD_NOT_BE_DEFINED_AND2
547 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_AND2 is defined.");
548 #else
549 cmPassed("SHOULD_NOT_BE_DEFINED_AND2 is not defined.");
550 #endif
552 #ifndef SHOULD_BE_DEFINED_AND2
553 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_AND2 is not defined.\n");
554 #else
555 cmPassed("SHOULD_BE_DEFINED_AND2 is defined.");
556 #endif
558 #ifdef SHOULD_NOT_BE_DEFINED_OR
559 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_OR is defined.");
560 #else
561 cmPassed("SHOULD_NOT_BE_DEFINED_OR is not defined.");
562 #endif
564 #ifndef SHOULD_BE_DEFINED_OR
565 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_OR is not defined.\n");
566 #else
567 cmPassed("SHOULD_BE_DEFINED_OR is defined.");
568 #endif
570 #ifdef SHOULD_NOT_BE_DEFINED_OR2
571 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_OR2 is defined.");
572 #else
573 cmPassed("SHOULD_NOT_BE_DEFINED_OR2 is not defined.");
574 #endif
576 #ifndef SHOULD_BE_DEFINED_OR2
577 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_OR2 is not defined.\n");
578 #else
579 cmPassed("SHOULD_BE_DEFINED_OR2 is defined.");
580 #endif
582 #ifdef SHOULD_NOT_BE_DEFINED_MATCHES
583 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_MATCHES is defined.");
584 #else
585 cmPassed("SHOULD_NOT_BE_DEFINED_MATCHES is not defined.");
586 #endif
588 #ifndef SHOULD_BE_DEFINED_MATCHES
589 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_MATCHES is not defined.\n");
590 #else
591 cmPassed("SHOULD_BE_DEFINED_MATCHES is defined.");
592 #endif
594 #ifdef SHOULD_NOT_BE_DEFINED_MATCHES2
595 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_MATCHES2 is defined.");
596 #else
597 cmPassed("SHOULD_NOT_BE_DEFINED_MATCHES2 is not defined.");
598 #endif
600 #ifndef SHOULD_BE_DEFINED_MATCHES2
601 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_MATCHES2 is not defined.\n");
602 #else
603 cmPassed("SHOULD_BE_DEFINED_MATCHES2 is defined.");
604 #endif
606 #ifdef SHOULD_NOT_BE_DEFINED_COMMAND
607 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_COMMAND is defined.");
608 #else
609 cmPassed("SHOULD_NOT_BE_DEFINED_COMMAND is not defined.");
610 #endif
612 #ifndef SHOULD_BE_DEFINED_COMMAND
613 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_COMMAND is not defined.\n");
614 #else
615 cmPassed("SHOULD_BE_DEFINED_COMMAND is defined.");
616 #endif
618 #ifdef SHOULD_NOT_BE_DEFINED_COMMAND2
619 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_COMMAND2 is defined.");
620 #else
621 cmPassed("SHOULD_NOT_BE_DEFINED_COMMAND2 is not defined.");
622 #endif
624 #ifndef SHOULD_BE_DEFINED_COMMAND2
625 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_COMMAND2 is not defined.\n");
626 #else
627 cmPassed("SHOULD_BE_DEFINED_COMMAND2 is defined.");
628 #endif
630 #ifdef SHOULD_NOT_BE_DEFINED_EXISTS
631 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_EXISTS is defined.");
632 #else
633 cmPassed("SHOULD_NOT_BE_DEFINED_EXISTS is not defined.");
634 #endif
636 #ifndef SHOULD_BE_DEFINED_EXISTS
637 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_EXISTS is not defined.\n");
638 #else
639 cmPassed("SHOULD_BE_DEFINED_EXISTS is defined.");
640 #endif
642 #ifdef SHOULD_NOT_BE_DEFINED_EXISTS2
643 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_EXISTS2 is defined.");
644 #else
645 cmPassed("SHOULD_NOT_BE_DEFINED_EXISTS2 is not defined.");
646 #endif
648 #ifndef SHOULD_BE_DEFINED_EXISTS2
649 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_EXISTS2 is not defined.\n");
650 #else
651 cmPassed("SHOULD_BE_DEFINED_EXISTS2 is defined.");
652 #endif
654 #ifndef SHOULD_BE_DEFINED_IS_DIRECTORY
655 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_IS_DIRECTORY is not defined.\n");
656 #else
657 cmPassed("SHOULD_BE_DEFINED_IS_DIRECTORY is defined.");
658 #endif
660 #ifndef SHOULD_BE_DEFINED_IS_DIRECTORY2
661 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_IS_DIRECTORY2 is not defined.\n");
662 #else
663 cmPassed("SHOULD_BE_DEFINED_IS_DIRECTORY2 is defined.");
664 #endif
666 #ifdef SHOULD_NOT_BE_DEFINED_LESS
667 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_LESS is defined.");
668 #else
669 cmPassed("SHOULD_NOT_BE_DEFINED_LESS is not defined.");
670 #endif
672 #ifndef SHOULD_BE_DEFINED_LESS
673 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_LESS is not defined.\n");
674 #else
675 cmPassed("SHOULD_BE_DEFINED_LESS is defined.");
676 #endif
678 #ifdef SHOULD_NOT_BE_DEFINED_LESS2
679 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_LESS2 is defined.");
680 #else
681 cmPassed("SHOULD_NOT_BE_DEFINED_LESS2 is not defined.");
682 #endif
684 #ifndef SHOULD_BE_DEFINED_LESS2
685 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_LESS2 is not defined.\n");
686 #else
687 cmPassed("SHOULD_BE_DEFINED_LESS2 is defined.");
688 #endif
690 #ifdef SHOULD_NOT_BE_DEFINED_GREATER
691 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_GREATER is defined.");
692 #else
693 cmPassed("SHOULD_NOT_BE_DEFINED_GREATER is not defined.");
694 #endif
696 #ifdef SHOULD_NOT_BE_DEFINED_EQUAL
697 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_EQUAL is defined.");
698 #else
699 cmPassed("SHOULD_NOT_BE_DEFINED_EQUAL is not defined.");
700 #endif
702 #ifndef SHOULD_BE_DEFINED_EQUAL
703 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_EQUAL is not defined.\n");
704 #else
705 cmPassed("SHOULD_BE_DEFINED_EQUAL is defined.");
706 #endif
708 #ifndef SHOULD_BE_DEFINED_GREATER
709 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_GREATER is not defined.\n");
710 #else
711 cmPassed("SHOULD_BE_DEFINED_GREATER is defined.");
712 #endif
714 #ifdef SHOULD_NOT_BE_DEFINED_GREATER2
715 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_GREATER2 is defined.");
716 #else
717 cmPassed("SHOULD_NOT_BE_DEFINED_GREATER2 is not defined.");
718 #endif
720 #ifndef SHOULD_BE_DEFINED_GREATER2
721 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_GREATER2 is not defined.\n");
722 #else
723 cmPassed("SHOULD_BE_DEFINED_GREATER2 is defined.");
724 #endif
726 #ifdef SHOULD_NOT_BE_DEFINED_STRLESS
727 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRLESS is defined.");
728 #else
729 cmPassed("SHOULD_NOT_BE_DEFINED_STRLESS is not defined.");
730 #endif
732 #ifndef SHOULD_BE_DEFINED_STRLESS
733 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRLESS is not defined.\n");
734 #else
735 cmPassed("SHOULD_BE_DEFINED_STRLESS is defined.");
736 #endif
738 #ifdef SHOULD_NOT_BE_DEFINED_STRLESS2
739 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRLESS2 is defined.");
740 #else
741 cmPassed("SHOULD_NOT_BE_DEFINED_STRLESS2 is not defined.");
742 #endif
744 #ifndef SHOULD_BE_DEFINED_STRLESS2
745 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRLESS2 is not defined.\n");
746 #else
747 cmPassed("SHOULD_BE_DEFINED_STRLESS2 is defined.");
748 #endif
750 #ifdef SHOULD_NOT_BE_DEFINED_STRGREATER
751 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRGREATER is defined.");
752 #else
753 cmPassed("SHOULD_NOT_BE_DEFINED_STRGREATER is not defined.");
754 #endif
756 #ifndef SHOULD_BE_DEFINED_STRGREATER
757 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRGREATER is not defined.\n");
758 #else
759 cmPassed("SHOULD_BE_DEFINED_STRGREATER is defined.");
760 #endif
762 #ifdef SHOULD_NOT_BE_DEFINED_STRGREATER2
763 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRGREATER2 is defined.");
764 #else
765 cmPassed("SHOULD_NOT_BE_DEFINED_STRGREATER2 is not defined.");
766 #endif
768 #ifndef SHOULD_BE_DEFINED_STRGREATER2
769 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRGREATER2 is not defined.\n");
770 #else
771 cmPassed("SHOULD_BE_DEFINED_STRGREATER2 is defined.");
772 #endif
774 // ----------------------------------------------------------------------
775 // Test FOREACH
777 #ifndef FOREACH_VAR1
778 cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
779 "FOREACH_VAR1 is not defined.");
780 #else
781 if(strcmp(FOREACH_VAR1, "VALUE1") != 0)
783 cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
784 "FOREACH_VAR1 == ", FOREACH_VAR1);
786 else
788 cmPassed("FOREACH_VAR1 == ", FOREACH_VAR1);
790 #endif
792 #ifndef FOREACH_VAR2
793 cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
794 "FOREACH_VAR2 is not defined.");
795 #else
796 if(strcmp(FOREACH_VAR2, "VALUE2") != 0)
798 cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
799 "FOREACH_VAR2 == ", FOREACH_VAR2);
801 else
803 cmPassed("FOREACH_VAR2 == ", FOREACH_VAR2);
805 #endif
807 #ifndef FOREACH_CONCAT
808 cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
809 "FOREACH_CONCAT is not defined.");
810 #else
811 if(strcmp(FOREACH_CONCAT, "abcdefg") != 0)
813 cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
814 "FOREACH_CONCAT == ", FOREACH_CONCAT);
816 else
818 cmPassed("FOREACH_CONCAT == ", FOREACH_CONCAT);
820 #endif
822 // ----------------------------------------------------------------------
823 // Test WHILE
825 if(WHILE_VALUE != 1000)
827 cmFailed("WHILE command is not working");
829 else
831 cmPassed("WHILE command is working");
834 // ----------------------------------------------------------------------
835 // Test FIND_FILE, FIND_PATH and various GET_FILENAME_COMPONENT combinations
837 #ifndef FILENAME_VAR_PATH_NAME
838 cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
839 "FILENAME_VAR_PATH_NAME is not defined.");
840 #else
841 if((strcmp(FILENAME_VAR_PATH_NAME, "Complex") == 0) ||
842 (strcmp(FILENAME_VAR_PATH_NAME, "ComplexOneConfig") == 0) ||
843 (strcmp(FILENAME_VAR_PATH_NAME, "ComplexRelativePaths") == 0))
845 cmPassed("FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME);
847 else
849 cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
850 "FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME);
852 #endif
854 #ifndef FILENAME_VAR_NAME
855 cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
856 "FILENAME_VAR_NAME is not defined.");
857 #else
858 if(strcmp(FILENAME_VAR_NAME, "VarTests.cmake") != 0)
860 cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
861 "FILENAME_VAR_NAME == ", FILENAME_VAR_NAME);
863 else
865 cmPassed("FILENAME_VAR_NAME == ", FILENAME_VAR_NAME);
867 #endif
869 #ifndef FILENAME_VAR_EXT
870 cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
871 "FILENAME_VAR_EXT is not defined.");
872 #else
873 if(strcmp(FILENAME_VAR_EXT, ".cmake") != 0)
875 cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
876 "FILENAME_VAR_EXT == ", FILENAME_VAR_EXT);
878 else
880 cmPassed("FILENAME_VAR_EXT == ", FILENAME_VAR_EXT);
882 #endif
884 #ifndef FILENAME_VAR_NAME_WE
885 cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
886 "FILENAME_VAR_NAME_WE is not defined.");
887 #else
888 if(strcmp(FILENAME_VAR_NAME_WE, "VarTests") != 0)
890 cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
891 "FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE);
893 else
895 cmPassed("FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE);
897 #endif
899 #ifndef PATH_VAR_NAME
900 cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
901 "PATH_VAR_NAME is not defined.");
902 #else
903 if((strcmp(PATH_VAR_NAME, "Complex") == 0) ||
904 (strcmp(PATH_VAR_NAME, "ComplexOneConfig") == 0) ||
905 (strcmp(PATH_VAR_NAME, "ComplexRelativePaths") == 0))
907 cmPassed("PATH_VAR_NAME == ", PATH_VAR_NAME);
909 else
911 cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
912 "PATH_VAR_NAME == ", PATH_VAR_NAME);
914 #endif
916 // ----------------------------------------------------------------------
917 // Test LOAD_CACHE
919 #ifndef CACHE_TEST_VAR1
920 cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
921 "CACHE_TEST_VAR1 is not defined.");
922 #else
923 if(strcmp(CACHE_TEST_VAR1, "foo") != 0)
925 cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
926 "CACHE_TEST_VAR1 == ", CACHE_TEST_VAR1);
928 else
930 cmPassed("CACHE_TEST_VAR1 == ", CACHE_TEST_VAR1);
932 #endif
934 #ifndef CACHE_TEST_VAR2
935 cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
936 "CACHE_TEST_VAR2 is not defined.");
937 #else
938 if(strcmp(CACHE_TEST_VAR2, "bar") != 0)
940 cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
941 "CACHE_TEST_VAR2 == ", CACHE_TEST_VAR2);
943 else
945 cmPassed("CACHE_TEST_VAR2 == ", CACHE_TEST_VAR2);
947 #endif
949 #ifndef CACHE_TEST_VAR3
950 cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
951 "CACHE_TEST_VAR3 is not defined.");
952 #else
953 if(strcmp(CACHE_TEST_VAR3, "1") != 0)
955 cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
956 "CACHE_TEST_VAR3 == ", CACHE_TEST_VAR3);
958 else
960 cmPassed("CACHE_TEST_VAR3 == ", CACHE_TEST_VAR3);
962 #endif
964 #ifdef CACHE_TEST_VAR_EXCLUDED
965 cmFailed("the LOAD_CACHE or CONFIGURE_FILE command or cmakedefine is broken, "
966 "CACHE_TEST_VAR_EXCLUDED is defined (should not have been loaded).");
967 #else
968 cmPassed("CACHE_TEST_VAR_EXCLUDED is not defined.");
969 #endif
971 #ifndef CACHE_TEST_VAR_INTERNAL
972 cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
973 "CACHE_TEST_VAR_INTERNAL is not defined.");
974 #else
975 std::string cachetest = CACHE_TEST_VAR_INTERNAL;
976 if(cachetest != "bar")
978 cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
979 "CACHE_TEST_VAR_INTERNAL == ", CACHE_TEST_VAR_INTERNAL);
981 else
983 cmPassed("CACHE_TEST_VAR_INTERNAL == ", CACHE_TEST_VAR_INTERNAL);
985 #endif
987 #ifdef COMPLEX_TEST_CMAKELIB
988 // ----------------------------------------------------------------------
989 // Some pre-build/pre-link/post-build custom-commands have been
990 // attached to the lib (see Library/).
991 // Each runs ${CREATE_FILE_EXE} which will create a file.
992 // It also copies that file again using cmake -E.
993 // Similar rules have been added to this executable.
995 // WARNING: if you run 'complex' manually, this *will* fail, because
996 // the file was removed the last time 'complex' was run, and it is
997 // only created during a build.
999 TestAndRemoveFile(BINARY_DIR "/Library/prebuild.txt");
1000 TestAndRemoveFile(BINARY_DIR "/Library/prelink.txt");
1001 TestAndRemoveFile(BINARY_DIR "/Library/postbuild.txt");
1002 TestAndRemoveFile(BINARY_DIR "/Library/postbuild2.txt");
1003 TestAndRemoveFile(BINARY_DIR "/Executable/prebuild.txt");
1004 TestAndRemoveFile(BINARY_DIR "/Executable/prelink.txt");
1005 TestAndRemoveFile(BINARY_DIR "/Executable/postbuild.txt");
1006 TestAndRemoveFile(BINARY_DIR "/Executable/postbuild2.txt");
1008 // ----------------------------------------------------------------------
1009 // A custom target has been created (see Library/).
1010 // It runs ${CREATE_FILE_EXE} which will create a file.
1012 // WARNING: if you run 'complex' manually, this *will* fail, because
1013 // the file was removed the last time 'complex' was run, and it is
1014 // only created during a build.
1016 TestAndRemoveFile(BINARY_DIR "/Library/custom_target1.txt");
1018 // ----------------------------------------------------------------------
1019 // A directory has been created.
1021 TestDir(BINARY_DIR "/make_dir");
1023 // ----------------------------------------------------------------------
1024 // Test OUTPUT_REQUIRED_FILES
1025 // The files required by 'complex' have been output to a file.
1026 // The contents of this file is not tested (absolute paths).
1028 // WARNING: if you run 'complex' manually, this *will* fail, because
1029 // the file was removed the last time 'complex' was run, and it is
1030 // only created during a build.
1032 TestAndRemoveFile(BINARY_DIR "/Executable/Temp/complex-required.txt");
1033 #endif
1035 // ----------------------------------------------------------------------
1036 // Test FIND_LIBRARY
1038 #ifndef FIND_DUMMY_LIB
1039 cmFailed("the CONFIGURE_FILE command is broken, "
1040 "FIND_DUMMY_LIB is not defined.");
1041 #else
1042 if(strstr(FIND_DUMMY_LIB, "dummylib") == NULL)
1044 cmFailed("the FIND_LIBRARY or CONFIGURE_FILE command is broken, "
1045 "FIND_DUMMY_LIB == ", FIND_DUMMY_LIB);
1047 else
1049 cmPassed("FIND_DUMMY_LIB == ", FIND_DUMMY_LIB);
1051 #endif
1053 // ----------------------------------------------------------------------
1054 // Test SET_SOURCE_FILES_PROPERTIES
1056 #ifndef FILE_HAS_EXTRA_COMPILE_FLAGS
1057 cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting FILE_HAS_EXTRA_COMPILE_FLAGS flag");
1058 #else
1059 cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting FILE_HAS_EXTRA_COMPILE_FLAGS flag");
1060 #endif
1062 #if 0 // Disable until implemented everywhere.
1063 #ifndef FILE_DEFINE_STRING
1064 cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting FILE_DEFINE_STRING flag");
1065 #else
1066 if(strcmp(FILE_DEFINE_STRING, "hello") != 0)
1068 cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting FILE_DEFINE_STRING flag correctly");
1070 else
1072 cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting FILE_DEFINE_STRING flag");
1074 #endif
1075 #endif
1077 #ifndef FILE_HAS_ABSTRACT
1078 cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting ABSTRACT flag");
1079 #else
1080 cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting ABSTRACT flag");
1081 #endif
1083 #ifndef FILE_HAS_WRAP_EXCLUDE
1084 cmFailed("FILE_HAS_WRAP_EXCLUDE failed at setting WRAP_EXCLUDE flag");
1085 #else
1086 cmPassed("FILE_HAS_WRAP_EXCLUDE succeeded in setting WRAP_EXCLUDE flag");
1087 #endif
1089 #ifndef FILE_COMPILE_FLAGS
1090 cmFailed("the CONFIGURE_FILE command is broken, FILE_COMPILE_FLAGS is not defined.");
1091 #else
1092 if(strcmp(FILE_COMPILE_FLAGS, "-foo -bar") != 0)
1094 cmFailed("the SET_SOURCE_FILES_PROPERTIES or CONFIGURE_FILE command is broken. FILE_COMPILE_FLAGS == ",
1095 FILE_COMPILE_FLAGS);
1097 else
1099 cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting extra flags == ", FILE_COMPILE_FLAGS);
1101 #endif
1103 // ----------------------------------------------------------------------
1104 // Test registry (win32)
1105 #if defined(_WIN32) && !defined(__CYGWIN__)
1106 #ifndef REGISTRY_TEST_PATH
1107 cmFailed("the CONFIGURE_FILE command is broken, REGISTRY_TEST_PATH is not defined.");
1108 #else
1109 std::cout << "REGISTRY_TEST_PATH == " << REGISTRY_TEST_PATH << "\n";
1110 if(stricmp(REGISTRY_TEST_PATH, BINARY_DIR "/registry_dir") != 0)
1112 cmFailed("the 'read registry value' function or CONFIGURE_FILE command is broken. REGISTRY_TEST_PATH == ",
1113 REGISTRY_TEST_PATH, " is not " BINARY_DIR "/registry_dir");
1115 else
1117 cmPassed("REGISTRY_TEST_PATH == ", REGISTRY_TEST_PATH);
1119 #endif
1120 #endif // defined(_WIN32) && !defined(__CYGWIN__)
1122 if(strcmp(CMAKE_MINIMUM_REQUIRED_VERSION, "1.3") == 0)
1124 cmPassed("CMAKE_MINIMUM_REQUIRED_VERSION is set to 1.3");
1126 else
1128 cmFailed("CMAKE_MINIMUM_REQUIRED_VERSION is not set to the expected 1.3");
1131 // ----------------------------------------------------------------------
1132 // Test REMOVE command
1133 if (strcmp("a;b;d",REMOVE_STRING) == 0)
1135 cmPassed("REMOVE is working");
1137 else
1139 cmFailed("REMOVE is not working");
1142 // ----------------------------------------------------------------------
1143 // Test SEPARATE_ARGUMENTS
1144 if(strcmp("a;b;c", TEST_SEP) == 0)
1146 cmPassed("SEPARATE_ARGUMENTS is working");
1148 else
1150 cmFailed("SEPARATE_ARGUMENTS is not working");
1153 // ----------------------------------------------------------------------
1154 // Test Escape Quotes
1155 if(strcmp("\"hello world\"", STRING_WITH_QUOTES) == 0)
1157 cmPassed("ESCAPE_QUOTES is working");
1159 else
1161 cmFailed("ESCAPE_QUOTES is not working");
1165 // ----------------------------------------------------------------------
1166 // Test if IF command inside a FOREACH works.
1167 #if defined(IF_INSIDE_FOREACH_THEN_EXECUTED) && !defined(IF_INSIDE_FOREACH_ELSE_EXECUTED)
1168 cmPassed("IF inside a FOREACH block works");
1169 #else
1170 cmFailed("IF inside a FOREACH block is broken");
1171 #endif
1173 #if defined(GENERATED_HEADER_INCLUDED)
1174 cmPassed("Generated header included by non-generated source works.");
1175 #else
1176 cmFailed("Generated header included by non-generated source failed.");
1177 #endif
1178 if(SHOULD_BE_ZERO == 0)
1180 cmPassed("cmakedefine01 is working for 0");
1182 else
1184 cmFailed("cmakedefine01 is not working for 0");
1186 if(SHOULD_BE_ONE == 1)
1188 cmPassed("cmakedefine01 is working for 1");
1190 else
1192 cmFailed("cmakedefine01 is not working for 1");
1194 #ifdef FORCE_TEST
1195 cmFailed("CMake SET CACHE FORCE");
1196 #else
1197 cmPassed("CMake SET CACHE FORCE");
1198 #endif
1200 #ifdef COMPLEX_TEST_CMAKELIB
1201 // Test the generated file stream.
1202 TestCMGeneratedFileSTream();
1203 #endif
1205 #ifdef COMPLEX_TEST_LINK_STATIC
1206 if(TestLinkGetType())
1208 cmPassed("Link to static over shared worked.");
1210 else
1212 cmFailed("Link to static over shared failed.");
1214 #endif
1216 // ----------------------------------------------------------------------
1217 // Summary
1219 std::cout << "Passed: " << cm_passed << "\n";
1220 if(cm_failed)
1222 std::cout << "Failed: " << cm_failed << "\n";
1223 return cm_failed;
1225 return 0;