12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214 |
- #include "cmTestConfigure.h"
- #include "cmTestConfigureEscape.h"
- #include "cmTestGeneratedHeader.h"
- #include "cmVersion.h"
- #include "ExtraSources/file1.h"
- #include "file2.h"
- #include "sharedFile.h"
- extern "C" {
- #include "testConly.h"
- }
- #ifndef CMAKE_TEST_DIFFERENT_GENERATOR
- #include "cmStandardIncludes.h"
- #include "cmSystemTools.h"
- #include "cmDynamicLoader.h"
- #include "cmSystemTools.h"
- #include "cmOrderLinkDirectories.h"
- #include "cmGeneratedFileStream.h"
- #include <cmsys/DynamicLoader.hxx>
- #else
- #include <vector>
- #include <string>
- #include <iostream>
- #include <string.h>
- #endif
- int cm_passed = 0;
- int cm_failed = 0;
- // ======================================================================
- void cmFailed(const char* Message, const char* m2= "", const char* m3 = "")
- {
- std::cout << "FAILED: " << Message << m2 << m3 << "\n";
- cm_failed++;
- }
- // ======================================================================
- void cmPassed(const char* Message, const char* m2="")
- {
- std::cout << "Passed: " << Message << m2 << "\n";
- cm_passed++;
- }
- #ifndef CMAKE_IS_REALLY_FUN
- This is a problem. Looks like ADD_DEFINITIONS and REMOVE_DEFINITIONS does not work
- #endif
- #ifndef CMAKE_TEST_DIFFERENT_GENERATOR
- // Here is a stupid function that tries to use std::string methods
- // so that the dec cxx compiler will instantiate the stuff that
- // we are using from the CMakeLib library....
- bool TestLibraryOrder(bool shouldFail)
- {
- std::string Adir = std::string(BINARY_DIR) + std::string("/A");
- std::string Bdir = std::string(BINARY_DIR) + std::string("/B");
- std::string Cdir = std::string(BINARY_DIR) + std::string("/C");
- #ifdef _WIN32
- // Avoid case problems for windows paths.
- if(Adir[0] >= 'A' && Adir[0] <= 'Z') { Adir[0] += 'a' - 'A'; }
- if(Bdir[0] >= 'A' && Bdir[0] <= 'Z') { Bdir[0] += 'a' - 'A'; }
- if(Cdir[0] >= 'A' && Cdir[0] <= 'Z') { Cdir[0] += 'a' - 'A'; }
- Adir = cmSystemTools::GetActualCaseForPath(Adir.c_str());
- Bdir = cmSystemTools::GetActualCaseForPath(Bdir.c_str());
- Cdir = cmSystemTools::GetActualCaseForPath(Cdir.c_str());
- #endif
-
- if(!shouldFail)
- {
- std::string rm = Bdir;
- rm += "/libA.a";
- cmSystemTools::RemoveFile(rm.c_str());
- }
- std::vector<std::string> linkLibraries;
- std::vector<std::string> linkDirectories;
- linkDirectories.push_back(Adir);
- linkDirectories.push_back(Bdir);
- linkDirectories.push_back(Cdir);
- linkDirectories.push_back("/lib/extra/stuff");
- Adir += "/libA.a";
- Bdir += "/libB.a";
- Cdir += "/libC.a";
- linkLibraries.push_back(Adir);
- linkLibraries.push_back(Bdir);
- linkLibraries.push_back(Cdir);
- linkLibraries.push_back("-lm");
- std::vector<cmStdString> sortedpaths;
- std::vector<cmStdString> linkItems;
- cmOrderLinkDirectories orderLibs;
- orderLibs.DebugOn();
- orderLibs.AddLinkExtension(".so");
- orderLibs.AddLinkExtension(".a");
- orderLibs.SetLinkPrefix("lib");
- orderLibs.SetLinkInformation("test", linkLibraries, linkDirectories);
- bool ret = orderLibs.DetermineLibraryPathOrder();
- orderLibs.GetLinkerInformation(sortedpaths, linkItems);
- std::cout << "Sorted Link Paths:\n";
- for(std::vector<cmStdString>::iterator i = sortedpaths.begin();
- i != sortedpaths.end(); ++i)
- {
- std::cout << *i << "\n";
- }
- std::cout << "Link Items: \n";
- for(std::vector<cmStdString>::iterator i = linkItems.begin();
- i != linkItems.end(); ++i)
- {
- std::cout << *i << "\n";
- }
- if(!(linkItems[0] == "A" &&
- linkItems[1] == "B" &&
- linkItems[2] == "C" &&
- linkItems[3] == "-lm" ))
- {
- std::cout << "fail because link items should be A B C -lm and the are not\n";
- return shouldFail;
- }
-
-
- // if this is not the fail test then the order should be f B C A
- if(!shouldFail)
- {
- char order[5];
- order[4] = 0;
- for(int i =0; i < 4; ++i)
- {
- order[i] = sortedpaths[i][sortedpaths[i].size()-1];
- }
- if(!(strcmp(order, "fBCA") == 0 || strcmp(order, "BCAf") == 0))
- {
- std::cout << "fail because order should be /lib/extra/stuff B C A and it is not\n";
- return false;
- }
- }
- return ret;
- }
- // ======================================================================
- void TestAndRemoveFile(const char* filename)
- {
- if (!cmSystemTools::FileExists(filename))
- {
- cmFailed("Could not find file: ", filename);
- }
- else
- {
- if (!cmSystemTools::RemoveFile(filename))
- {
- 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);
- }
- else
- {
- cmPassed("Find and remove file: ", filename);
- }
- }
- }
- // ======================================================================
- void TestDir(const char* filename)
- {
- if (!cmSystemTools::FileExists(filename))
- {
- cmFailed("Could not find dir: ", filename);
- }
- else
- {
- if (!cmSystemTools::FileIsDirectory(filename))
- {
- cmFailed("Unable to check if file is a directory: ", filename);
- }
- else
- {
- cmPassed("Find dir: ", filename);
- }
- }
- }
- // ======================================================================
- void TestCMGeneratedFileSTream()
- {
- cmGeneratedFileStream gm;
- std::string file1 = std::string(BINARY_DIR) + std::string("/generatedFile1");
- std::string file2 = std::string(BINARY_DIR) + std::string("/generatedFile2");
- std::string file3 = std::string(BINARY_DIR) + std::string("/generatedFile3");
- std::string file4 = std::string(BINARY_DIR) + std::string("/generatedFile4");
- std::string file1tmp = file1 + ".tmp";
- std::string file2tmp = file2 + ".tmp";
- std::string file3tmp = file3 + ".tmp";
- std::string file4tmp = file4 + ".tmp";
- gm.Open(file1.c_str());
- gm << "This is generated file 1";
- gm.Close();
- gm.Open(file2.c_str());
- gm << "This is generated file 2";
- gm.Close();
- gm.Open(file3.c_str());
- gm << "This is generated file 3";
- gm.Close();
- gm.Open(file4.c_str());
- gm << "This is generated file 4";
- gm.Close();
- if ( cmSystemTools::FileExists(file1.c_str()) )
- {
- if ( cmSystemTools::FileExists(file2.c_str()) )
- {
- if ( cmSystemTools::FileExists(file3.c_str()) )
- {
- if ( cmSystemTools::FileExists(file4.c_str()) )
- {
- if ( cmSystemTools::FileExists(file1tmp.c_str()) )
- {
- cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file1tmp.c_str());
- }
- else if ( cmSystemTools::FileExists(file2tmp.c_str()) )
- {
- cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file2tmp.c_str());
- }
- else if ( cmSystemTools::FileExists(file3tmp.c_str()) )
- {
- cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file3tmp.c_str());
- }
- else if ( cmSystemTools::FileExists(file4tmp.c_str()) )
- {
- cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file4tmp.c_str());
- }
- else
- {
- cmPassed("cmGeneratedFileStream works.");
- }
- }
- else
- {
- cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", file4.c_str());
- }
- }
- else
- {
- cmFailed("Something wrong with cmGeneratedFileStream. Found file: ", file3.c_str());
- }
- }
- else
- {
- cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", file2.c_str());
- }
- }
- else
- {
- cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", file1.c_str());
- }
- cmSystemTools::RemoveFile(file1.c_str());
- cmSystemTools::RemoveFile(file2.c_str());
- cmSystemTools::RemoveFile(file3.c_str());
- cmSystemTools::RemoveFile(file1tmp.c_str());
- cmSystemTools::RemoveFile(file2tmp.c_str());
- cmSystemTools::RemoveFile(file3tmp.c_str());
- }
- #endif
- void ForceStringUse()
- {
- std::vector<std::string> v;
- std::vector<std::string> v2;
- v = v2;
- std::string cachetest = CACHE_TEST_VAR_INTERNAL;
- v.push_back(cachetest);
- v2 = v;
- std::string x(5,'x');
- char buff[5];
- x.copy(buff, 1, 0);
- x[0] = 'a';
- std::string::size_type pos = 0;
- x.replace(pos, pos, pos, 'x');
- std::string copy = cachetest;
- cachetest.find("bar");
- cachetest.rfind("bar");
- copy.append(cachetest);
- copy = cachetest.substr(0, cachetest.size());
- }
- // defined in testcflags.c
- extern "C" int TestCFlags(char* m);
- extern "C" int TestTargetCompileFlags(char* m);
- // ======================================================================
- int main()
- {
- std::string lib = BINARY_DIR;
- lib += "/bin/";
- #ifdef CMAKE_INTDIR
- lib += CMAKE_INTDIR;
- lib += "/";
- #endif
- std::string exe = lib;
- #ifndef CMAKE_TEST_DIFFERENT_GENERATOR
- // Test a single character executable to test a: in makefiles
- exe += "A";
- exe += cmSystemTools::GetExecutableExtension();
- int ret;
- std::string errorMessage;
- exe = cmSystemTools::ConvertToRunCommandPath(exe.c_str());
- if(cmSystemTools::RunSingleCommand(exe.c_str(), 0, &ret))
- {
- if(ret != 10)
- {
- errorMessage += exe;
- errorMessage += " did not return 10";
- }
- }
- else
- {
- errorMessage += exe;
- errorMessage += ": failed to run.";
- }
- if(errorMessage.size())
- {
- cmFailed(errorMessage.c_str());
- }
- else
- {
- cmPassed("run Single Character executable A returned 10 as expected.");
- }
-
- lib += cmDynamicLoader::LibPrefix();
- lib += "CMakeTestModule";
- lib += cmDynamicLoader::LibExtension();
- cmsys::DynamicLoader::LibraryHandle handle = cmDynamicLoader::OpenLibrary(lib.c_str());
- if(!handle)
- {
- std::string err = "Can not open CMakeTestModule:\n";
- err += lib;
- cmFailed(err.c_str());
- }
- else
- {
- cmsys::DynamicLoader::SymbolPointer fun =
- cmsys::DynamicLoader::GetSymbolAddress(handle, "ModuleFunction");
- if(!fun)
- {
- fun = cmsys::DynamicLoader::GetSymbolAddress(handle, "_ModuleFunction");
- }
- typedef int (*TEST_FUNCTION)();
- TEST_FUNCTION testFun = (TEST_FUNCTION)fun;
- if(!testFun)
- {
- cmFailed("Could not find symbol ModuleFunction in library ");
- }
- else
- {
- int ret = (*testFun)();
- if(!ret)
- {
- cmFailed("ModuleFunction call did not return valid return.");
- }
- cmPassed("Module loaded and ModuleFunction called correctly.");
- }
- }
- if(sharedFunction() != 1)
- {
- cmFailed("Call to sharedFunction from shared library failed.");
- }
- else
- {
- cmPassed("Call to sharedFunction from shared library worked.");
- }
- if(CsharedFunction() != 1)
- {
- cmFailed("Call to C sharedFunction from shared library failed.");
- }
- else
- {
- cmPassed("Call to C sharedFunction from shared library worked.");
- }
-
- // ----------------------------------------------------------------------
- // Test cmSystemTools::UpperCase
- std::string str = "abc";
- std::string strupper = "ABC";
- if(cmSystemTools::UpperCase(str) == strupper)
- {
- cmPassed("cmSystemTools::UpperCase is working");
- }
- else
- {
- cmFailed("cmSystemTools::UpperCase is working");
- }
- #endif
-
- if(file1() != 1)
- {
- cmFailed("Call to file1 function from library failed.");
- }
- else
- {
- cmPassed("Call to file1 function returned 1.");
- }
- #ifndef COMPLEX_TARGET_FLAG
- cmFailed("COMPILE_FLAGS did not work with SET_TARGET_PROPERTIES");
- #else
- cmPassed("COMPILE_FLAGS did work with SET_TARGET_PROPERTIES");
- #endif
-
- if(file2() != 1)
- {
- cmFailed("Call to file2 function from library failed.");
- }
- else
- {
- cmPassed("Call to file2 function returned 1.");
- }
- #ifndef TEST_CXX_FLAGS
- cmFailed("CMake CMAKE_CXX_FLAGS is not being passed to the compiler!");
- #else
- cmPassed("CMake CMAKE_CXX_FLAGS is being passed to the compiler.");
- #endif
- std::string gen = CMAKE_GENERATOR;
- // visual studio is currently broken for c flags
- char msg[1024];
- if(gen.find("Visual") == gen.npos)
- {
- #ifdef TEST_C_FLAGS
- cmFailed("CMake CMAKE_C_FLAGS are being passed to c++ files the compiler!");
- #else
- cmPassed("CMake CMAKE_C_FLAGS are not being passed to c++ files.");
- #endif
- if(TestCFlags(msg))
- {
- cmPassed(
- "CMake CMAKE_C_FLAGS are being passed to c files and CXX flags are not.");
- }
- else
- {
- cmFailed(msg);
- }
- }
- if(TestTargetCompileFlags(msg))
- {
- cmPassed(msg);
- }
- else
- {
- cmFailed(msg);
- }
- // ----------------------------------------------------------------------
- // Test ADD_DEFINITIONS
- #ifndef CMAKE_IS_FUN
- cmFailed("CMake is not fun, so it is broken and should be fixed.");
- #else
- cmPassed("CMAKE_IS_FUN is defined.");
- #endif
-
- #if defined(CMAKE_ARGV1) && defined(CMAKE_ARGV2) && defined(CMAKE_ARGV3) && defined(CMAKE_ARGV4)
- cmPassed("Variable args for MACROs are working.");
- #else
- cmFailed("Variable args for MACROs are failing.");
- #endif
- // ----------------------------------------------------------------------
- // Test SET, VARIABLE_REQUIRES
- #ifdef SHOULD_NOT_BE_DEFINED
- cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED is defined.");
- #else
- cmPassed("SHOULD_NOT_BE_DEFINED is not defined.");
- #endif
-
- #ifndef SHOULD_BE_DEFINED
- cmFailed("IF or SET is broken, SHOULD_BE_DEFINED is not defined.\n");
- #else
- cmPassed("SHOULD_BE_DEFINED is defined.");
- #endif
-
- #ifndef ONE_VAR
- cmFailed("cmakedefine is broken, ONE_VAR is not defined.");
- #else
- cmPassed("ONE_VAR is defined.");
- #endif
-
- #ifndef ONE_VAR_IS_DEFINED
- cmFailed("cmakedefine, SET or VARIABLE_REQUIRES is broken, "
- "ONE_VAR_IS_DEFINED is not defined.");
- #else
- cmPassed("ONE_VAR_IS_DEFINED is defined.");
- #endif
-
- #ifdef ZERO_VAR
- cmFailed("cmakedefine is broken, ZERO_VAR is defined.");
- #else
- cmPassed("ZERO_VAR is not defined.");
- #endif
-
- #ifndef STRING_VAR
- cmFailed("the CONFIGURE_FILE command is broken, STRING_VAR is not defined.");
- #else
- if(strcmp(STRING_VAR, "CMake is great") != 0)
- {
- cmFailed("the SET or CONFIGURE_FILE command is broken. STRING_VAR == ",
- STRING_VAR);
- }
- else
- {
- cmPassed("STRING_VAR == ", STRING_VAR);
- }
- #endif
- // ----------------------------------------------------------------------
- // Test various IF/ELSE combinations
- #ifdef SHOULD_NOT_BE_DEFINED_NOT
- cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_NOT is defined.");
- #else
- cmPassed("SHOULD_NOT_BE_DEFINED_NOT is not defined.");
- #endif
-
- #ifndef SHOULD_BE_DEFINED_NOT
- cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_NOT is not defined.\n");
- #else
- cmPassed("SHOULD_BE_DEFINED_NOT is defined.");
- #endif
-
- #ifdef SHOULD_NOT_BE_DEFINED_NOT2
- cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_NOT2 is defined.");
- #else
- cmPassed("SHOULD_NOT_BE_DEFINED_NOT2 is not defined.");
- #endif
-
- #ifndef SHOULD_BE_DEFINED_NOT2
- cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_NOT2 is not defined.\n");
- #else
- cmPassed("SHOULD_BE_DEFINED_NOT2 is defined.");
- #endif
-
- #ifdef SHOULD_NOT_BE_DEFINED_AND
- cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_AND is defined.");
- #else
- cmPassed("SHOULD_NOT_BE_DEFINED_AND is not defined.");
- #endif
-
- #ifndef SHOULD_BE_DEFINED_AND
- cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_AND is not defined.\n");
- #else
- cmPassed("SHOULD_BE_DEFINED_AND is defined.");
- #endif
-
- #ifdef SHOULD_NOT_BE_DEFINED_AND2
- cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_AND2 is defined.");
- #else
- cmPassed("SHOULD_NOT_BE_DEFINED_AND2 is not defined.");
- #endif
-
- #ifndef SHOULD_BE_DEFINED_AND2
- cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_AND2 is not defined.\n");
- #else
- cmPassed("SHOULD_BE_DEFINED_AND2 is defined.");
- #endif
-
- #ifdef SHOULD_NOT_BE_DEFINED_OR
- cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_OR is defined.");
- #else
- cmPassed("SHOULD_NOT_BE_DEFINED_OR is not defined.");
- #endif
-
- #ifndef SHOULD_BE_DEFINED_OR
- cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_OR is not defined.\n");
- #else
- cmPassed("SHOULD_BE_DEFINED_OR is defined.");
- #endif
-
- #ifdef SHOULD_NOT_BE_DEFINED_OR2
- cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_OR2 is defined.");
- #else
- cmPassed("SHOULD_NOT_BE_DEFINED_OR2 is not defined.");
- #endif
-
- #ifndef SHOULD_BE_DEFINED_OR2
- cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_OR2 is not defined.\n");
- #else
- cmPassed("SHOULD_BE_DEFINED_OR2 is defined.");
- #endif
-
- #ifdef SHOULD_NOT_BE_DEFINED_MATCHES
- cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_MATCHES is defined.");
- #else
- cmPassed("SHOULD_NOT_BE_DEFINED_MATCHES is not defined.");
- #endif
-
- #ifndef SHOULD_BE_DEFINED_MATCHES
- cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_MATCHES is not defined.\n");
- #else
- cmPassed("SHOULD_BE_DEFINED_MATCHES is defined.");
- #endif
-
- #ifdef SHOULD_NOT_BE_DEFINED_MATCHES2
- cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_MATCHES2 is defined.");
- #else
- cmPassed("SHOULD_NOT_BE_DEFINED_MATCHES2 is not defined.");
- #endif
-
- #ifndef SHOULD_BE_DEFINED_MATCHES2
- cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_MATCHES2 is not defined.\n");
- #else
- cmPassed("SHOULD_BE_DEFINED_MATCHES2 is defined.");
- #endif
-
- #ifdef SHOULD_NOT_BE_DEFINED_COMMAND
- cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_COMMAND is defined.");
- #else
- cmPassed("SHOULD_NOT_BE_DEFINED_COMMAND is not defined.");
- #endif
-
- #ifndef SHOULD_BE_DEFINED_COMMAND
- cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_COMMAND is not defined.\n");
- #else
- cmPassed("SHOULD_BE_DEFINED_COMMAND is defined.");
- #endif
-
- #ifdef SHOULD_NOT_BE_DEFINED_COMMAND2
- cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_COMMAND2 is defined.");
- #else
- cmPassed("SHOULD_NOT_BE_DEFINED_COMMAND2 is not defined.");
- #endif
-
- #ifndef SHOULD_BE_DEFINED_COMMAND2
- cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_COMMAND2 is not defined.\n");
- #else
- cmPassed("SHOULD_BE_DEFINED_COMMAND2 is defined.");
- #endif
-
- #ifdef SHOULD_NOT_BE_DEFINED_EXISTS
- cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_EXISTS is defined.");
- #else
- cmPassed("SHOULD_NOT_BE_DEFINED_EXISTS is not defined.");
- #endif
-
- #ifndef SHOULD_BE_DEFINED_EXISTS
- cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_EXISTS is not defined.\n");
- #else
- cmPassed("SHOULD_BE_DEFINED_EXISTS is defined.");
- #endif
-
- #ifdef SHOULD_NOT_BE_DEFINED_EXISTS2
- cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_EXISTS2 is defined.");
- #else
- cmPassed("SHOULD_NOT_BE_DEFINED_EXISTS2 is not defined.");
- #endif
-
- #ifndef SHOULD_BE_DEFINED_EXISTS2
- cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_EXISTS2 is not defined.\n");
- #else
- cmPassed("SHOULD_BE_DEFINED_EXISTS2 is defined.");
- #endif
-
- #ifdef SHOULD_NOT_BE_DEFINED_LESS
- cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_LESS is defined.");
- #else
- cmPassed("SHOULD_NOT_BE_DEFINED_LESS is not defined.");
- #endif
-
- #ifndef SHOULD_BE_DEFINED_LESS
- cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_LESS is not defined.\n");
- #else
- cmPassed("SHOULD_BE_DEFINED_LESS is defined.");
- #endif
-
- #ifdef SHOULD_NOT_BE_DEFINED_LESS2
- cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_LESS2 is defined.");
- #else
- cmPassed("SHOULD_NOT_BE_DEFINED_LESS2 is not defined.");
- #endif
-
- #ifndef SHOULD_BE_DEFINED_LESS2
- cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_LESS2 is not defined.\n");
- #else
- cmPassed("SHOULD_BE_DEFINED_LESS2 is defined.");
- #endif
-
- #ifdef SHOULD_NOT_BE_DEFINED_GREATER
- cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_GREATER is defined.");
- #else
- cmPassed("SHOULD_NOT_BE_DEFINED_GREATER is not defined.");
- #endif
-
- #ifdef SHOULD_NOT_BE_DEFINED_EQUAL
- cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_EQUAL is defined.");
- #else
- cmPassed("SHOULD_NOT_BE_DEFINED_EQUAL is not defined.");
- #endif
- #ifndef SHOULD_BE_DEFINED_EQUAL
- cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_EQUAL is not defined.\n");
- #else
- cmPassed("SHOULD_BE_DEFINED_EQUAL is defined.");
- #endif
- #ifndef SHOULD_BE_DEFINED_GREATER
- cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_GREATER is not defined.\n");
- #else
- cmPassed("SHOULD_BE_DEFINED_GREATER is defined.");
- #endif
-
- #ifdef SHOULD_NOT_BE_DEFINED_GREATER2
- cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_GREATER2 is defined.");
- #else
- cmPassed("SHOULD_NOT_BE_DEFINED_GREATER2 is not defined.");
- #endif
-
- #ifndef SHOULD_BE_DEFINED_GREATER2
- cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_GREATER2 is not defined.\n");
- #else
- cmPassed("SHOULD_BE_DEFINED_GREATER2 is defined.");
- #endif
-
- #ifdef SHOULD_NOT_BE_DEFINED_STRLESS
- cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRLESS is defined.");
- #else
- cmPassed("SHOULD_NOT_BE_DEFINED_STRLESS is not defined.");
- #endif
-
- #ifndef SHOULD_BE_DEFINED_STRLESS
- cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRLESS is not defined.\n");
- #else
- cmPassed("SHOULD_BE_DEFINED_STRLESS is defined.");
- #endif
-
- #ifdef SHOULD_NOT_BE_DEFINED_STRLESS2
- cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRLESS2 is defined.");
- #else
- cmPassed("SHOULD_NOT_BE_DEFINED_STRLESS2 is not defined.");
- #endif
-
- #ifndef SHOULD_BE_DEFINED_STRLESS2
- cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRLESS2 is not defined.\n");
- #else
- cmPassed("SHOULD_BE_DEFINED_STRLESS2 is defined.");
- #endif
-
- #ifdef SHOULD_NOT_BE_DEFINED_STRGREATER
- cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRGREATER is defined.");
- #else
- cmPassed("SHOULD_NOT_BE_DEFINED_STRGREATER is not defined.");
- #endif
-
- #ifndef SHOULD_BE_DEFINED_STRGREATER
- cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRGREATER is not defined.\n");
- #else
- cmPassed("SHOULD_BE_DEFINED_STRGREATER is defined.");
- #endif
-
- #ifdef SHOULD_NOT_BE_DEFINED_STRGREATER2
- cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRGREATER2 is defined.");
- #else
- cmPassed("SHOULD_NOT_BE_DEFINED_STRGREATER2 is not defined.");
- #endif
-
- #ifndef SHOULD_BE_DEFINED_STRGREATER2
- cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRGREATER2 is not defined.\n");
- #else
- cmPassed("SHOULD_BE_DEFINED_STRGREATER2 is defined.");
- #endif
-
- // ----------------------------------------------------------------------
- // Test FOREACH
- #ifndef FOREACH_VAR1
- cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
- "FOREACH_VAR1 is not defined.");
- #else
- if(strcmp(FOREACH_VAR1, "VALUE1") != 0)
- {
- cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
- "FOREACH_VAR1 == ", FOREACH_VAR1);
- }
- else
- {
- cmPassed("FOREACH_VAR1 == ", FOREACH_VAR1);
- }
- #endif
- #ifndef FOREACH_VAR2
- cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
- "FOREACH_VAR2 is not defined.");
- #else
- if(strcmp(FOREACH_VAR2, "VALUE2") != 0)
- {
- cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
- "FOREACH_VAR2 == ", FOREACH_VAR2);
- }
- else
- {
- cmPassed("FOREACH_VAR2 == ", FOREACH_VAR2);
- }
- #endif
- #ifndef FOREACH_CONCAT
- cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
- "FOREACH_CONCAT is not defined.");
- #else
- if(strcmp(FOREACH_CONCAT, "abcdefg") != 0)
- {
- cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
- "FOREACH_CONCAT == ", FOREACH_CONCAT);
- }
- else
- {
- cmPassed("FOREACH_CONCAT == ", FOREACH_CONCAT);
- }
- #endif
- // ----------------------------------------------------------------------
- // Test WHILE
-
- if(WHILE_VALUE != 1000)
- {
- cmFailed("WHILE command is not working");
- }
- else
- {
- cmPassed("WHILE command is working");
- }
- // ----------------------------------------------------------------------
- // Test FIND_FILE, FIND_PATH and various GET_FILENAME_COMPONENT combinations
- #ifndef FILENAME_VAR_PATH_NAME
- cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
- "FILENAME_VAR_PATH_NAME is not defined.");
- #else
- if((strcmp(FILENAME_VAR_PATH_NAME, "Complex") == 0) ||
- (strcmp(FILENAME_VAR_PATH_NAME, "ComplexOneConfig") == 0) ||
- (strcmp(FILENAME_VAR_PATH_NAME, "ComplexRelativePaths") == 0))
- {
- cmPassed("FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME);
- }
- else
- {
- cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
- "FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME);
- }
- #endif
- #ifndef FILENAME_VAR_NAME
- cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
- "FILENAME_VAR_NAME is not defined.");
- #else
- if(strcmp(FILENAME_VAR_NAME, "VarTests.cmake") != 0)
- {
- cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
- "FILENAME_VAR_NAME == ", FILENAME_VAR_NAME);
- }
- else
- {
- cmPassed("FILENAME_VAR_NAME == ", FILENAME_VAR_NAME);
- }
- #endif
- #ifndef FILENAME_VAR_EXT
- cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
- "FILENAME_VAR_EXT is not defined.");
- #else
- if(strcmp(FILENAME_VAR_EXT, ".cmake") != 0)
- {
- cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
- "FILENAME_VAR_EXT == ", FILENAME_VAR_EXT);
- }
- else
- {
- cmPassed("FILENAME_VAR_EXT == ", FILENAME_VAR_EXT);
- }
- #endif
- #ifndef FILENAME_VAR_NAME_WE
- cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
- "FILENAME_VAR_NAME_WE is not defined.");
- #else
- if(strcmp(FILENAME_VAR_NAME_WE, "VarTests") != 0)
- {
- cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
- "FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE);
- }
- else
- {
- cmPassed("FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE);
- }
- #endif
- #ifndef PATH_VAR_NAME
- cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
- "PATH_VAR_NAME is not defined.");
- #else
- if((strcmp(PATH_VAR_NAME, "Complex") == 0) ||
- (strcmp(PATH_VAR_NAME, "ComplexOneConfig") == 0) ||
- (strcmp(PATH_VAR_NAME, "ComplexRelativePaths") == 0))
- {
- cmPassed("PATH_VAR_NAME == ", PATH_VAR_NAME);
- }
- else
- {
- cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
- "PATH_VAR_NAME == ", PATH_VAR_NAME);
- }
- #endif
- // ----------------------------------------------------------------------
- // Test LOAD_CACHE
- #ifndef CACHE_TEST_VAR1
- cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
- "CACHE_TEST_VAR1 is not defined.");
- #else
- if(strcmp(CACHE_TEST_VAR1, "foo") != 0)
- {
- cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
- "CACHE_TEST_VAR1 == ", CACHE_TEST_VAR1);
- }
- else
- {
- cmPassed("CACHE_TEST_VAR1 == ", CACHE_TEST_VAR1);
- }
- #endif
- #ifndef CACHE_TEST_VAR2
- cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
- "CACHE_TEST_VAR2 is not defined.");
- #else
- if(strcmp(CACHE_TEST_VAR2, "bar") != 0)
- {
- cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
- "CACHE_TEST_VAR2 == ", CACHE_TEST_VAR2);
- }
- else
- {
- cmPassed("CACHE_TEST_VAR2 == ", CACHE_TEST_VAR2);
- }
- #endif
- #ifndef CACHE_TEST_VAR3
- cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
- "CACHE_TEST_VAR3 is not defined.");
- #else
- if(strcmp(CACHE_TEST_VAR3, "1") != 0)
- {
- cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
- "CACHE_TEST_VAR3 == ", CACHE_TEST_VAR3);
- }
- else
- {
- cmPassed("CACHE_TEST_VAR3 == ", CACHE_TEST_VAR3);
- }
- #endif
- #ifdef CACHE_TEST_VAR_EXCLUDED
- cmFailed("the LOAD_CACHE or CONFIGURE_FILE command or cmakedefine is broken, "
- "CACHE_TEST_VAR_EXCLUDED is defined (should not have been loaded).");
- #else
- cmPassed("CACHE_TEST_VAR_EXCLUDED is not defined.");
- #endif
- #ifndef CACHE_TEST_VAR_INTERNAL
- cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
- "CACHE_TEST_VAR_INTERNAL is not defined.");
- #else
- std::string cachetest = CACHE_TEST_VAR_INTERNAL;
- if(cachetest != "bar")
- {
- cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
- "CACHE_TEST_VAR_INTERNAL == ", CACHE_TEST_VAR_INTERNAL);
- }
- else
- {
- cmPassed("CACHE_TEST_VAR_INTERNAL == ", CACHE_TEST_VAR_INTERNAL);
- }
- #endif
- #ifndef CMAKE_TEST_DIFFERENT_GENERATOR
- // ----------------------------------------------------------------------
- // Some pre-build/pre-link/post-build custom-commands have been
- // attached to the lib (see Library/).
- // Each runs ${CREATE_FILE_EXE} which will create a file.
- // It also copies that file again using cmake -E.
- // Similar rules have been added to this executable.
- //
- // WARNING: if you run 'complex' manually, this *will* fail, because
- // the file was removed the last time 'complex' was run, and it is
- // only created during a build.
- TestAndRemoveFile(BINARY_DIR "/Library/prebuild.txt");
- TestAndRemoveFile(BINARY_DIR "/Library/prelink.txt");
- TestAndRemoveFile(BINARY_DIR "/Library/postbuild.txt");
- TestAndRemoveFile(BINARY_DIR "/Library/postbuild2.txt");
- TestAndRemoveFile(BINARY_DIR "/Executable/prebuild.txt");
- TestAndRemoveFile(BINARY_DIR "/Executable/prelink.txt");
- TestAndRemoveFile(BINARY_DIR "/Executable/postbuild.txt");
- TestAndRemoveFile(BINARY_DIR "/Executable/postbuild2.txt");
- // ----------------------------------------------------------------------
- // A custom target has been created (see Library/).
- // It runs ${CREATE_FILE_EXE} which will create a file.
- //
- // WARNING: if you run 'complex' manually, this *will* fail, because
- // the file was removed the last time 'complex' was run, and it is
- // only created during a build.
- TestAndRemoveFile(BINARY_DIR "/Library/custom_target1.txt");
-
- // ----------------------------------------------------------------------
- // A directory has been created.
- TestDir(BINARY_DIR "/make_dir");
- // ----------------------------------------------------------------------
- // Test OUTPUT_REQUIRED_FILES
- // The files required by 'complex' have been output to a file.
- // The contents of this file is not tested (absolute paths).
- //
- // WARNING: if you run 'complex' manually, this *will* fail, because
- // the file was removed the last time 'complex' was run, and it is
- // only created during a build.
- TestAndRemoveFile(BINARY_DIR "/Executable/Temp/complex-required.txt");
- #endif
- // ----------------------------------------------------------------------
- // Test FIND_LIBRARY
- #ifndef FIND_DUMMY_LIB
- cmFailed("the CONFIGURE_FILE command is broken, "
- "FIND_DUMMY_LIB is not defined.");
- #else
- if(strstr(FIND_DUMMY_LIB, "dummylib") == NULL)
- {
- cmFailed("the FIND_LIBRARY or CONFIGURE_FILE command is broken, "
- "FIND_DUMMY_LIB == ", FIND_DUMMY_LIB);
- }
- else
- {
- cmPassed("FIND_DUMMY_LIB == ", FIND_DUMMY_LIB);
- }
- #endif
- // ----------------------------------------------------------------------
- // Test SET_SOURCE_FILES_PROPERTIES
- #ifndef FILE_HAS_EXTRA_COMPILE_FLAGS
- cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting FILE_HAS_EXTRA_COMPILE_FLAGS flag");
- #else
- cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting FILE_HAS_EXTRA_COMPILE_FLAGS flag");
- #endif
- #ifndef FILE_HAS_ABSTRACT
- cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting ABSTRACT flag");
- #else
- cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting ABSTRACT flag");
- #endif
- #ifndef FILE_HAS_WRAP_EXCLUDE
- cmFailed("FILE_HAS_WRAP_EXCLUDE failed at setting WRAP_EXCLUDE flag");
- #else
- cmPassed("FILE_HAS_WRAP_EXCLUDE succeeded in setting WRAP_EXCLUDE flag");
- #endif
- #ifndef FILE_COMPILE_FLAGS
- cmFailed("the CONFIGURE_FILE command is broken, FILE_COMPILE_FLAGS is not defined.");
- #else
- if(strcmp(FILE_COMPILE_FLAGS, "-foo -bar") != 0)
- {
- cmFailed("the SET_SOURCE_FILES_PROPERTIES or CONFIGURE_FILE command is broken. FILE_COMPILE_FLAGS == ",
- FILE_COMPILE_FLAGS);
- }
- else
- {
- cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting extra flags == ", FILE_COMPILE_FLAGS);
- }
- #endif
- // ----------------------------------------------------------------------
- // Test registry (win32)
- #if defined(_WIN32) && !defined(__CYGWIN__)
- #ifndef REGISTRY_TEST_PATH
- cmFailed("the CONFIGURE_FILE command is broken, REGISTRY_TEST_PATH is not defined.");
- #else
- std::cout << "REGISTRY_TEST_PATH == " << REGISTRY_TEST_PATH << "\n";
- if(stricmp(REGISTRY_TEST_PATH, BINARY_DIR "/registry_dir") != 0)
- {
- cmFailed("the 'read registry value' function or CONFIGURE_FILE command is broken. REGISTRY_TEST_PATH == ",
- REGISTRY_TEST_PATH, " is not " BINARY_DIR "/registry_dir");
- }
- else
- {
- cmPassed("REGISTRY_TEST_PATH == ", REGISTRY_TEST_PATH);
- }
- #endif
- #endif // defined(_WIN32) && !defined(__CYGWIN__)
- if(strcmp(CMAKE_MINIMUM_REQUIRED_VERSION, "1.3") == 0)
- {
- cmPassed("CMAKE_MINIMUM_REQUIRED_VERSION is set to 1.3");
- }
- else
- {
- cmFailed("CMAKE_MINIMUM_REQUIRED_VERSION is not set to the expected 1.3");
- }
- // ----------------------------------------------------------------------
- // Test REMOVE command
- if (strcmp("a;b;d",REMOVE_STRING) == 0)
- {
- cmPassed("REMOVE is working");
- }
- else
- {
- cmFailed("REMOVE is not working");
- }
-
- // ----------------------------------------------------------------------
- // Test SEPARATE_ARGUMENTS
- if(strcmp("a;b;c", TEST_SEP) == 0)
- {
- cmPassed("SEPARATE_ARGUMENTS is working");
- }
- else
- {
- cmFailed("SEPARATE_ARGUMENTS is not working");
- }
-
- // ----------------------------------------------------------------------
- // Test Escape Quotes
- if(strcmp("\"hello world\"", STRING_WITH_QUOTES) == 0)
- {
- cmPassed("ESCAPE_QUOTES is working");
- }
- else
- {
- cmFailed("ESCAPE_QUOTES is not working");
- }
-
-
- // ----------------------------------------------------------------------
- // Test if IF command inside a FOREACH works.
- #if defined(IF_INSIDE_FOREACH_THEN_EXECUTED) && !defined(IF_INSIDE_FOREACH_ELSE_EXECUTED)
- cmPassed("IF inside a FOREACH block works");
- #else
- cmFailed("IF inside a FOREACH block is broken");
- #endif
- #if defined(GENERATED_HEADER_INCLUDED)
- cmPassed("Generated header included by non-generated source works.");
- #else
- cmFailed("Generated header included by non-generated source failed.");
- #endif
- if(SHOULD_BE_ZERO == 0)
- {
- cmPassed("cmakedefine01 is working for 0");
- }
- else
- {
- cmFailed("cmakedefine01 is not working for 0");
- }
- if(SHOULD_BE_ONE == 1)
- {
- cmPassed("cmakedefine01 is working for 1");
- }
- else
- {
- cmFailed("cmakedefine01 is not working for 1");
- }
- #ifdef FORCE_TEST
- cmFailed("CMake SET CACHE FORCE");
- #else
- cmPassed("CMake SET CACHE FORCE");
- #endif
- #ifndef CMAKE_TEST_DIFFERENT_GENERATOR
- // first run with shouldFail = true, this will
- // run with A B C as set by the CMakeList.txt file.
- if(!TestLibraryOrder(true))
- {
- cmPassed("CMake cmOrderLinkDirectories failed when it should.");
- }
- else
- {
- cmFailed("CMake cmOrderLinkDirectories failed to fail when given an impossible set of paths.");
- }
- // next run with shouldPass = true, this will
- // run with B/libA.a removed and should create the order
- // B C A
- if(TestLibraryOrder(false))
- {
- cmPassed("CMake cmOrderLinkDirectories worked.");
- }
- else
- {
- cmFailed("CMake cmOrderLinkDirectories failed.");
- }
- // Test the generated file stream.
- TestCMGeneratedFileSTream();
- #endif
-
- // ----------------------------------------------------------------------
- // Summary
- std::cout << "Passed: " << cm_passed << "\n";
- if(cm_failed)
- {
- std::cout << "Failed: " << cm_failed << "\n";
- return cm_failed;
- }
- return 0;
- }
|