complex.cxx 38 KB

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