complex.cxx 30 KB

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