complex.cxx 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  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. #include "cmStandardIncludes.h"
  12. #include "cmSystemTools.h"
  13. #include "cmDynamicLoader.h"
  14. #include "cmSystemTools.h"
  15. #include "cmOrderLinkDirectories.h"
  16. int cm_passed = 0;
  17. int cm_failed = 0;
  18. #ifndef CMAKE_IS_REALLY_FUN
  19. This is a problem. Looks like ADD_DEFINITIONS and REMOVE_DEFINITIONS does not work
  20. #endif
  21. // Here is a stupid function that tries to use std::string methods
  22. // so that the dec cxx compiler will instantiate the stuff that
  23. // we are using from the CMakeLib library....
  24. bool TestLibraryOrder(bool shouldFail)
  25. {
  26. std::string Adir = std::string(BINARY_DIR) + std::string("/A");
  27. std::string Bdir = std::string(BINARY_DIR) + std::string("/B");
  28. std::string Cdir = std::string(BINARY_DIR) + std::string("/C");
  29. if(!shouldFail)
  30. {
  31. std::string rm = Bdir;
  32. rm += "/libA.a";
  33. cmSystemTools::RemoveFile(rm.c_str());
  34. }
  35. cmTarget target;
  36. target.AddLinkDirectory(Adir.c_str());
  37. target.AddLinkDirectory(Bdir.c_str());
  38. target.AddLinkDirectory(Cdir.c_str());
  39. target.AddLinkDirectory("/lib/extra/stuff");
  40. Adir += "/libA.a";
  41. Bdir += "/libB.a";
  42. Cdir += "/libC.a";
  43. target.AddLinkLibrary(Adir.c_str(), cmTarget::GENERAL);
  44. target.AddLinkLibrary(Bdir.c_str(), cmTarget::GENERAL);
  45. target.AddLinkLibrary(Cdir.c_str(), cmTarget::GENERAL);
  46. target.AddLinkLibrary("-lm", cmTarget::GENERAL);
  47. std::vector<cmStdString> sortedpaths;
  48. std::vector<cmStdString> linkItems;
  49. cmOrderLinkDirectories orderLibs;
  50. orderLibs.DebugOn();
  51. orderLibs.AddLinkExtension(".so");
  52. orderLibs.AddLinkExtension(".a");
  53. orderLibs.SetLinkInformation(target, cmTarget::GENERAL, "A");
  54. bool ret = orderLibs.DetermineLibraryPathOrder();
  55. orderLibs.GetLinkerInformation(sortedpaths, linkItems);
  56. std::cout << "Sorted Link Paths:\n";
  57. for(std::vector<cmStdString>::iterator i = sortedpaths.begin();
  58. i != sortedpaths.end(); ++i)
  59. {
  60. std::cout << *i << "\n";
  61. }
  62. std::cout << "Link Items: \n";
  63. for(std::vector<cmStdString>::iterator i = linkItems.begin();
  64. i != linkItems.end(); ++i)
  65. {
  66. std::cout << *i << "\n";
  67. }
  68. if(!(linkItems[0] == "A" &&
  69. linkItems[1] == "B" &&
  70. linkItems[2] == "C" &&
  71. linkItems[3] == "-lm" ))
  72. {
  73. std::cout << "fail because link items should be A B C -lm and the are not\n";
  74. return shouldFail;
  75. }
  76. // if this is not the fail test then the order should be f B C A
  77. if(!shouldFail)
  78. {
  79. char order[5];
  80. order[4] = 0;
  81. for(int i =0; i < 4; ++i)
  82. {
  83. order[i] = sortedpaths[i][sortedpaths[i].size()-1];
  84. }
  85. if(!(strcmp(order, "fBCA") == 0 || strcmp(order, "BCAf") == 0))
  86. {
  87. std::cout << "fail because order should be /lib/extra/stuff B C A and it is not\n";
  88. return false;
  89. }
  90. }
  91. return ret;
  92. }
  93. void ForceStringUse()
  94. {
  95. std::vector<std::string> v;
  96. std::vector<std::string> v2;
  97. v = v2;
  98. std::string cachetest = CACHE_TEST_VAR_INTERNAL;
  99. v.push_back(cachetest);
  100. v2 = v;
  101. std::string x(5,'x');
  102. char buff[5];
  103. x.copy(buff, 1, 0);
  104. x[0] = 'a';
  105. std::string::size_type pos = 0;
  106. x.replace(pos, pos, pos, 'x');
  107. std::string copy = cachetest;
  108. cachetest.find("bar");
  109. cachetest.rfind("bar");
  110. copy.append(cachetest);
  111. copy = cachetest.substr(0, cachetest.size());
  112. }
  113. // ======================================================================
  114. void cmFailed(const char* Message, const char* m2= "", const char* m3 = "")
  115. {
  116. std::cout << "FAILED: " << Message << m2 << m3 << "\n";
  117. cm_failed++;
  118. }
  119. // ======================================================================
  120. void cmPassed(const char* Message, const char* m2="")
  121. {
  122. std::cout << "Passed: " << Message << m2 << "\n";
  123. cm_passed++;
  124. }
  125. // ======================================================================
  126. void TestAndRemoveFile(const char* filename)
  127. {
  128. if (!cmSystemTools::FileExists(filename))
  129. {
  130. cmFailed("Could not find file: ", filename);
  131. }
  132. else
  133. {
  134. if (!cmSystemTools::RemoveFile(filename))
  135. {
  136. 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);
  137. }
  138. else
  139. {
  140. cmPassed("Find and remove file: ", filename);
  141. }
  142. }
  143. }
  144. // ======================================================================
  145. void TestDir(const char* filename)
  146. {
  147. if (!cmSystemTools::FileExists(filename))
  148. {
  149. cmFailed("Could not find dir: ", filename);
  150. }
  151. else
  152. {
  153. if (!cmSystemTools::FileIsDirectory(filename))
  154. {
  155. cmFailed("Unable to check if file is a directory: ", filename);
  156. }
  157. else
  158. {
  159. cmPassed("Find dir: ", filename);
  160. }
  161. }
  162. }
  163. // ======================================================================
  164. int main()
  165. {
  166. std::string lib = BINARY_DIR;
  167. lib += "/bin/";
  168. #ifdef CMAKE_INTDIR
  169. lib += CMAKE_INTDIR;
  170. lib += "/";
  171. #endif
  172. std::string exe = lib;
  173. // Test a single character executable to test a: in makefiles
  174. exe += "A";
  175. exe += cmSystemTools::GetExecutableExtension();
  176. int ret;
  177. std::string errorMessage;
  178. exe = cmSystemTools::ConvertToRunCommandPath(exe.c_str());
  179. if(cmSystemTools::RunSingleCommand(exe.c_str(), 0, &ret))
  180. {
  181. if(ret != 10)
  182. {
  183. errorMessage += exe;
  184. errorMessage += " did not return 10";
  185. }
  186. }
  187. else
  188. {
  189. errorMessage += exe;
  190. errorMessage += ": failed to run.";
  191. }
  192. if(errorMessage.size())
  193. {
  194. cmFailed(errorMessage.c_str());
  195. }
  196. else
  197. {
  198. cmPassed("run Single Character executable A returned 10 as expected.");
  199. }
  200. lib += cmDynamicLoader::LibPrefix();
  201. lib += "CMakeTestModule";
  202. lib += cmDynamicLoader::LibExtension();
  203. cmLibHandle handle = cmDynamicLoader::OpenLibrary(lib.c_str());
  204. if(!handle)
  205. {
  206. std::string err = "Can not open CMakeTestModule:\n";
  207. err += lib;
  208. cmFailed(err.c_str());
  209. }
  210. else
  211. {
  212. cmDynamicLoaderFunction fun =
  213. cmDynamicLoader::GetSymbolAddress(handle, "ModuleFunction");
  214. if(!fun)
  215. {
  216. fun = cmDynamicLoader::GetSymbolAddress(handle, "_ModuleFunction");
  217. }
  218. typedef int (*TEST_FUNCTION)();
  219. TEST_FUNCTION testFun = (TEST_FUNCTION)fun;
  220. if(!testFun)
  221. {
  222. cmFailed("Could not find symbol ModuleFunction in library ");
  223. }
  224. else
  225. {
  226. int ret = (*testFun)();
  227. if(!ret)
  228. {
  229. cmFailed("ModuleFunction call did not return valid return.");
  230. }
  231. cmPassed("Module loaded and ModuleFunction called correctly.");
  232. }
  233. }
  234. if(sharedFunction() != 1)
  235. {
  236. cmFailed("Call to sharedFunction from shared library failed.");
  237. }
  238. else
  239. {
  240. cmPassed("Call to sharedFunction from shared library worked.");
  241. }
  242. if(CsharedFunction() != 1)
  243. {
  244. cmFailed("Call to C sharedFunction from shared library failed.");
  245. }
  246. else
  247. {
  248. cmPassed("Call to C sharedFunction from shared library worked.");
  249. }
  250. if(file1() != 1)
  251. {
  252. cmFailed("Call to file1 function from library failed.");
  253. }
  254. else
  255. {
  256. cmPassed("Call to file1 function returned 1.");
  257. }
  258. if(file2() != 1)
  259. {
  260. cmFailed("Call to file2 function from library failed.");
  261. }
  262. else
  263. {
  264. cmPassed("Call to file2 function returned 1.");
  265. }
  266. #ifndef TEST_CXX_FLAGS
  267. cmFailed("CMake CMAKE_CXX_FLAGS is not being passed to the compiler!");
  268. #else
  269. cmPassed("CMake CMAKE_CXX_FLAGS is being passed to the compiler.");
  270. #endif
  271. // ----------------------------------------------------------------------
  272. // Test ADD_DEFINITIONS
  273. #ifndef CMAKE_IS_FUN
  274. cmFailed("CMake is not fun, so it is broken and should be fixed.");
  275. #else
  276. cmPassed("CMAKE_IS_FUN is defined.");
  277. #endif
  278. #if defined(CMAKE_ARGV1) && defined(CMAKE_ARGV2) && defined(CMAKE_ARGV3) && defined(CMAKE_ARGV4)
  279. cmPassed("Variable args for MACROs are working.");
  280. #else
  281. cmFailed("Variable args for MACROs are failing.");
  282. #endif
  283. // ----------------------------------------------------------------------
  284. // Test SET, VARIABLE_REQUIRES
  285. #ifdef SHOULD_NOT_BE_DEFINED
  286. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED is defined.");
  287. #else
  288. cmPassed("SHOULD_NOT_BE_DEFINED is not defined.");
  289. #endif
  290. #ifndef SHOULD_BE_DEFINED
  291. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED is not defined.\n");
  292. #else
  293. cmPassed("SHOULD_BE_DEFINED is defined.");
  294. #endif
  295. #ifndef ONE_VAR
  296. cmFailed("cmakedefine is broken, ONE_VAR is not defined.");
  297. #else
  298. cmPassed("ONE_VAR is defined.");
  299. #endif
  300. #ifndef ONE_VAR_IS_DEFINED
  301. cmFailed("cmakedefine, SET or VARIABLE_REQUIRES is broken, "
  302. "ONE_VAR_IS_DEFINED is not defined.");
  303. #else
  304. cmPassed("ONE_VAR_IS_DEFINED is defined.");
  305. #endif
  306. #ifdef ZERO_VAR
  307. cmFailed("cmakedefine is broken, ZERO_VAR is defined.");
  308. #else
  309. cmPassed("ZERO_VAR is not defined.");
  310. #endif
  311. #ifndef STRING_VAR
  312. cmFailed("the CONFIGURE_FILE command is broken, STRING_VAR is not defined.");
  313. #else
  314. if(strcmp(STRING_VAR, "CMake is great") != 0)
  315. {
  316. cmFailed("the SET or CONFIGURE_FILE command is broken. STRING_VAR == ",
  317. STRING_VAR);
  318. }
  319. else
  320. {
  321. cmPassed("STRING_VAR == ", STRING_VAR);
  322. }
  323. #endif
  324. // ----------------------------------------------------------------------
  325. // Test various IF/ELSE combinations
  326. #ifdef SHOULD_NOT_BE_DEFINED_NOT
  327. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_NOT is defined.");
  328. #else
  329. cmPassed("SHOULD_NOT_BE_DEFINED_NOT is not defined.");
  330. #endif
  331. #ifndef SHOULD_BE_DEFINED_NOT
  332. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_NOT is not defined.\n");
  333. #else
  334. cmPassed("SHOULD_BE_DEFINED_NOT is defined.");
  335. #endif
  336. #ifdef SHOULD_NOT_BE_DEFINED_NOT2
  337. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_NOT2 is defined.");
  338. #else
  339. cmPassed("SHOULD_NOT_BE_DEFINED_NOT2 is not defined.");
  340. #endif
  341. #ifndef SHOULD_BE_DEFINED_NOT2
  342. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_NOT2 is not defined.\n");
  343. #else
  344. cmPassed("SHOULD_BE_DEFINED_NOT2 is defined.");
  345. #endif
  346. #ifdef SHOULD_NOT_BE_DEFINED_AND
  347. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_AND is defined.");
  348. #else
  349. cmPassed("SHOULD_NOT_BE_DEFINED_AND is not defined.");
  350. #endif
  351. #ifndef SHOULD_BE_DEFINED_AND
  352. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_AND is not defined.\n");
  353. #else
  354. cmPassed("SHOULD_BE_DEFINED_AND is defined.");
  355. #endif
  356. #ifdef SHOULD_NOT_BE_DEFINED_AND2
  357. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_AND2 is defined.");
  358. #else
  359. cmPassed("SHOULD_NOT_BE_DEFINED_AND2 is not defined.");
  360. #endif
  361. #ifndef SHOULD_BE_DEFINED_AND2
  362. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_AND2 is not defined.\n");
  363. #else
  364. cmPassed("SHOULD_BE_DEFINED_AND2 is defined.");
  365. #endif
  366. #ifdef SHOULD_NOT_BE_DEFINED_OR
  367. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_OR is defined.");
  368. #else
  369. cmPassed("SHOULD_NOT_BE_DEFINED_OR is not defined.");
  370. #endif
  371. #ifndef SHOULD_BE_DEFINED_OR
  372. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_OR is not defined.\n");
  373. #else
  374. cmPassed("SHOULD_BE_DEFINED_OR is defined.");
  375. #endif
  376. #ifdef SHOULD_NOT_BE_DEFINED_OR2
  377. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_OR2 is defined.");
  378. #else
  379. cmPassed("SHOULD_NOT_BE_DEFINED_OR2 is not defined.");
  380. #endif
  381. #ifndef SHOULD_BE_DEFINED_OR2
  382. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_OR2 is not defined.\n");
  383. #else
  384. cmPassed("SHOULD_BE_DEFINED_OR2 is defined.");
  385. #endif
  386. #ifdef SHOULD_NOT_BE_DEFINED_MATCHES
  387. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_MATCHES is defined.");
  388. #else
  389. cmPassed("SHOULD_NOT_BE_DEFINED_MATCHES is not defined.");
  390. #endif
  391. #ifndef SHOULD_BE_DEFINED_MATCHES
  392. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_MATCHES is not defined.\n");
  393. #else
  394. cmPassed("SHOULD_BE_DEFINED_MATCHES is defined.");
  395. #endif
  396. #ifdef SHOULD_NOT_BE_DEFINED_MATCHES2
  397. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_MATCHES2 is defined.");
  398. #else
  399. cmPassed("SHOULD_NOT_BE_DEFINED_MATCHES2 is not defined.");
  400. #endif
  401. #ifndef SHOULD_BE_DEFINED_MATCHES2
  402. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_MATCHES2 is not defined.\n");
  403. #else
  404. cmPassed("SHOULD_BE_DEFINED_MATCHES2 is defined.");
  405. #endif
  406. #ifdef SHOULD_NOT_BE_DEFINED_COMMAND
  407. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_COMMAND is defined.");
  408. #else
  409. cmPassed("SHOULD_NOT_BE_DEFINED_COMMAND is not defined.");
  410. #endif
  411. #ifndef SHOULD_BE_DEFINED_COMMAND
  412. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_COMMAND is not defined.\n");
  413. #else
  414. cmPassed("SHOULD_BE_DEFINED_COMMAND is defined.");
  415. #endif
  416. #ifdef SHOULD_NOT_BE_DEFINED_COMMAND2
  417. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_COMMAND2 is defined.");
  418. #else
  419. cmPassed("SHOULD_NOT_BE_DEFINED_COMMAND2 is not defined.");
  420. #endif
  421. #ifndef SHOULD_BE_DEFINED_COMMAND2
  422. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_COMMAND2 is not defined.\n");
  423. #else
  424. cmPassed("SHOULD_BE_DEFINED_COMMAND2 is defined.");
  425. #endif
  426. #ifdef SHOULD_NOT_BE_DEFINED_EXISTS
  427. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_EXISTS is defined.");
  428. #else
  429. cmPassed("SHOULD_NOT_BE_DEFINED_EXISTS is not defined.");
  430. #endif
  431. #ifndef SHOULD_BE_DEFINED_EXISTS
  432. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_EXISTS is not defined.\n");
  433. #else
  434. cmPassed("SHOULD_BE_DEFINED_EXISTS is defined.");
  435. #endif
  436. #ifdef SHOULD_NOT_BE_DEFINED_EXISTS2
  437. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_EXISTS2 is defined.");
  438. #else
  439. cmPassed("SHOULD_NOT_BE_DEFINED_EXISTS2 is not defined.");
  440. #endif
  441. #ifndef SHOULD_BE_DEFINED_EXISTS2
  442. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_EXISTS2 is not defined.\n");
  443. #else
  444. cmPassed("SHOULD_BE_DEFINED_EXISTS2 is defined.");
  445. #endif
  446. #ifdef SHOULD_NOT_BE_DEFINED_LESS
  447. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_LESS is defined.");
  448. #else
  449. cmPassed("SHOULD_NOT_BE_DEFINED_LESS is not defined.");
  450. #endif
  451. #ifndef SHOULD_BE_DEFINED_LESS
  452. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_LESS is not defined.\n");
  453. #else
  454. cmPassed("SHOULD_BE_DEFINED_LESS is defined.");
  455. #endif
  456. #ifdef SHOULD_NOT_BE_DEFINED_LESS2
  457. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_LESS2 is defined.");
  458. #else
  459. cmPassed("SHOULD_NOT_BE_DEFINED_LESS2 is not defined.");
  460. #endif
  461. #ifndef SHOULD_BE_DEFINED_LESS2
  462. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_LESS2 is not defined.\n");
  463. #else
  464. cmPassed("SHOULD_BE_DEFINED_LESS2 is defined.");
  465. #endif
  466. #ifdef SHOULD_NOT_BE_DEFINED_GREATER
  467. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_GREATER is defined.");
  468. #else
  469. cmPassed("SHOULD_NOT_BE_DEFINED_GREATER is not defined.");
  470. #endif
  471. #ifdef SHOULD_NOT_BE_DEFINED_EQUAL
  472. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_EQUAL is defined.");
  473. #else
  474. cmPassed("SHOULD_NOT_BE_DEFINED_EQUAL is not defined.");
  475. #endif
  476. #ifndef SHOULD_BE_DEFINED_EQUAL
  477. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_EQUAL is not defined.\n");
  478. #else
  479. cmPassed("SHOULD_BE_DEFINED_EQUAL is defined.");
  480. #endif
  481. #ifndef SHOULD_BE_DEFINED_GREATER
  482. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_GREATER is not defined.\n");
  483. #else
  484. cmPassed("SHOULD_BE_DEFINED_GREATER is defined.");
  485. #endif
  486. #ifdef SHOULD_NOT_BE_DEFINED_GREATER2
  487. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_GREATER2 is defined.");
  488. #else
  489. cmPassed("SHOULD_NOT_BE_DEFINED_GREATER2 is not defined.");
  490. #endif
  491. #ifndef SHOULD_BE_DEFINED_GREATER2
  492. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_GREATER2 is not defined.\n");
  493. #else
  494. cmPassed("SHOULD_BE_DEFINED_GREATER2 is defined.");
  495. #endif
  496. #ifdef SHOULD_NOT_BE_DEFINED_STRLESS
  497. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRLESS is defined.");
  498. #else
  499. cmPassed("SHOULD_NOT_BE_DEFINED_STRLESS is not defined.");
  500. #endif
  501. #ifndef SHOULD_BE_DEFINED_STRLESS
  502. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRLESS is not defined.\n");
  503. #else
  504. cmPassed("SHOULD_BE_DEFINED_STRLESS is defined.");
  505. #endif
  506. #ifdef SHOULD_NOT_BE_DEFINED_STRLESS2
  507. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRLESS2 is defined.");
  508. #else
  509. cmPassed("SHOULD_NOT_BE_DEFINED_STRLESS2 is not defined.");
  510. #endif
  511. #ifndef SHOULD_BE_DEFINED_STRLESS2
  512. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRLESS2 is not defined.\n");
  513. #else
  514. cmPassed("SHOULD_BE_DEFINED_STRLESS2 is defined.");
  515. #endif
  516. #ifdef SHOULD_NOT_BE_DEFINED_STRGREATER
  517. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRGREATER is defined.");
  518. #else
  519. cmPassed("SHOULD_NOT_BE_DEFINED_STRGREATER is not defined.");
  520. #endif
  521. #ifndef SHOULD_BE_DEFINED_STRGREATER
  522. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRGREATER is not defined.\n");
  523. #else
  524. cmPassed("SHOULD_BE_DEFINED_STRGREATER is defined.");
  525. #endif
  526. #ifdef SHOULD_NOT_BE_DEFINED_STRGREATER2
  527. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRGREATER2 is defined.");
  528. #else
  529. cmPassed("SHOULD_NOT_BE_DEFINED_STRGREATER2 is not defined.");
  530. #endif
  531. #ifndef SHOULD_BE_DEFINED_STRGREATER2
  532. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRGREATER2 is not defined.\n");
  533. #else
  534. cmPassed("SHOULD_BE_DEFINED_STRGREATER2 is defined.");
  535. #endif
  536. // ----------------------------------------------------------------------
  537. // Test FOREACH
  538. #ifndef FOREACH_VAR1
  539. cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
  540. "FOREACH_VAR1 is not defined.");
  541. #else
  542. if(strcmp(FOREACH_VAR1, "VALUE1") != 0)
  543. {
  544. cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
  545. "FOREACH_VAR1 == ", FOREACH_VAR1);
  546. }
  547. else
  548. {
  549. cmPassed("FOREACH_VAR1 == ", FOREACH_VAR1);
  550. }
  551. #endif
  552. #ifndef FOREACH_VAR2
  553. cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
  554. "FOREACH_VAR2 is not defined.");
  555. #else
  556. if(strcmp(FOREACH_VAR2, "VALUE2") != 0)
  557. {
  558. cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
  559. "FOREACH_VAR2 == ", FOREACH_VAR2);
  560. }
  561. else
  562. {
  563. cmPassed("FOREACH_VAR2 == ", FOREACH_VAR2);
  564. }
  565. #endif
  566. #ifndef FOREACH_CONCAT
  567. cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
  568. "FOREACH_CONCAT is not defined.");
  569. #else
  570. if(strcmp(FOREACH_CONCAT, "abcdefg") != 0)
  571. {
  572. cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
  573. "FOREACH_CONCAT == ", FOREACH_CONCAT);
  574. }
  575. else
  576. {
  577. cmPassed("FOREACH_CONCAT == ", FOREACH_CONCAT);
  578. }
  579. #endif
  580. // ----------------------------------------------------------------------
  581. // Test FIND_FILE, FIND_PATH and various GET_FILENAME_COMPONENT combinations
  582. #ifndef FILENAME_VAR_PATH_NAME
  583. cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  584. "FILENAME_VAR_PATH_NAME is not defined.");
  585. #else
  586. if((strcmp(FILENAME_VAR_PATH_NAME, "Complex") == 0) ||
  587. (strcmp(FILENAME_VAR_PATH_NAME, "ComplexOneConfig") == 0) ||
  588. (strcmp(FILENAME_VAR_PATH_NAME, "ComplexRelativePaths") == 0))
  589. {
  590. cmPassed("FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME);
  591. }
  592. else
  593. {
  594. cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  595. "FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME);
  596. }
  597. #endif
  598. #ifndef FILENAME_VAR_NAME
  599. cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  600. "FILENAME_VAR_NAME is not defined.");
  601. #else
  602. if(strcmp(FILENAME_VAR_NAME, "VarTests.cmake") != 0)
  603. {
  604. cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  605. "FILENAME_VAR_NAME == ", FILENAME_VAR_NAME);
  606. }
  607. else
  608. {
  609. cmPassed("FILENAME_VAR_NAME == ", FILENAME_VAR_NAME);
  610. }
  611. #endif
  612. #ifndef FILENAME_VAR_EXT
  613. cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  614. "FILENAME_VAR_EXT is not defined.");
  615. #else
  616. if(strcmp(FILENAME_VAR_EXT, ".cmake") != 0)
  617. {
  618. cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  619. "FILENAME_VAR_EXT == ", FILENAME_VAR_EXT);
  620. }
  621. else
  622. {
  623. cmPassed("FILENAME_VAR_EXT == ", FILENAME_VAR_EXT);
  624. }
  625. #endif
  626. #ifndef FILENAME_VAR_NAME_WE
  627. cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  628. "FILENAME_VAR_NAME_WE is not defined.");
  629. #else
  630. if(strcmp(FILENAME_VAR_NAME_WE, "VarTests") != 0)
  631. {
  632. cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  633. "FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE);
  634. }
  635. else
  636. {
  637. cmPassed("FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE);
  638. }
  639. #endif
  640. #ifndef PATH_VAR_NAME
  641. cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  642. "PATH_VAR_NAME is not defined.");
  643. #else
  644. if((strcmp(PATH_VAR_NAME, "Complex") == 0) ||
  645. (strcmp(PATH_VAR_NAME, "ComplexOneConfig") == 0) ||
  646. (strcmp(PATH_VAR_NAME, "ComplexRelativePaths") == 0))
  647. {
  648. cmPassed("PATH_VAR_NAME == ", PATH_VAR_NAME);
  649. }
  650. else
  651. {
  652. cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  653. "PATH_VAR_NAME == ", PATH_VAR_NAME);
  654. }
  655. #endif
  656. // ----------------------------------------------------------------------
  657. // Test LOAD_CACHE
  658. #ifndef CACHE_TEST_VAR1
  659. cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
  660. "CACHE_TEST_VAR1 is not defined.");
  661. #else
  662. if(strcmp(CACHE_TEST_VAR1, "foo") != 0)
  663. {
  664. cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
  665. "CACHE_TEST_VAR1 == ", CACHE_TEST_VAR1);
  666. }
  667. else
  668. {
  669. cmPassed("CACHE_TEST_VAR1 == ", CACHE_TEST_VAR1);
  670. }
  671. #endif
  672. #ifndef CACHE_TEST_VAR2
  673. cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
  674. "CACHE_TEST_VAR2 is not defined.");
  675. #else
  676. if(strcmp(CACHE_TEST_VAR2, "bar") != 0)
  677. {
  678. cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
  679. "CACHE_TEST_VAR2 == ", CACHE_TEST_VAR2);
  680. }
  681. else
  682. {
  683. cmPassed("CACHE_TEST_VAR2 == ", CACHE_TEST_VAR2);
  684. }
  685. #endif
  686. #ifndef CACHE_TEST_VAR3
  687. cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
  688. "CACHE_TEST_VAR3 is not defined.");
  689. #else
  690. if(strcmp(CACHE_TEST_VAR3, "1") != 0)
  691. {
  692. cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
  693. "CACHE_TEST_VAR3 == ", CACHE_TEST_VAR3);
  694. }
  695. else
  696. {
  697. cmPassed("CACHE_TEST_VAR3 == ", CACHE_TEST_VAR3);
  698. }
  699. #endif
  700. #ifdef CACHE_TEST_VAR_EXCLUDED
  701. cmFailed("the LOAD_CACHE or CONFIGURE_FILE command or cmakedefine is broken, "
  702. "CACHE_TEST_VAR_EXCLUDED is defined (should not have been loaded).");
  703. #else
  704. cmPassed("CACHE_TEST_VAR_EXCLUDED is not defined.");
  705. #endif
  706. #ifndef CACHE_TEST_VAR_INTERNAL
  707. cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
  708. "CACHE_TEST_VAR_INTERNAL is not defined.");
  709. #else
  710. std::string cachetest = CACHE_TEST_VAR_INTERNAL;
  711. if(cachetest != "bar")
  712. {
  713. cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
  714. "CACHE_TEST_VAR_INTERNAL == ", CACHE_TEST_VAR_INTERNAL);
  715. }
  716. else
  717. {
  718. cmPassed("CACHE_TEST_VAR_INTERNAL == ", CACHE_TEST_VAR_INTERNAL);
  719. }
  720. #endif
  721. // ----------------------------------------------------------------------
  722. // Some pre-build/pre-link/post-build custom-commands have been
  723. // attached to the lib (see Library/).
  724. // Each runs ${CREATE_FILE_EXE} which will create a file.
  725. // It also copies that file again using cmake -E.
  726. // Similar rules have been added to this executable.
  727. //
  728. // WARNING: if you run 'complex' manually, this *will* fail, because
  729. // the file was removed the last time 'complex' was run, and it is
  730. // only created during a build.
  731. TestAndRemoveFile(BINARY_DIR "/Library/prebuild.txt");
  732. TestAndRemoveFile(BINARY_DIR "/Library/prelink.txt");
  733. TestAndRemoveFile(BINARY_DIR "/Library/postbuild.txt");
  734. TestAndRemoveFile(BINARY_DIR "/Library/postbuild2.txt");
  735. TestAndRemoveFile(BINARY_DIR "/Executable/prebuild.txt");
  736. TestAndRemoveFile(BINARY_DIR "/Executable/prelink.txt");
  737. TestAndRemoveFile(BINARY_DIR "/Executable/postbuild.txt");
  738. TestAndRemoveFile(BINARY_DIR "/Executable/postbuild2.txt");
  739. // ----------------------------------------------------------------------
  740. // A custom target has been created (see Library/).
  741. // It runs ${CREATE_FILE_EXE} which will create a file.
  742. //
  743. // WARNING: if you run 'complex' manually, this *will* fail, because
  744. // the file was removed the last time 'complex' was run, and it is
  745. // only created during a build.
  746. TestAndRemoveFile(BINARY_DIR "/Library/custom_target1.txt");
  747. // ----------------------------------------------------------------------
  748. // A directory has been created.
  749. TestDir(BINARY_DIR "/make_dir");
  750. // ----------------------------------------------------------------------
  751. // Test OUTPUT_REQUIRED_FILES
  752. // The files required by 'complex' have been output to a file.
  753. // The contents of this file is not tested (absolute paths).
  754. //
  755. // WARNING: if you run 'complex' manually, this *will* fail, because
  756. // the file was removed the last time 'complex' was run, and it is
  757. // only created during a build.
  758. TestAndRemoveFile(BINARY_DIR "/Executable/Temp/complex-required.txt");
  759. // ----------------------------------------------------------------------
  760. // Test FIND_LIBRARY
  761. #ifndef FIND_DUMMY_LIB
  762. cmFailed("the CONFIGURE_FILE command is broken, "
  763. "FIND_DUMMY_LIB is not defined.");
  764. #else
  765. if(strstr(FIND_DUMMY_LIB, "dummylib") == NULL)
  766. {
  767. cmFailed("the FIND_LIBRARY or CONFIGURE_FILE command is broken, "
  768. "FIND_DUMMY_LIB == ", FIND_DUMMY_LIB);
  769. }
  770. else
  771. {
  772. cmPassed("FIND_DUMMY_LIB == ", FIND_DUMMY_LIB);
  773. }
  774. #endif
  775. // ----------------------------------------------------------------------
  776. // Test SET_SOURCE_FILES_PROPERTIES
  777. #ifndef FILE_HAS_EXTRA_COMPILE_FLAGS
  778. cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting FILE_HAS_EXTRA_COMPILE_FLAGS flag");
  779. #else
  780. cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting FILE_HAS_EXTRA_COMPILE_FLAGS flag");
  781. #endif
  782. #ifndef FILE_HAS_ABSTRACT
  783. cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting ABSTRACT flag");
  784. #else
  785. cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting ABSTRACT flag");
  786. #endif
  787. #ifndef FILE_HAS_WRAP_EXCLUDE
  788. cmFailed("FILE_HAS_WRAP_EXCLUDE failed at setting WRAP_EXCLUDE flag");
  789. #else
  790. cmPassed("FILE_HAS_WRAP_EXCLUDE succeeded in setting WRAP_EXCLUDE flag");
  791. #endif
  792. #ifndef FILE_COMPILE_FLAGS
  793. cmFailed("the CONFIGURE_FILE command is broken, FILE_COMPILE_FLAGS is not defined.");
  794. #else
  795. if(strcmp(FILE_COMPILE_FLAGS, "-foo -bar") != 0)
  796. {
  797. cmFailed("the SET_SOURCE_FILES_PROPERTIES or CONFIGURE_FILE command is broken. FILE_COMPILE_FLAGS == ",
  798. FILE_COMPILE_FLAGS);
  799. }
  800. else
  801. {
  802. cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting extra flags == ", FILE_COMPILE_FLAGS);
  803. }
  804. #endif
  805. // ----------------------------------------------------------------------
  806. // Test registry (win32)
  807. #if defined(_WIN32) && !defined(__CYGWIN__)
  808. #ifndef REGISTRY_TEST_PATH
  809. cmFailed("the CONFIGURE_FILE command is broken, REGISTRY_TEST_PATH is not defined.");
  810. #else
  811. std::cout << "REGISTRY_TEST_PATH == " << REGISTRY_TEST_PATH << "\n";
  812. if(stricmp(REGISTRY_TEST_PATH, BINARY_DIR "/registry_dir") != 0)
  813. {
  814. cmFailed("the 'read registry value' function or CONFIGURE_FILE command is broken. REGISTRY_TEST_PATH == ",
  815. REGISTRY_TEST_PATH, " is not " BINARY_DIR "/registry_dir");
  816. }
  817. else
  818. {
  819. cmPassed("REGISTRY_TEST_PATH == ", REGISTRY_TEST_PATH);
  820. }
  821. #endif
  822. #endif // defined(_WIN32) && !defined(__CYGWIN__)
  823. if(strcmp(CMAKE_MINIMUM_REQUIRED_VERSION, "1.3") == 0)
  824. {
  825. cmPassed("CMAKE_MINIMUM_REQUIRED_VERSION is set to 1.3");
  826. }
  827. else
  828. {
  829. cmFailed("CMAKE_MINIMUM_REQUIRED_VERSION is not set to the expected 1.3");
  830. }
  831. // ----------------------------------------------------------------------
  832. // Test REMOVE command
  833. if (strcmp("a;b;d",REMOVE_STRING) == 0)
  834. {
  835. cmPassed("REMOVE is working");
  836. }
  837. else
  838. {
  839. cmFailed("REMOVE is not working");
  840. }
  841. // ----------------------------------------------------------------------
  842. // Test SEPARATE_ARGUMENTS
  843. if(strcmp("a;b;c", TEST_SEP) == 0)
  844. {
  845. cmPassed("SEPARATE_ARGUMENTS is working");
  846. }
  847. else
  848. {
  849. cmFailed("SEPARATE_ARGUMENTS is not working");
  850. }
  851. // ----------------------------------------------------------------------
  852. // Test Escape Quotes
  853. if(strcmp("\"hello world\"", STRING_WITH_QUOTES) == 0)
  854. {
  855. cmPassed("ESCAPE_QUOTES is working");
  856. }
  857. else
  858. {
  859. cmFailed("ESCAPE_QUOTES is not working");
  860. }
  861. // ----------------------------------------------------------------------
  862. // Test cmSystemTools::UpperCase
  863. std::string str = "abc";
  864. std::string strupper = "ABC";
  865. if(cmSystemTools::UpperCase(str) == strupper)
  866. {
  867. cmPassed("cmSystemTools::UpperCase is working");
  868. }
  869. else
  870. {
  871. cmFailed("cmSystemTools::UpperCase is working");
  872. }
  873. // ----------------------------------------------------------------------
  874. // Test if IF command inside a FOREACH works.
  875. #if defined(IF_INSIDE_FOREACH_THEN_EXECUTED) && !defined(IF_INSIDE_FOREACH_ELSE_EXECUTED)
  876. cmPassed("IF inside a FOREACH block works");
  877. #else
  878. cmFailed("IF inside a FOREACH block is broken");
  879. #endif
  880. #if defined(GENERATED_HEADER_INCLUDED)
  881. cmPassed("Generated header included by non-generated source works.");
  882. #else
  883. cmFailed("Generated header included by non-generated source failed.");
  884. #endif
  885. #ifdef FORCE_TEST
  886. cmFailed("CMake SET CACHE FORCE");
  887. #else
  888. cmPassed("CMake SET CACHE FORCE");
  889. #endif
  890. // first run with shouldFail = true, this will
  891. // run with A B C as set by the CMakeList.txt file.
  892. if(!TestLibraryOrder(true))
  893. {
  894. cmPassed("CMake cmOrderLinkDirectories failed when it should.");
  895. }
  896. else
  897. {
  898. cmFailed("CMake cmOrderLinkDirectories failed to fail when given an impossible set of paths.");
  899. }
  900. // next run with shouldPass = true, this will
  901. // run with B/libA.a removed and should create the order
  902. // B C A
  903. if(TestLibraryOrder(false))
  904. {
  905. cmPassed("CMake cmOrderLinkDirectories worked.");
  906. }
  907. else
  908. {
  909. cmFailed("CMake cmOrderLinkDirectories failed.");
  910. }
  911. // ----------------------------------------------------------------------
  912. // Summary
  913. std::cout << "Passed: " << cm_passed << "\n";
  914. if(cm_failed)
  915. {
  916. std::cout << "Failed: " << cm_failed << "\n";
  917. return cm_failed;
  918. }
  919. return 0;
  920. }