complex.cxx 29 KB

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