complex.cxx 37 KB

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