You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

439 lines
9.3 KiB

  1. // Setup for tests that use result of stl namespace test.
  2. #if defined(KWSYS_STL_HAVE_STD)
  3. # if KWSYS_STL_HAVE_STD
  4. # define kwsys_stl std
  5. # else
  6. # define kwsys_stl
  7. # endif
  8. #endif
  9. // Setup for tests that use iostreams.
  10. #if defined(KWSYS_IOS_USE_ANSI) && defined(KWSYS_IOS_HAVE_STD)
  11. # if defined(_MSC_VER)
  12. # pragma warning (push,1)
  13. # endif
  14. # if KWSYS_IOS_USE_ANSI
  15. # include <iostream>
  16. # else
  17. # include <iostream.h>
  18. # endif
  19. # if defined(_MSC_VER)
  20. # pragma warning (pop)
  21. # endif
  22. # if KWSYS_IOS_HAVE_STD
  23. # define kwsys_ios std
  24. # else
  25. # define kwsys_ios
  26. # endif
  27. #endif
  28. #ifdef TEST_KWSYS_STL_HAVE_STD
  29. #include <list>
  30. void f(std::list<int>*) {}
  31. int main() { return 0; }
  32. #endif
  33. #ifdef TEST_KWSYS_IOS_USE_ANSI
  34. #include <iosfwd>
  35. int main() { return 0; }
  36. #endif
  37. #ifdef TEST_KWSYS_IOS_HAVE_STD
  38. #include <iosfwd>
  39. void f(std::ostream*) {}
  40. int main() { return 0; }
  41. #endif
  42. #ifdef TEST_KWSYS_IOS_USE_SSTREAM
  43. #include <sstream>
  44. int main()
  45. {
  46. std::ostringstream ostr;
  47. ostr << "hello";
  48. if(ostr.str().size() == 5)
  49. {
  50. return 0;
  51. }
  52. return -1;
  53. }
  54. #endif
  55. #ifdef TEST_KWSYS_IOS_USE_STRSTREAM_H
  56. #include <strstream.h>
  57. int main() { return 0; }
  58. #endif
  59. #ifdef TEST_KWSYS_IOS_USE_STRSTREA_H
  60. #include <strstrea.h>
  61. int main() { return 0; }
  62. #endif
  63. #ifdef TEST_KWSYS_STL_STRING_HAVE_OSTREAM
  64. # include <iostream.h>
  65. # include <string>
  66. void f(ostream& os, const kwsys_stl::string& s) { os << s; }
  67. int main() { return 0; }
  68. #endif
  69. #ifdef TEST_KWSYS_STL_STRING_HAVE_ISTREAM
  70. # include <iostream.h>
  71. # include <string>
  72. void f(istream& is, kwsys_stl::string& s) { is >> s; }
  73. int main() { return 0; }
  74. #endif
  75. #ifdef TEST_KWSYS_STL_STRING_HAVE_NEQ_CHAR
  76. # include <string>
  77. bool f(const kwsys_stl::string& s) { return s != ""; }
  78. int main() { return 0; }
  79. #endif
  80. #ifdef TEST_KWSYS_CXX_HAS_CSTDDEF
  81. #include <cstddef>
  82. void f(size_t) {}
  83. int main() { return 0; }
  84. #endif
  85. #ifdef TEST_KWSYS_CXX_HAS_NULL_TEMPLATE_ARGS
  86. template <class T> class A;
  87. template <class T> int f(A<T>&);
  88. template <class T> class A
  89. {
  90. public:
  91. // "friend int f<>(A<T>&)" would conform
  92. friend int f(A<T>&);
  93. private:
  94. int x;
  95. };
  96. template <class T> int f(A<T>& a) { return a.x = 0; }
  97. template int f(A<int>&);
  98. int main()
  99. {
  100. A<int> a;
  101. return f(a);
  102. }
  103. #endif
  104. #ifdef TEST_KWSYS_CXX_HAS_MEMBER_TEMPLATES
  105. template <class U>
  106. class A
  107. {
  108. public:
  109. U u;
  110. A(): u(0) {}
  111. template <class V> V m(V* p) { return *p = u; }
  112. };
  113. int main()
  114. {
  115. A<short> a;
  116. int s = 1;
  117. return a.m(&s);
  118. }
  119. #endif
  120. #ifdef TEST_KWSYS_CXX_HAS_FULL_SPECIALIZATION
  121. template <class T> struct A {};
  122. template <> struct A<int*>
  123. {
  124. static int f() { return 0; }
  125. };
  126. int main() { return A<int*>::f(); }
  127. #endif
  128. #ifdef TEST_KWSYS_CXX_HAS_ARGUMENT_DEPENDENT_LOOKUP
  129. namespace N
  130. {
  131. class A {};
  132. int f(A*) { return 0; }
  133. }
  134. void f(void*);
  135. int main()
  136. {
  137. N::A* a = 0;
  138. return f(a);
  139. }
  140. #endif
  141. #ifdef TEST_KWSYS_STL_HAS_ITERATOR_TRAITS
  142. #include <iterator>
  143. #include <list>
  144. void f(kwsys_stl::iterator_traits<kwsys_stl::list<int>::iterator>::iterator_category const&) {}
  145. int main() { return 0; }
  146. #endif
  147. #ifdef TEST_KWSYS_STL_HAS_ITERATOR_CATEGORY
  148. #include <iterator>
  149. #include <list>
  150. void f(kwsys_stl::list<int>::iterator x) { kwsys_stl::iterator_category(x); }
  151. int main() { return 0; }
  152. #endif
  153. #ifdef TEST_KWSYS_STL_HAS___ITERATOR_CATEGORY
  154. #include <iterator>
  155. #include <list>
  156. void f(kwsys_stl::list<int>::iterator x) { kwsys_stl::__iterator_category(x); }
  157. int main() { return 0; }
  158. #endif
  159. #ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_TEMPLATE
  160. #include <memory>
  161. template <class Alloc>
  162. void f(const Alloc&)
  163. {
  164. typedef typename Alloc::size_type alloc_size_type;
  165. }
  166. int main()
  167. {
  168. f(kwsys_stl::allocator<char>());
  169. return 0;
  170. }
  171. #endif
  172. #ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE
  173. #include <memory>
  174. void f(kwsys_stl::allocator::size_type const&) {}
  175. int main() { return 0; }
  176. #endif
  177. #ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_REBIND
  178. #include <memory>
  179. template <class T, class Alloc>
  180. void f(const T&, const Alloc&)
  181. {
  182. typedef typename Alloc::template rebind<T>::other alloc_type;
  183. }
  184. int main()
  185. {
  186. f(0, kwsys_stl::allocator<char>());
  187. return 0;
  188. }
  189. #endif
  190. #ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT
  191. #include <memory>
  192. void f(kwsys_stl::allocator<char> const& a)
  193. {
  194. a.max_size(sizeof(int));
  195. }
  196. int main()
  197. {
  198. f(kwsys_stl::allocator<char>());
  199. return 0;
  200. }
  201. #endif
  202. #ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_OBJECTS
  203. #include <vector>
  204. void f(kwsys_stl::vector<int> const& v1)
  205. {
  206. kwsys_stl::vector<int>(1, 1, v1.get_allocator());
  207. }
  208. int main()
  209. {
  210. f(kwsys_stl::vector<int>());
  211. return 0;
  212. }
  213. #endif
  214. #ifdef TEST_KWSYS_STAT_HAS_ST_MTIM
  215. #include <sys/types.h>
  216. #include <sys/stat.h>
  217. #include <unistd.h>
  218. int main()
  219. {
  220. struct stat stat1;
  221. (void)stat1.st_mtim.tv_sec;
  222. (void)stat1.st_mtim.tv_nsec;
  223. return 0;
  224. }
  225. #endif
  226. #ifdef TEST_KWSYS_CXX_SAME_LONG_AND___INT64
  227. void function(long**) {}
  228. int main()
  229. {
  230. __int64** p = 0;
  231. function(p);
  232. return 0;
  233. }
  234. #endif
  235. #ifdef TEST_KWSYS_CXX_SAME_LONG_LONG_AND___INT64
  236. void function(long long**) {}
  237. int main()
  238. {
  239. __int64** p = 0;
  240. function(p);
  241. return 0;
  242. }
  243. #endif
  244. #ifdef TEST_KWSYS_CAN_CONVERT_UI64_TO_DOUBLE
  245. void function(double& l, unsigned __int64 const& r)
  246. {
  247. l = static_cast<double>(r);
  248. }
  249. int main()
  250. {
  251. double tTo = 0.0;
  252. unsigned __int64 tFrom = 0;
  253. function(tTo, tFrom);
  254. return 0;
  255. }
  256. #endif
  257. #ifdef TEST_KWSYS_IOS_HAS_ISTREAM_LONG_LONG
  258. int test_istream(kwsys_ios::istream& is, long long& x)
  259. {
  260. return (is >> x)? 1:0;
  261. }
  262. int main()
  263. {
  264. long long x = 0;
  265. return test_istream(kwsys_ios::cin, x);
  266. }
  267. #endif
  268. #ifdef TEST_KWSYS_IOS_HAS_OSTREAM_LONG_LONG
  269. int test_ostream(kwsys_ios::ostream& os, long long x)
  270. {
  271. return (os << x)? 1:0;
  272. }
  273. int main()
  274. {
  275. long long x = 0;
  276. return test_ostream(kwsys_ios::cout, x);
  277. }
  278. #endif
  279. #ifdef TEST_KWSYS_CHAR_IS_SIGNED
  280. /* Return 0 for char signed and 1 for char unsigned. */
  281. int main()
  282. {
  283. unsigned char uc = 255;
  284. return (*reinterpret_cast<char*>(&uc) < 0)?0:1;
  285. }
  286. #endif
  287. #ifdef TEST_KWSYS_LFS_WORKS
  288. /* Return 0 when LFS is available and 1 otherwise. */
  289. #define _LARGEFILE_SOURCE
  290. #define _LARGEFILE64_SOURCE
  291. #define _LARGE_FILES
  292. #define _FILE_OFFSET_BITS 64
  293. #include <sys/types.h>
  294. #include <sys/stat.h>
  295. #include <assert.h>
  296. #include <stdio.h>
  297. int main(int, char **argv)
  298. {
  299. /* check that off_t can hold 2^63 - 1 and perform basic operations... */
  300. #define OFF_T_64 (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
  301. if (OFF_T_64 % 2147483647 != 1)
  302. return 1;
  303. // stat breaks on SCO OpenServer
  304. struct stat buf;
  305. stat( argv[0], &buf );
  306. if (!S_ISREG(buf.st_mode))
  307. return 2;
  308. FILE *file = fopen( argv[0], "r" );
  309. off_t offset = ftello( file );
  310. fseek( file, offset, SEEK_CUR );
  311. fclose( file );
  312. return 0;
  313. }
  314. #endif
  315. #ifdef TEST_KWSYS_CXX_TYPE_INFO
  316. /* Collect fundamental type information and save it to a CMake script. */
  317. /* Include limits.h to get macros indicating long long and __int64.
  318. Note that certain compilers need special macros to define these
  319. macros in limits.h. */
  320. #if defined(_MSC_VER) && !defined(_MSC_EXTENSIONS)
  321. # define _MSC_EXTENSIONS
  322. #endif
  323. #if defined(__GNUC__) && __GNUC__ < 3
  324. # define _GNU_SOURCE
  325. #endif
  326. #include <limits.h>
  327. #include <stdio.h>
  328. #include <string.h>
  329. /* Due to shell differences and limitations of ADD_DEFINITIONS the
  330. KWSYS_CXX_TYPE_INFO_FILE macro will sometimes have double quotes
  331. and sometimes not. This macro will make sure the value is treated
  332. as a double-quoted string. */
  333. #define TO_STRING(x) TO_STRING0(x)
  334. #define TO_STRING0(x) TO_STRING1(x)
  335. #define TO_STRING1(x) #x
  336. void f() {}
  337. int main()
  338. {
  339. /* Construct the output file name. Some preprocessors will add an
  340. extra level of double quotes, so strip them. */
  341. char fbuf[] = TO_STRING(KWSYS_CXX_TYPE_INFO_FILE);
  342. char* fname = fbuf;
  343. if(fname[0] == '"')
  344. {
  345. ++fname;
  346. int len = static_cast<int>(strlen(fname));
  347. if(len > 0 && fname[len-1] == '"')
  348. {
  349. fname[len-1] = 0;
  350. }
  351. }
  352. /* Try to open the output file. */
  353. if(FILE* fout = fopen(fname, "w"))
  354. {
  355. /* Set the size of standard types. */
  356. fprintf(fout, "SET(KWSYS_SIZEOF_CHAR %d)\n", static_cast<int>(sizeof(char)));
  357. fprintf(fout, "SET(KWSYS_SIZEOF_SHORT %d)\n", static_cast<int>(sizeof(short)));
  358. fprintf(fout, "SET(KWSYS_SIZEOF_INT %d)\n", static_cast<int>(sizeof(int)));
  359. fprintf(fout, "SET(KWSYS_SIZEOF_LONG %d)\n", static_cast<int>(sizeof(long)));
  360. /* Set the size of some non-standard but common types. */
  361. /* Check for a limits.h macro for long long to see if the type exists. */
  362. #if defined(LLONG_MAX) || defined(LONG_LONG_MAX) || defined(LONGLONG_MAX)
  363. fprintf(fout, "SET(KWSYS_SIZEOF_LONG_LONG %d)\n", static_cast<int>(sizeof(long long)));
  364. #else
  365. fprintf(fout, "SET(KWSYS_SIZEOF_LONG_LONG 0) # No long long available.\n");
  366. #endif
  367. /* Check for a limits.h macro for __int64 to see if the type exists. */
  368. #if defined(_I64_MIN)
  369. fprintf(fout, "SET(KWSYS_SIZEOF___INT64 %d)\n", static_cast<int>(sizeof(__int64)));
  370. #else
  371. fprintf(fout, "SET(KWSYS_SIZEOF___INT64 0) # No __int64 available.\n");
  372. #endif
  373. /* Set the size of some pointer types. */
  374. fprintf(fout, "SET(KWSYS_SIZEOF_PDATA %d)\n", static_cast<int>(sizeof(void*)));
  375. fprintf(fout, "SET(KWSYS_SIZEOF_PFUNC %d)\n", static_cast<int>(sizeof(&f)));
  376. /* Set whether the native type "char" is signed or unsigned. */
  377. unsigned char uc = 255;
  378. fprintf(fout, "SET(KWSYS_CHAR_IS_SIGNED %d)\n",
  379. (*reinterpret_cast<char*>(&uc) < 0)?1:0);
  380. fclose(fout);
  381. return 0;
  382. }
  383. else
  384. {
  385. fprintf(stderr, "Failed to write fundamental type info to \"%s\".\n",
  386. fname);
  387. return 1;
  388. }
  389. }
  390. #endif