complex.cxx 37 KB

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