1 #include "cmTestConfigure.h"
2 #include "cmTestConfigureEscape.h"
3 #include "cmTestGeneratedHeader.h"
5 #include "ExtraSources/file1.h"
7 #include "sharedFile.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>
25 #ifdef COMPLEX_TEST_LINK_STATIC
28 int TestLinkGetType();
34 // ======================================================================
36 void cmFailed(const char* Message
, const char* m2
= "", const char* m3
= "")
38 std::cout
<< "FAILED: " << Message
<< m2
<< m3
<< "\n";
42 // ======================================================================
44 void cmPassed(const char* Message
, const char* m2
="")
46 std::cout
<< "Passed: " << Message
<< m2
<< "\n";
50 #ifndef COMPLEX_DEFINED_PRE
51 # error "COMPLEX_DEFINED_PRE not defined!"
54 #ifdef COMPLEX_DEFINED
55 # error "COMPLEX_DEFINED is defined but it should not!"
58 #ifndef COMPLEX_DEFINED_POST
59 # error "COMPLEX_DEFINED_POST not defined!"
62 #ifndef CMAKE_IS_REALLY_FUN
63 # error This is a problem. Looks like ADD_DEFINITIONS and REMOVE_DEFINITIONS does not work
66 #if defined(NDEBUG) && !defined(CMAKE_IS_FUN_IN_RELEASE_MODE)
67 # error Per-configuration directory-level definition not inherited.
70 #ifdef COMPLEX_TEST_CMAKELIB
71 // ======================================================================
73 void TestAndRemoveFile(const char* filename
)
75 if (!cmSystemTools::FileExists(filename
))
77 cmFailed("Could not find file: ", filename
);
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
);
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
);
102 if (!cmSystemTools::FileIsDirectory(filename
))
104 cmFailed("Unable to check if file is a directory: ", filename
);
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";
129 gm
.Open(file2
.c_str());
130 gm
<< "This is generated file 2";
132 gm
.Open(file3
.c_str());
133 gm
<< "This is generated file 3";
135 gm
.Open(file4
.c_str());
136 gm
<< "This is generated file 4";
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());
164 cmPassed("cmGeneratedFileStream works.");
169 cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", file4
.c_str());
174 cmFailed("Something wrong with cmGeneratedFileStream. Found file: ", file3
.c_str());
179 cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", file2
.c_str());
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());
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
;
203 std::string cachetest
= CACHE_TEST_VAR_INTERNAL
;
204 v
.push_back(cachetest
);
206 std::string
x(5,'x');
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
);
225 // defined in Sub1/NameConflictTest.c
226 extern "C" int NameConflictTest1();
227 // defined in Sub2/NameConflictTest.c
228 extern "C" int NameConflictTest2();
231 // ======================================================================
235 std::string lib
= BINARY_DIR
;
241 std::string exe
= BINARY_DIR
;
248 #ifdef COMPLEX_TEST_CMAKELIB
249 // Test a single character executable to test a: in makefiles
251 exe
+= cmSystemTools::GetExecutableExtension();
253 std::string errorMessage
;
254 exe
= cmSystemTools::ConvertToRunCommandPath(exe
.c_str());
255 if(cmSystemTools::RunSingleCommand(exe
.c_str(), 0, &ret
))
260 errorMessage
+= " did not return 10";
266 errorMessage
+= ": failed to run.";
268 if(errorMessage
.size())
270 cmFailed(errorMessage
.c_str());
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());
283 std::string err
= "Can not open CMakeTestModule:\n";
285 cmFailed(err
.c_str());
289 cmsys::DynamicLoader::SymbolPointer fun
=
290 cmsys::DynamicLoader::GetSymbolAddress(handle
, "ModuleFunction");
293 fun
= cmsys::DynamicLoader::GetSymbolAddress(handle
, "_ModuleFunction");
295 typedef int (*TEST_FUNCTION
)();
296 TEST_FUNCTION testFun
= (TEST_FUNCTION
)fun
;
299 cmFailed("Could not find symbol ModuleFunction in library ");
303 int ret
= (*testFun
)();
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.");
318 cmPassed("Call to sharedFunction from shared library worked.");
320 if(CsharedFunction() != 1)
322 cmFailed("Call to C sharedFunction from shared library failed.");
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");
339 cmFailed("cmSystemTools::UpperCase is working");
343 if(NameConflictTest1() == 0 && NameConflictTest2() == 0)
345 cmPassed("Sub dir with same named source works");
349 cmFailed("Sub dir with same named source fails");
354 cmFailed("Call to file1 function from library failed.");
358 cmPassed("Call to file1 function returned 1.");
360 #ifndef COMPLEX_TARGET_FLAG
361 cmFailed("COMPILE_FLAGS did not work with SET_TARGET_PROPERTIES");
363 cmPassed("COMPILE_FLAGS did work with SET_TARGET_PROPERTIES");
367 cmPassed("ELSEIF did work");
369 cmFailed("ELSEIF did not work");
372 #ifdef CONDITIONAL_PARENTHESES
373 cmPassed("CONDITIONAL_PARENTHESES did work");
375 cmFailed("CONDITIONAL_PARENTHESES did not work");
380 cmFailed("Call to file2 function from library failed.");
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!");
389 cmPassed("CMake CMAKE_CXX_FLAGS is being passed to the compiler.");
391 std::string gen
= CMAKE_GENERATOR
;
392 // visual studio is currently broken for c flags
394 if(gen
.find("Visual") == gen
.npos
)
397 cmFailed("CMake CMAKE_C_FLAGS are being passed to c++ files the compiler!");
399 cmPassed("CMake CMAKE_C_FLAGS are not being passed to c++ files.");
404 "CMake CMAKE_C_FLAGS are being passed to c files and CXX flags are not.");
411 if(TestTargetCompileFlags(msg
))
420 // ----------------------------------------------------------------------
421 // Test ADD_DEFINITIONS
424 cmFailed("CMake is not fun, so it is broken and should be fixed.");
426 cmPassed("CMAKE_IS_FUN is defined.");
429 #if defined(CMAKE_ARGV1) && defined(CMAKE_ARGV2) && defined(CMAKE_ARGV3) && defined(CMAKE_ARGV4)
430 cmPassed("Variable args for MACROs are working.");
432 cmFailed("Variable args for MACROs are failing.");
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");
440 cmPassed("CMake found A.cxx properly");
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");
448 cmPassed("CMake found the parent directory properly");
451 // ----------------------------------------------------------------------
452 // Test GET_DIRECTORY_PROPERTY for listfiles
453 #ifndef CMAKE_FOUND_LISTFILE_STACK
454 cmFailed("CMake did not get the listfile stack properly");
456 cmPassed("CMake found the listfile stack properly");
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.");
465 cmPassed("SHOULD_NOT_BE_DEFINED is not defined.");
468 #ifndef SHOULD_BE_DEFINED
469 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED is not defined.\n");
471 cmPassed("SHOULD_BE_DEFINED is defined.");
475 cmFailed("cmakedefine is broken, ONE_VAR is not defined.");
477 cmPassed("ONE_VAR is defined.");
480 #ifndef ONE_VAR_IS_DEFINED
481 cmFailed("cmakedefine, SET or VARIABLE_REQUIRES is broken, "
482 "ONE_VAR_IS_DEFINED is not defined.");
484 cmPassed("ONE_VAR_IS_DEFINED is defined.");
488 cmFailed("cmakedefine is broken, ZERO_VAR is defined.");
490 cmPassed("ZERO_VAR is not defined.");
494 cmFailed("the CONFIGURE_FILE command is broken, STRING_VAR is not defined.");
496 if(strcmp(STRING_VAR
, "CMake is great") != 0)
498 cmFailed("the SET or CONFIGURE_FILE command is broken. STRING_VAR == ",
503 cmPassed("STRING_VAR == ", STRING_VAR
);
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.");
513 cmPassed("SHOULD_NOT_BE_DEFINED_NOT is not defined.");
516 #ifndef SHOULD_BE_DEFINED_NOT
517 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_NOT is not defined.\n");
519 cmPassed("SHOULD_BE_DEFINED_NOT is defined.");
522 #ifdef SHOULD_NOT_BE_DEFINED_NOT2
523 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_NOT2 is defined.");
525 cmPassed("SHOULD_NOT_BE_DEFINED_NOT2 is not defined.");
528 #ifndef SHOULD_BE_DEFINED_NOT2
529 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_NOT2 is not defined.\n");
531 cmPassed("SHOULD_BE_DEFINED_NOT2 is defined.");
534 #ifdef SHOULD_NOT_BE_DEFINED_AND
535 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_AND is defined.");
537 cmPassed("SHOULD_NOT_BE_DEFINED_AND is not defined.");
540 #ifndef SHOULD_BE_DEFINED_AND
541 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_AND is not defined.\n");
543 cmPassed("SHOULD_BE_DEFINED_AND is defined.");
546 #ifdef SHOULD_NOT_BE_DEFINED_AND2
547 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_AND2 is defined.");
549 cmPassed("SHOULD_NOT_BE_DEFINED_AND2 is not defined.");
552 #ifndef SHOULD_BE_DEFINED_AND2
553 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_AND2 is not defined.\n");
555 cmPassed("SHOULD_BE_DEFINED_AND2 is defined.");
558 #ifdef SHOULD_NOT_BE_DEFINED_OR
559 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_OR is defined.");
561 cmPassed("SHOULD_NOT_BE_DEFINED_OR is not defined.");
564 #ifndef SHOULD_BE_DEFINED_OR
565 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_OR is not defined.\n");
567 cmPassed("SHOULD_BE_DEFINED_OR is defined.");
570 #ifdef SHOULD_NOT_BE_DEFINED_OR2
571 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_OR2 is defined.");
573 cmPassed("SHOULD_NOT_BE_DEFINED_OR2 is not defined.");
576 #ifndef SHOULD_BE_DEFINED_OR2
577 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_OR2 is not defined.\n");
579 cmPassed("SHOULD_BE_DEFINED_OR2 is defined.");
582 #ifdef SHOULD_NOT_BE_DEFINED_MATCHES
583 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_MATCHES is defined.");
585 cmPassed("SHOULD_NOT_BE_DEFINED_MATCHES is not defined.");
588 #ifndef SHOULD_BE_DEFINED_MATCHES
589 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_MATCHES is not defined.\n");
591 cmPassed("SHOULD_BE_DEFINED_MATCHES is defined.");
594 #ifdef SHOULD_NOT_BE_DEFINED_MATCHES2
595 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_MATCHES2 is defined.");
597 cmPassed("SHOULD_NOT_BE_DEFINED_MATCHES2 is not defined.");
600 #ifndef SHOULD_BE_DEFINED_MATCHES2
601 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_MATCHES2 is not defined.\n");
603 cmPassed("SHOULD_BE_DEFINED_MATCHES2 is defined.");
606 #ifdef SHOULD_NOT_BE_DEFINED_COMMAND
607 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_COMMAND is defined.");
609 cmPassed("SHOULD_NOT_BE_DEFINED_COMMAND is not defined.");
612 #ifndef SHOULD_BE_DEFINED_COMMAND
613 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_COMMAND is not defined.\n");
615 cmPassed("SHOULD_BE_DEFINED_COMMAND is defined.");
618 #ifdef SHOULD_NOT_BE_DEFINED_COMMAND2
619 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_COMMAND2 is defined.");
621 cmPassed("SHOULD_NOT_BE_DEFINED_COMMAND2 is not defined.");
624 #ifndef SHOULD_BE_DEFINED_COMMAND2
625 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_COMMAND2 is not defined.\n");
627 cmPassed("SHOULD_BE_DEFINED_COMMAND2 is defined.");
630 #ifdef SHOULD_NOT_BE_DEFINED_EXISTS
631 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_EXISTS is defined.");
633 cmPassed("SHOULD_NOT_BE_DEFINED_EXISTS is not defined.");
636 #ifndef SHOULD_BE_DEFINED_EXISTS
637 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_EXISTS is not defined.\n");
639 cmPassed("SHOULD_BE_DEFINED_EXISTS is defined.");
642 #ifdef SHOULD_NOT_BE_DEFINED_EXISTS2
643 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_EXISTS2 is defined.");
645 cmPassed("SHOULD_NOT_BE_DEFINED_EXISTS2 is not defined.");
648 #ifndef SHOULD_BE_DEFINED_EXISTS2
649 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_EXISTS2 is not defined.\n");
651 cmPassed("SHOULD_BE_DEFINED_EXISTS2 is defined.");
654 #ifndef SHOULD_BE_DEFINED_IS_DIRECTORY
655 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_IS_DIRECTORY is not defined.\n");
657 cmPassed("SHOULD_BE_DEFINED_IS_DIRECTORY is defined.");
660 #ifndef SHOULD_BE_DEFINED_IS_DIRECTORY2
661 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_IS_DIRECTORY2 is not defined.\n");
663 cmPassed("SHOULD_BE_DEFINED_IS_DIRECTORY2 is defined.");
666 #ifdef SHOULD_NOT_BE_DEFINED_LESS
667 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_LESS is defined.");
669 cmPassed("SHOULD_NOT_BE_DEFINED_LESS is not defined.");
672 #ifndef SHOULD_BE_DEFINED_LESS
673 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_LESS is not defined.\n");
675 cmPassed("SHOULD_BE_DEFINED_LESS is defined.");
678 #ifdef SHOULD_NOT_BE_DEFINED_LESS2
679 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_LESS2 is defined.");
681 cmPassed("SHOULD_NOT_BE_DEFINED_LESS2 is not defined.");
684 #ifndef SHOULD_BE_DEFINED_LESS2
685 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_LESS2 is not defined.\n");
687 cmPassed("SHOULD_BE_DEFINED_LESS2 is defined.");
690 #ifdef SHOULD_NOT_BE_DEFINED_GREATER
691 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_GREATER is defined.");
693 cmPassed("SHOULD_NOT_BE_DEFINED_GREATER is not defined.");
696 #ifdef SHOULD_NOT_BE_DEFINED_EQUAL
697 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_EQUAL is defined.");
699 cmPassed("SHOULD_NOT_BE_DEFINED_EQUAL is not defined.");
702 #ifndef SHOULD_BE_DEFINED_EQUAL
703 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_EQUAL is not defined.\n");
705 cmPassed("SHOULD_BE_DEFINED_EQUAL is defined.");
708 #ifndef SHOULD_BE_DEFINED_GREATER
709 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_GREATER is not defined.\n");
711 cmPassed("SHOULD_BE_DEFINED_GREATER is defined.");
714 #ifdef SHOULD_NOT_BE_DEFINED_GREATER2
715 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_GREATER2 is defined.");
717 cmPassed("SHOULD_NOT_BE_DEFINED_GREATER2 is not defined.");
720 #ifndef SHOULD_BE_DEFINED_GREATER2
721 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_GREATER2 is not defined.\n");
723 cmPassed("SHOULD_BE_DEFINED_GREATER2 is defined.");
726 #ifdef SHOULD_NOT_BE_DEFINED_STRLESS
727 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRLESS is defined.");
729 cmPassed("SHOULD_NOT_BE_DEFINED_STRLESS is not defined.");
732 #ifndef SHOULD_BE_DEFINED_STRLESS
733 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRLESS is not defined.\n");
735 cmPassed("SHOULD_BE_DEFINED_STRLESS is defined.");
738 #ifdef SHOULD_NOT_BE_DEFINED_STRLESS2
739 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRLESS2 is defined.");
741 cmPassed("SHOULD_NOT_BE_DEFINED_STRLESS2 is not defined.");
744 #ifndef SHOULD_BE_DEFINED_STRLESS2
745 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRLESS2 is not defined.\n");
747 cmPassed("SHOULD_BE_DEFINED_STRLESS2 is defined.");
750 #ifdef SHOULD_NOT_BE_DEFINED_STRGREATER
751 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRGREATER is defined.");
753 cmPassed("SHOULD_NOT_BE_DEFINED_STRGREATER is not defined.");
756 #ifndef SHOULD_BE_DEFINED_STRGREATER
757 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRGREATER is not defined.\n");
759 cmPassed("SHOULD_BE_DEFINED_STRGREATER is defined.");
762 #ifdef SHOULD_NOT_BE_DEFINED_STRGREATER2
763 cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRGREATER2 is defined.");
765 cmPassed("SHOULD_NOT_BE_DEFINED_STRGREATER2 is not defined.");
768 #ifndef SHOULD_BE_DEFINED_STRGREATER2
769 cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRGREATER2 is not defined.\n");
771 cmPassed("SHOULD_BE_DEFINED_STRGREATER2 is defined.");
774 // ----------------------------------------------------------------------
778 cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
779 "FOREACH_VAR1 is not defined.");
781 if(strcmp(FOREACH_VAR1
, "VALUE1") != 0)
783 cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
784 "FOREACH_VAR1 == ", FOREACH_VAR1
);
788 cmPassed("FOREACH_VAR1 == ", FOREACH_VAR1
);
793 cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
794 "FOREACH_VAR2 is not defined.");
796 if(strcmp(FOREACH_VAR2
, "VALUE2") != 0)
798 cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
799 "FOREACH_VAR2 == ", FOREACH_VAR2
);
803 cmPassed("FOREACH_VAR2 == ", FOREACH_VAR2
);
807 #ifndef FOREACH_CONCAT
808 cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
809 "FOREACH_CONCAT is not defined.");
811 if(strcmp(FOREACH_CONCAT
, "abcdefg") != 0)
813 cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
814 "FOREACH_CONCAT == ", FOREACH_CONCAT
);
818 cmPassed("FOREACH_CONCAT == ", FOREACH_CONCAT
);
822 // ----------------------------------------------------------------------
825 if(WHILE_VALUE
!= 1000)
827 cmFailed("WHILE command is not working");
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.");
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
);
849 cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
850 "FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME
);
854 #ifndef FILENAME_VAR_NAME
855 cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
856 "FILENAME_VAR_NAME is not defined.");
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
);
865 cmPassed("FILENAME_VAR_NAME == ", FILENAME_VAR_NAME
);
869 #ifndef FILENAME_VAR_EXT
870 cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
871 "FILENAME_VAR_EXT is not defined.");
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
);
880 cmPassed("FILENAME_VAR_EXT == ", FILENAME_VAR_EXT
);
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.");
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
);
895 cmPassed("FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE
);
899 #ifndef PATH_VAR_NAME
900 cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
901 "PATH_VAR_NAME is not defined.");
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
);
911 cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
912 "PATH_VAR_NAME == ", PATH_VAR_NAME
);
916 // ----------------------------------------------------------------------
919 #ifndef CACHE_TEST_VAR1
920 cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
921 "CACHE_TEST_VAR1 is not defined.");
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
);
930 cmPassed("CACHE_TEST_VAR1 == ", CACHE_TEST_VAR1
);
934 #ifndef CACHE_TEST_VAR2
935 cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
936 "CACHE_TEST_VAR2 is not defined.");
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
);
945 cmPassed("CACHE_TEST_VAR2 == ", CACHE_TEST_VAR2
);
949 #ifndef CACHE_TEST_VAR3
950 cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
951 "CACHE_TEST_VAR3 is not defined.");
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
);
960 cmPassed("CACHE_TEST_VAR3 == ", CACHE_TEST_VAR3
);
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).");
968 cmPassed("CACHE_TEST_VAR_EXCLUDED is not defined.");
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.");
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
);
983 cmPassed("CACHE_TEST_VAR_INTERNAL == ", CACHE_TEST_VAR_INTERNAL
);
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");
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.");
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
);
1049 cmPassed("FIND_DUMMY_LIB == ", FIND_DUMMY_LIB
);
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");
1059 cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting FILE_HAS_EXTRA_COMPILE_FLAGS flag");
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");
1066 if(strcmp(FILE_DEFINE_STRING
, "hello") != 0)
1068 cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting FILE_DEFINE_STRING flag correctly");
1072 cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting FILE_DEFINE_STRING flag");
1077 #ifndef FILE_HAS_ABSTRACT
1078 cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting ABSTRACT flag");
1080 cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting ABSTRACT flag");
1083 #ifndef FILE_HAS_WRAP_EXCLUDE
1084 cmFailed("FILE_HAS_WRAP_EXCLUDE failed at setting WRAP_EXCLUDE flag");
1086 cmPassed("FILE_HAS_WRAP_EXCLUDE succeeded in setting WRAP_EXCLUDE flag");
1089 #ifndef FILE_COMPILE_FLAGS
1090 cmFailed("the CONFIGURE_FILE command is broken, FILE_COMPILE_FLAGS is not defined.");
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
);
1099 cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting extra flags == ", FILE_COMPILE_FLAGS
);
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.");
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");
1117 cmPassed("REGISTRY_TEST_PATH == ", REGISTRY_TEST_PATH
);
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");
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");
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");
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");
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");
1170 cmFailed("IF inside a FOREACH block is broken");
1173 #if defined(GENERATED_HEADER_INCLUDED)
1174 cmPassed("Generated header included by non-generated source works.");
1176 cmFailed("Generated header included by non-generated source failed.");
1178 if(SHOULD_BE_ZERO
== 0)
1180 cmPassed("cmakedefine01 is working for 0");
1184 cmFailed("cmakedefine01 is not working for 0");
1186 if(SHOULD_BE_ONE
== 1)
1188 cmPassed("cmakedefine01 is working for 1");
1192 cmFailed("cmakedefine01 is not working for 1");
1195 cmFailed("CMake SET CACHE FORCE");
1197 cmPassed("CMake SET CACHE FORCE");
1200 #ifdef COMPLEX_TEST_CMAKELIB
1201 // Test the generated file stream.
1202 TestCMGeneratedFileSTream();
1205 #ifdef COMPLEX_TEST_LINK_STATIC
1206 if(TestLinkGetType())
1208 cmPassed("Link to static over shared worked.");
1212 cmFailed("Link to static over shared failed.");
1216 // ----------------------------------------------------------------------
1219 std::cout
<< "Passed: " << cm_passed
<< "\n";
1222 std::cout
<< "Failed: " << cm_failed
<< "\n";