complex.cxx 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896
  1. #include "Aout.h"
  2. #include "ExtraSources/file1.h"
  3. #include "cmTestConfigure.h"
  4. #include "cmTestConfigureEscape.h"
  5. #include "cmTestGeneratedHeader.h"
  6. #include "cmVersion.h"
  7. #include "file2.h"
  8. #include "sharedFile.h"
  9. extern "C" {
  10. #include "testConly.h"
  11. }
  12. #include <iostream>
  13. #include <string.h>
  14. #include <string>
  15. #include <vector>
  16. #include <stdio.h>
  17. #include <sys/stat.h>
  18. #if !defined(S_ISDIR)
  19. #define S_ISDIR(mode) ((mode)&_S_IFDIR)
  20. #endif
  21. #ifdef COMPLEX_TEST_LINK_STATIC
  22. extern "C" {
  23. int TestLinkGetType();
  24. }
  25. #endif
  26. int cm_passed = 0;
  27. int cm_failed = 0;
  28. // ======================================================================
  29. void cmFailed(const char* Message, const char* m2 = "", const char* m3 = "")
  30. {
  31. std::cout << "FAILED: " << Message << m2 << m3 << "\n";
  32. cm_failed++;
  33. }
  34. // ======================================================================
  35. void cmPassed(const char* Message, const char* m2 = "")
  36. {
  37. std::cout << "Passed: " << Message << m2 << "\n";
  38. cm_passed++;
  39. }
  40. #ifndef COMPLEX_DEFINED_PRE
  41. #error "COMPLEX_DEFINED_PRE not defined!"
  42. #endif
  43. #ifdef COMPLEX_DEFINED
  44. #error "COMPLEX_DEFINED is defined but it should not!"
  45. #endif
  46. #ifndef COMPLEX_DEFINED_POST
  47. #error "COMPLEX_DEFINED_POST not defined!"
  48. #endif
  49. #ifndef CMAKE_IS_REALLY_FUN
  50. #error This is a problem. Looks like ADD_DEFINITIONS and REMOVE_DEFINITIONS does not work
  51. #endif
  52. #if defined(NDEBUG) && !defined(CMAKE_IS_FUN_IN_RELEASE_MODE)
  53. #error Per-configuration directory-level definition not inherited.
  54. #endif
  55. // ======================================================================
  56. void TestAndRemoveFile(const char* filename)
  57. {
  58. struct stat st;
  59. if (stat(filename, &st) < 0) {
  60. cmFailed("Could not find file: ", filename);
  61. } else {
  62. if (remove(filename) < 0) {
  63. cmFailed("Unable to remove file. It does not imply that this test "
  64. "failed, but it *will* be corrupted thereafter if this file is "
  65. "not removed: ",
  66. filename);
  67. } else {
  68. cmPassed("Find and remove file: ", filename);
  69. }
  70. }
  71. }
  72. // ======================================================================
  73. void TestDir(const char* filename)
  74. {
  75. struct stat st;
  76. if (stat(filename, &st) < 0 || !S_ISDIR(st.st_mode)) {
  77. cmFailed("Could not find dir: ", filename);
  78. } else {
  79. cmPassed("Find dir: ", filename);
  80. }
  81. }
  82. // Here is a stupid function that tries to use std::string methods
  83. // so that the dec cxx compiler will instantiate the stuff that
  84. // we are using from the CMakeLib library....
  85. void ForceStringUse()
  86. {
  87. std::vector<std::string> v;
  88. std::vector<std::string> v2;
  89. v = v2;
  90. std::string cachetest = CACHE_TEST_VAR_INTERNAL;
  91. v.push_back(cachetest);
  92. v2 = v;
  93. std::string x(5, 'x');
  94. char buff[5];
  95. x.copy(buff, 1, 0);
  96. x[0] = 'a';
  97. std::string::size_type pos = 0;
  98. x.replace(pos, pos, pos, 'x');
  99. std::string copy = cachetest;
  100. cachetest.find("bar");
  101. cachetest.rfind("bar");
  102. copy.append(cachetest);
  103. copy = cachetest.substr(0, cachetest.size());
  104. }
  105. // defined in testcflags.c
  106. extern "C" int TestCFlags(char* m);
  107. extern "C" int TestTargetCompileFlags(char* m);
  108. #if 0
  109. // defined in Sub1/NameConflictTest.c
  110. extern "C" int NameConflictTest1();
  111. // defined in Sub2/NameConflictTest.c
  112. extern "C" int NameConflictTest2();
  113. #endif
  114. // ======================================================================
  115. int main()
  116. {
  117. #if 0
  118. if(NameConflictTest1() == 0 && NameConflictTest2() == 0)
  119. {
  120. cmPassed("Sub dir with same named source works");
  121. }
  122. else
  123. {
  124. cmFailed("Sub dir with same named source fails");
  125. }
  126. #endif
  127. if (file1() != 1) {
  128. cmFailed("Call to file1 function from library failed.");
  129. } else {
  130. cmPassed("Call to file1 function returned 1.");
  131. }
  132. #ifndef COMPLEX_TARGET_FLAG
  133. cmFailed("COMPILE_FLAGS did not work with SET_TARGET_PROPERTIES");
  134. #else
  135. cmPassed("COMPILE_FLAGS did work with SET_TARGET_PROPERTIES");
  136. #endif
  137. #ifdef ELSEIF_RESULT
  138. cmPassed("ELSEIF did work");
  139. #else
  140. cmFailed("ELSEIF did not work");
  141. #endif
  142. #ifdef CONDITIONAL_PARENTHESES
  143. cmPassed("CONDITIONAL_PARENTHESES did work");
  144. #else
  145. cmFailed("CONDITIONAL_PARENTHESES did not work");
  146. #endif
  147. if (file2() != 1) {
  148. cmFailed("Call to file2 function from library failed.");
  149. } else {
  150. cmPassed("Call to file2 function returned 1.");
  151. }
  152. #ifndef TEST_CXX_FLAGS
  153. cmFailed("CMake CMAKE_CXX_FLAGS is not being passed to the compiler!");
  154. #else
  155. cmPassed("CMake CMAKE_CXX_FLAGS is being passed to the compiler.");
  156. #endif
  157. std::string gen = CMAKE_GENERATOR;
  158. // visual studio is currently broken for c flags
  159. char msg[1024];
  160. if (gen.find("Visual") == gen.npos) {
  161. #ifdef TEST_C_FLAGS
  162. cmFailed(
  163. "CMake CMAKE_C_FLAGS are being passed to c++ files the compiler!");
  164. #else
  165. cmPassed("CMake CMAKE_C_FLAGS are not being passed to c++ files.");
  166. #endif
  167. if (TestCFlags(msg)) {
  168. cmPassed("CMake CMAKE_C_FLAGS are being passed to c files and CXX flags "
  169. "are not.");
  170. } else {
  171. cmFailed(msg);
  172. }
  173. }
  174. if (TestTargetCompileFlags(msg)) {
  175. cmPassed(msg);
  176. } else {
  177. cmFailed(msg);
  178. }
  179. // ----------------------------------------------------------------------
  180. // Test ADD_DEFINITIONS
  181. #ifndef CMAKE_IS_FUN
  182. cmFailed("CMake is not fun, so it is broken and should be fixed.");
  183. #else
  184. cmPassed("CMAKE_IS_FUN is defined.");
  185. #endif
  186. #if defined(CMAKE_ARGV1) && defined(CMAKE_ARGV2) && defined(CMAKE_ARGV3) && \
  187. defined(CMAKE_ARGV4)
  188. cmPassed("Variable args for MACROs are working.");
  189. #else
  190. cmFailed("Variable args for MACROs are failing.");
  191. #endif
  192. // ----------------------------------------------------------------------
  193. // Test GET_SOURCE_FILE_PROPERTY for location
  194. #ifndef CMAKE_FOUND_ACXX
  195. cmFailed("CMake did not get the location of A.cxx correctly");
  196. #else
  197. cmPassed("CMake found A.cxx properly");
  198. #endif
  199. // ----------------------------------------------------------------------
  200. // Test GET_DIRECTORY_PROPERTY for parent
  201. #ifndef CMAKE_FOUND_PARENT
  202. cmFailed("CMake did not get the location of the parent directory properly");
  203. #else
  204. cmPassed("CMake found the parent directory properly");
  205. #endif
  206. // ----------------------------------------------------------------------
  207. // Test GET_DIRECTORY_PROPERTY for listfiles
  208. #ifndef CMAKE_FOUND_LISTFILE_STACK
  209. cmFailed("CMake did not get the listfile stack properly");
  210. #else
  211. cmPassed("CMake found the listfile stack properly");
  212. #endif
  213. // ----------------------------------------------------------------------
  214. // Test SET, VARIABLE_REQUIRES
  215. #ifdef SHOULD_NOT_BE_DEFINED
  216. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED is defined.");
  217. #else
  218. cmPassed("SHOULD_NOT_BE_DEFINED is not defined.");
  219. #endif
  220. #ifndef SHOULD_BE_DEFINED
  221. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED is not defined.\n");
  222. #else
  223. cmPassed("SHOULD_BE_DEFINED is defined.");
  224. #endif
  225. #ifndef ONE_VAR
  226. cmFailed("cmakedefine is broken, ONE_VAR is not defined.");
  227. #else
  228. cmPassed("ONE_VAR is defined.");
  229. #endif
  230. #ifndef ONE_VAR_IS_DEFINED
  231. cmFailed("cmakedefine, SET or VARIABLE_REQUIRES is broken, "
  232. "ONE_VAR_IS_DEFINED is not defined.");
  233. #else
  234. cmPassed("ONE_VAR_IS_DEFINED is defined.");
  235. #endif
  236. #ifdef ZERO_VAR
  237. cmFailed("cmakedefine is broken, ZERO_VAR is defined.");
  238. #else
  239. cmPassed("ZERO_VAR is not defined.");
  240. #endif
  241. #ifndef STRING_VAR
  242. cmFailed("the CONFIGURE_FILE command is broken, STRING_VAR is not defined.");
  243. #else
  244. if (strcmp(STRING_VAR, "CMake is great") != 0) {
  245. cmFailed("the SET or CONFIGURE_FILE command is broken. STRING_VAR == ",
  246. STRING_VAR);
  247. } else {
  248. cmPassed("STRING_VAR == ", STRING_VAR);
  249. }
  250. #endif
  251. // ----------------------------------------------------------------------
  252. // Test various IF/ELSE combinations
  253. #ifdef SHOULD_NOT_BE_DEFINED_NOT
  254. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_NOT is defined.");
  255. #else
  256. cmPassed("SHOULD_NOT_BE_DEFINED_NOT is not defined.");
  257. #endif
  258. #ifndef SHOULD_BE_DEFINED_NOT
  259. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_NOT is not defined.\n");
  260. #else
  261. cmPassed("SHOULD_BE_DEFINED_NOT is defined.");
  262. #endif
  263. #ifdef SHOULD_NOT_BE_DEFINED_NOT2
  264. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_NOT2 is defined.");
  265. #else
  266. cmPassed("SHOULD_NOT_BE_DEFINED_NOT2 is not defined.");
  267. #endif
  268. #ifndef SHOULD_BE_DEFINED_NOT2
  269. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_NOT2 is not defined.\n");
  270. #else
  271. cmPassed("SHOULD_BE_DEFINED_NOT2 is defined.");
  272. #endif
  273. #ifdef SHOULD_NOT_BE_DEFINED_AND
  274. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_AND is defined.");
  275. #else
  276. cmPassed("SHOULD_NOT_BE_DEFINED_AND is not defined.");
  277. #endif
  278. #ifndef SHOULD_BE_DEFINED_AND
  279. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_AND is not defined.\n");
  280. #else
  281. cmPassed("SHOULD_BE_DEFINED_AND is defined.");
  282. #endif
  283. #ifdef SHOULD_NOT_BE_DEFINED_AND2
  284. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_AND2 is defined.");
  285. #else
  286. cmPassed("SHOULD_NOT_BE_DEFINED_AND2 is not defined.");
  287. #endif
  288. #ifndef SHOULD_BE_DEFINED_AND2
  289. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_AND2 is not defined.\n");
  290. #else
  291. cmPassed("SHOULD_BE_DEFINED_AND2 is defined.");
  292. #endif
  293. #ifdef SHOULD_NOT_BE_DEFINED_OR
  294. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_OR is defined.");
  295. #else
  296. cmPassed("SHOULD_NOT_BE_DEFINED_OR is not defined.");
  297. #endif
  298. #ifndef SHOULD_BE_DEFINED_OR
  299. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_OR is not defined.\n");
  300. #else
  301. cmPassed("SHOULD_BE_DEFINED_OR is defined.");
  302. #endif
  303. #ifdef SHOULD_NOT_BE_DEFINED_OR2
  304. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_OR2 is defined.");
  305. #else
  306. cmPassed("SHOULD_NOT_BE_DEFINED_OR2 is not defined.");
  307. #endif
  308. #ifndef SHOULD_BE_DEFINED_OR2
  309. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_OR2 is not defined.\n");
  310. #else
  311. cmPassed("SHOULD_BE_DEFINED_OR2 is defined.");
  312. #endif
  313. #ifdef SHOULD_NOT_BE_DEFINED_MATCHES
  314. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_MATCHES is defined.");
  315. #else
  316. cmPassed("SHOULD_NOT_BE_DEFINED_MATCHES is not defined.");
  317. #endif
  318. #ifndef SHOULD_BE_DEFINED_MATCHES
  319. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_MATCHES is not defined.\n");
  320. #else
  321. cmPassed("SHOULD_BE_DEFINED_MATCHES is defined.");
  322. #endif
  323. #ifdef SHOULD_NOT_BE_DEFINED_MATCHES2
  324. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_MATCHES2 is defined.");
  325. #else
  326. cmPassed("SHOULD_NOT_BE_DEFINED_MATCHES2 is not defined.");
  327. #endif
  328. #ifndef SHOULD_BE_DEFINED_MATCHES2
  329. cmFailed(
  330. "IF or SET is broken, SHOULD_BE_DEFINED_MATCHES2 is not defined.\n");
  331. #else
  332. cmPassed("SHOULD_BE_DEFINED_MATCHES2 is defined.");
  333. #endif
  334. #ifdef SHOULD_NOT_BE_DEFINED_COMMAND
  335. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_COMMAND is defined.");
  336. #else
  337. cmPassed("SHOULD_NOT_BE_DEFINED_COMMAND is not defined.");
  338. #endif
  339. #ifndef SHOULD_BE_DEFINED_COMMAND
  340. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_COMMAND is not defined.\n");
  341. #else
  342. cmPassed("SHOULD_BE_DEFINED_COMMAND is defined.");
  343. #endif
  344. #ifdef SHOULD_NOT_BE_DEFINED_COMMAND2
  345. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_COMMAND2 is defined.");
  346. #else
  347. cmPassed("SHOULD_NOT_BE_DEFINED_COMMAND2 is not defined.");
  348. #endif
  349. #ifndef SHOULD_BE_DEFINED_COMMAND2
  350. cmFailed(
  351. "IF or SET is broken, SHOULD_BE_DEFINED_COMMAND2 is not defined.\n");
  352. #else
  353. cmPassed("SHOULD_BE_DEFINED_COMMAND2 is defined.");
  354. #endif
  355. #ifdef SHOULD_NOT_BE_DEFINED_EXISTS
  356. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_EXISTS is defined.");
  357. #else
  358. cmPassed("SHOULD_NOT_BE_DEFINED_EXISTS is not defined.");
  359. #endif
  360. #ifndef SHOULD_BE_DEFINED_EXISTS
  361. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_EXISTS is not defined.\n");
  362. #else
  363. cmPassed("SHOULD_BE_DEFINED_EXISTS is defined.");
  364. #endif
  365. #ifdef SHOULD_NOT_BE_DEFINED_EXISTS2
  366. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_EXISTS2 is defined.");
  367. #else
  368. cmPassed("SHOULD_NOT_BE_DEFINED_EXISTS2 is not defined.");
  369. #endif
  370. #ifndef SHOULD_BE_DEFINED_EXISTS2
  371. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_EXISTS2 is not defined.\n");
  372. #else
  373. cmPassed("SHOULD_BE_DEFINED_EXISTS2 is defined.");
  374. #endif
  375. #ifndef SHOULD_BE_DEFINED_IS_DIRECTORY
  376. cmFailed(
  377. "IF or SET is broken, SHOULD_BE_DEFINED_IS_DIRECTORY is not defined.\n");
  378. #else
  379. cmPassed("SHOULD_BE_DEFINED_IS_DIRECTORY is defined.");
  380. #endif
  381. #ifndef SHOULD_BE_DEFINED_IS_DIRECTORY2
  382. cmFailed(
  383. "IF or SET is broken, SHOULD_BE_DEFINED_IS_DIRECTORY2 is not defined.\n");
  384. #else
  385. cmPassed("SHOULD_BE_DEFINED_IS_DIRECTORY2 is defined.");
  386. #endif
  387. #ifdef SHOULD_NOT_BE_DEFINED_LESS
  388. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_LESS is defined.");
  389. #else
  390. cmPassed("SHOULD_NOT_BE_DEFINED_LESS is not defined.");
  391. #endif
  392. #ifndef SHOULD_BE_DEFINED_LESS
  393. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_LESS is not defined.\n");
  394. #else
  395. cmPassed("SHOULD_BE_DEFINED_LESS is defined.");
  396. #endif
  397. #ifdef SHOULD_NOT_BE_DEFINED_LESS2
  398. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_LESS2 is defined.");
  399. #else
  400. cmPassed("SHOULD_NOT_BE_DEFINED_LESS2 is not defined.");
  401. #endif
  402. #ifndef SHOULD_BE_DEFINED_LESS2
  403. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_LESS2 is not defined.\n");
  404. #else
  405. cmPassed("SHOULD_BE_DEFINED_LESS2 is defined.");
  406. #endif
  407. #ifdef SHOULD_NOT_BE_DEFINED_GREATER
  408. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_GREATER is defined.");
  409. #else
  410. cmPassed("SHOULD_NOT_BE_DEFINED_GREATER is not defined.");
  411. #endif
  412. #ifdef SHOULD_NOT_BE_DEFINED_EQUAL
  413. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_EQUAL is defined.");
  414. #else
  415. cmPassed("SHOULD_NOT_BE_DEFINED_EQUAL is not defined.");
  416. #endif
  417. #ifndef SHOULD_BE_DEFINED_EQUAL
  418. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_EQUAL is not defined.\n");
  419. #else
  420. cmPassed("SHOULD_BE_DEFINED_EQUAL is defined.");
  421. #endif
  422. #ifndef SHOULD_BE_DEFINED_GREATER
  423. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_GREATER is not defined.\n");
  424. #else
  425. cmPassed("SHOULD_BE_DEFINED_GREATER is defined.");
  426. #endif
  427. #ifdef SHOULD_NOT_BE_DEFINED_GREATER2
  428. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_GREATER2 is defined.");
  429. #else
  430. cmPassed("SHOULD_NOT_BE_DEFINED_GREATER2 is not defined.");
  431. #endif
  432. #ifndef SHOULD_BE_DEFINED_GREATER2
  433. cmFailed(
  434. "IF or SET is broken, SHOULD_BE_DEFINED_GREATER2 is not defined.\n");
  435. #else
  436. cmPassed("SHOULD_BE_DEFINED_GREATER2 is defined.");
  437. #endif
  438. #ifdef SHOULD_NOT_BE_DEFINED_STRLESS
  439. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRLESS is defined.");
  440. #else
  441. cmPassed("SHOULD_NOT_BE_DEFINED_STRLESS is not defined.");
  442. #endif
  443. #ifndef SHOULD_BE_DEFINED_STRLESS
  444. cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRLESS is not defined.\n");
  445. #else
  446. cmPassed("SHOULD_BE_DEFINED_STRLESS is defined.");
  447. #endif
  448. #ifdef SHOULD_NOT_BE_DEFINED_STRLESS2
  449. cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRLESS2 is defined.");
  450. #else
  451. cmPassed("SHOULD_NOT_BE_DEFINED_STRLESS2 is not defined.");
  452. #endif
  453. #ifndef SHOULD_BE_DEFINED_STRLESS2
  454. cmFailed(
  455. "IF or SET is broken, SHOULD_BE_DEFINED_STRLESS2 is not defined.\n");
  456. #else
  457. cmPassed("SHOULD_BE_DEFINED_STRLESS2 is defined.");
  458. #endif
  459. #ifdef SHOULD_NOT_BE_DEFINED_STRGREATER
  460. cmFailed(
  461. "IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRGREATER is defined.");
  462. #else
  463. cmPassed("SHOULD_NOT_BE_DEFINED_STRGREATER is not defined.");
  464. #endif
  465. #ifndef SHOULD_BE_DEFINED_STRGREATER
  466. cmFailed(
  467. "IF or SET is broken, SHOULD_BE_DEFINED_STRGREATER is not defined.\n");
  468. #else
  469. cmPassed("SHOULD_BE_DEFINED_STRGREATER is defined.");
  470. #endif
  471. #ifdef SHOULD_NOT_BE_DEFINED_STRGREATER2
  472. cmFailed(
  473. "IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRGREATER2 is defined.");
  474. #else
  475. cmPassed("SHOULD_NOT_BE_DEFINED_STRGREATER2 is not defined.");
  476. #endif
  477. #ifndef SHOULD_BE_DEFINED_STRGREATER2
  478. cmFailed(
  479. "IF or SET is broken, SHOULD_BE_DEFINED_STRGREATER2 is not defined.\n");
  480. #else
  481. cmPassed("SHOULD_BE_DEFINED_STRGREATER2 is defined.");
  482. #endif
  483. // ----------------------------------------------------------------------
  484. // Test FOREACH
  485. #ifndef FOREACH_VAR1
  486. cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
  487. "FOREACH_VAR1 is not defined.");
  488. #else
  489. if (strcmp(FOREACH_VAR1, "VALUE1") != 0) {
  490. cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
  491. "FOREACH_VAR1 == ",
  492. FOREACH_VAR1);
  493. } else {
  494. cmPassed("FOREACH_VAR1 == ", FOREACH_VAR1);
  495. }
  496. #endif
  497. #ifndef FOREACH_VAR2
  498. cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
  499. "FOREACH_VAR2 is not defined.");
  500. #else
  501. if (strcmp(FOREACH_VAR2, "VALUE2") != 0) {
  502. cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
  503. "FOREACH_VAR2 == ",
  504. FOREACH_VAR2);
  505. } else {
  506. cmPassed("FOREACH_VAR2 == ", FOREACH_VAR2);
  507. }
  508. #endif
  509. #ifndef FOREACH_CONCAT
  510. cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
  511. "FOREACH_CONCAT is not defined.");
  512. #else
  513. if (strcmp(FOREACH_CONCAT, "abcdefg") != 0) {
  514. cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
  515. "FOREACH_CONCAT == ",
  516. FOREACH_CONCAT);
  517. } else {
  518. cmPassed("FOREACH_CONCAT == ", FOREACH_CONCAT);
  519. }
  520. #endif
  521. // ----------------------------------------------------------------------
  522. // Test WHILE
  523. if (WHILE_VALUE != 1000) {
  524. cmFailed("WHILE command is not working");
  525. } else {
  526. cmPassed("WHILE command is working");
  527. }
  528. // ----------------------------------------------------------------------
  529. // Test LOAD_CACHE
  530. #ifndef CACHE_TEST_VAR1
  531. cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
  532. "CACHE_TEST_VAR1 is not defined.");
  533. #else
  534. if (strcmp(CACHE_TEST_VAR1, "foo") != 0) {
  535. cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
  536. "CACHE_TEST_VAR1 == ",
  537. CACHE_TEST_VAR1);
  538. } else {
  539. cmPassed("CACHE_TEST_VAR1 == ", CACHE_TEST_VAR1);
  540. }
  541. #endif
  542. #ifndef CACHE_TEST_VAR2
  543. cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
  544. "CACHE_TEST_VAR2 is not defined.");
  545. #else
  546. if (strcmp(CACHE_TEST_VAR2, "bar") != 0) {
  547. cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
  548. "CACHE_TEST_VAR2 == ",
  549. CACHE_TEST_VAR2);
  550. } else {
  551. cmPassed("CACHE_TEST_VAR2 == ", CACHE_TEST_VAR2);
  552. }
  553. #endif
  554. #ifndef CACHE_TEST_VAR3
  555. cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
  556. "CACHE_TEST_VAR3 is not defined.");
  557. #else
  558. if (strcmp(CACHE_TEST_VAR3, "1") != 0) {
  559. cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
  560. "CACHE_TEST_VAR3 == ",
  561. CACHE_TEST_VAR3);
  562. } else {
  563. cmPassed("CACHE_TEST_VAR3 == ", CACHE_TEST_VAR3);
  564. }
  565. #endif
  566. #ifdef CACHE_TEST_VAR_EXCLUDED
  567. cmFailed(
  568. "the LOAD_CACHE or CONFIGURE_FILE command or cmakedefine is broken, "
  569. "CACHE_TEST_VAR_EXCLUDED is defined (should not have been loaded).");
  570. #else
  571. cmPassed("CACHE_TEST_VAR_EXCLUDED is not defined.");
  572. #endif
  573. #ifndef CACHE_TEST_VAR_INTERNAL
  574. cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
  575. "CACHE_TEST_VAR_INTERNAL is not defined.");
  576. #else
  577. std::string cachetest = CACHE_TEST_VAR_INTERNAL;
  578. if (cachetest != "bar") {
  579. cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
  580. "CACHE_TEST_VAR_INTERNAL == ",
  581. CACHE_TEST_VAR_INTERNAL);
  582. } else {
  583. cmPassed("CACHE_TEST_VAR_INTERNAL == ", CACHE_TEST_VAR_INTERNAL);
  584. }
  585. #endif
  586. // ----------------------------------------------------------------------
  587. // Some pre-build/pre-link/post-build custom-commands have been
  588. // attached to the lib (see Library/).
  589. // Each runs ${CREATE_FILE_EXE} which will create a file.
  590. // It also copies that file again using cmake -E.
  591. // Similar rules have been added to this executable.
  592. //
  593. // WARNING: if you run 'complex' manually, this *will* fail, because
  594. // the file was removed the last time 'complex' was run, and it is
  595. // only created during a build.
  596. TestAndRemoveFile("Library/prebuild.txt");
  597. TestAndRemoveFile("Library/prelink.txt");
  598. TestAndRemoveFile("Library/postbuild.txt");
  599. TestAndRemoveFile("Library/postbuild2.txt");
  600. TestAndRemoveFile("Executable/prebuild.txt");
  601. TestAndRemoveFile("Executable/prelink.txt");
  602. TestAndRemoveFile("Executable/postbuild.txt");
  603. TestAndRemoveFile("Executable/postbuild2.txt");
  604. // ----------------------------------------------------------------------
  605. // A custom target has been created (see Library/).
  606. // It runs ${CREATE_FILE_EXE} which will create a file.
  607. //
  608. // WARNING: if you run 'complex' manually, this *will* fail, because
  609. // the file was removed the last time 'complex' was run, and it is
  610. // only created during a build.
  611. TestAndRemoveFile("Library/custom_target1.txt");
  612. // ----------------------------------------------------------------------
  613. // A directory has been created.
  614. TestDir("make_dir");
  615. // ----------------------------------------------------------------------
  616. // Test OUTPUT_REQUIRED_FILES
  617. // The files required by 'complex' have been output to a file.
  618. // The contents of this file is not tested (absolute paths).
  619. //
  620. // WARNING: if you run 'complex' manually, this *will* fail, because
  621. // the file was removed the last time 'complex' was run, and it is
  622. // only created during a build.
  623. TestAndRemoveFile("Executable/Temp/complex-required.txt");
  624. // ----------------------------------------------------------------------
  625. // Test FIND_LIBRARY
  626. #ifndef FIND_DUMMY_LIB
  627. cmFailed("the CONFIGURE_FILE command is broken, "
  628. "FIND_DUMMY_LIB is not defined.");
  629. #else
  630. if (strstr(FIND_DUMMY_LIB, "dummylib") == NULL) {
  631. cmFailed("the FIND_LIBRARY or CONFIGURE_FILE command is broken, "
  632. "FIND_DUMMY_LIB == ",
  633. FIND_DUMMY_LIB);
  634. } else {
  635. cmPassed("FIND_DUMMY_LIB == ", FIND_DUMMY_LIB);
  636. }
  637. #endif
  638. // ----------------------------------------------------------------------
  639. // Test SET_SOURCE_FILES_PROPERTIES
  640. #ifndef FILE_HAS_EXTRA_COMPILE_FLAGS
  641. cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting "
  642. "FILE_HAS_EXTRA_COMPILE_FLAGS flag");
  643. #else
  644. cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting "
  645. "FILE_HAS_EXTRA_COMPILE_FLAGS flag");
  646. #endif
  647. #if 0 // Disable until implemented everywhere.
  648. #ifndef FILE_DEFINE_STRING
  649. cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting FILE_DEFINE_STRING flag");
  650. #else
  651. if(strcmp(FILE_DEFINE_STRING, "hello") != 0)
  652. {
  653. cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting FILE_DEFINE_STRING flag correctly");
  654. }
  655. else
  656. {
  657. cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting FILE_DEFINE_STRING flag");
  658. }
  659. #endif
  660. #endif
  661. #ifndef FILE_HAS_ABSTRACT
  662. cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting ABSTRACT flag");
  663. #else
  664. cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting ABSTRACT flag");
  665. #endif
  666. #ifndef FILE_HAS_WRAP_EXCLUDE
  667. cmFailed("FILE_HAS_WRAP_EXCLUDE failed at setting WRAP_EXCLUDE flag");
  668. #else
  669. cmPassed("FILE_HAS_WRAP_EXCLUDE succeeded in setting WRAP_EXCLUDE flag");
  670. #endif
  671. #ifndef FILE_COMPILE_FLAGS
  672. cmFailed("the CONFIGURE_FILE command is broken, FILE_COMPILE_FLAGS is not "
  673. "defined.");
  674. #else
  675. if (strcmp(FILE_COMPILE_FLAGS, "-foo -bar") != 0) {
  676. cmFailed("the SET_SOURCE_FILES_PROPERTIES or CONFIGURE_FILE command is "
  677. "broken. FILE_COMPILE_FLAGS == ",
  678. FILE_COMPILE_FLAGS);
  679. } else {
  680. cmPassed(
  681. "SET_SOURCE_FILES_PROPERTIES succeeded in setting extra flags == ",
  682. FILE_COMPILE_FLAGS);
  683. }
  684. #endif
  685. // ----------------------------------------------------------------------
  686. // Test registry (win32)
  687. #if defined(_WIN32) && !defined(__CYGWIN__)
  688. #ifndef REGISTRY_TEST_PATH
  689. cmFailed("the CONFIGURE_FILE command is broken, REGISTRY_TEST_PATH is not "
  690. "defined.");
  691. #else
  692. std::cout << "REGISTRY_TEST_PATH == " << REGISTRY_TEST_PATH << "\n";
  693. if (stricmp(REGISTRY_TEST_PATH, BINARY_DIR "/registry_dir") != 0) {
  694. cmFailed("the 'read registry value' function or CONFIGURE_FILE command is "
  695. "broken. REGISTRY_TEST_PATH == ",
  696. REGISTRY_TEST_PATH, " is not " BINARY_DIR "/registry_dir");
  697. } else {
  698. cmPassed("REGISTRY_TEST_PATH == ", REGISTRY_TEST_PATH);
  699. }
  700. #endif
  701. #endif // defined(_WIN32) && !defined(__CYGWIN__)
  702. if (strcmp(CMAKE_MINIMUM_REQUIRED_VERSION, "2.4") == 0) {
  703. cmPassed("CMAKE_MINIMUM_REQUIRED_VERSION is set to 2.4");
  704. } else {
  705. cmFailed("CMAKE_MINIMUM_REQUIRED_VERSION is not set to the expected 2.4");
  706. }
  707. // ----------------------------------------------------------------------
  708. // Test REMOVE command
  709. if (strcmp("a;b;d", REMOVE_STRING) == 0) {
  710. cmPassed("REMOVE is working");
  711. } else {
  712. cmFailed("REMOVE is not working");
  713. }
  714. // ----------------------------------------------------------------------
  715. // Test SEPARATE_ARGUMENTS
  716. if (strcmp("a;b;c", TEST_SEP) == 0) {
  717. cmPassed("SEPARATE_ARGUMENTS is working");
  718. } else {
  719. cmFailed("SEPARATE_ARGUMENTS is not working");
  720. }
  721. // ----------------------------------------------------------------------
  722. // Test Escape Quotes
  723. if (strcmp("\"hello world\"", STRING_WITH_QUOTES) == 0) {
  724. cmPassed("ESCAPE_QUOTES is working");
  725. } else {
  726. cmFailed("ESCAPE_QUOTES is not working");
  727. }
  728. // ----------------------------------------------------------------------
  729. // Test if IF command inside a FOREACH works.
  730. #if defined(IF_INSIDE_FOREACH_THEN_EXECUTED) && \
  731. !defined(IF_INSIDE_FOREACH_ELSE_EXECUTED)
  732. cmPassed("IF inside a FOREACH block works");
  733. #else
  734. cmFailed("IF inside a FOREACH block is broken");
  735. #endif
  736. #if defined(GENERATED_HEADER_INCLUDED)
  737. cmPassed("Generated header included by non-generated source works.");
  738. #else
  739. cmFailed("Generated header included by non-generated source failed.");
  740. #endif
  741. if (SHOULD_BE_ZERO == 0) {
  742. cmPassed("cmakedefine01 is working for 0");
  743. } else {
  744. cmFailed("cmakedefine01 is not working for 0");
  745. }
  746. if (SHOULD_BE_ONE == 1) {
  747. cmPassed("cmakedefine01 is working for 1");
  748. } else {
  749. cmFailed("cmakedefine01 is not working for 1");
  750. }
  751. #ifdef FORCE_TEST
  752. cmFailed("CMake SET CACHE FORCE");
  753. #else
  754. cmPassed("CMake SET CACHE FORCE");
  755. #endif
  756. #ifdef COMPLEX_TEST_LINK_STATIC
  757. if (TestLinkGetType()) {
  758. cmPassed("Link to static over shared worked.");
  759. } else {
  760. cmFailed("Link to static over shared failed.");
  761. }
  762. #endif
  763. #if defined(A_VALUE) && A_VALUE == 10
  764. cmPassed("Single-character executable A worked.");
  765. #else
  766. cmFailed("Single-character executable A failed.");
  767. #endif
  768. // ----------------------------------------------------------------------
  769. // Summary
  770. std::cout << "Passed: " << cm_passed << "\n";
  771. if (cm_failed) {
  772. std::cout << "Failed: " << cm_failed << "\n";
  773. return cm_failed;
  774. }
  775. return 0;
  776. }