kwsysPlatformTestsCXX.cxx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. /*============================================================================
  2. KWSys - Kitware System Library
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifdef TEST_KWSYS_CXX_HAS_CSTDIO
  11. #include <cstdio>
  12. int main() { return 0; }
  13. #endif
  14. #ifdef TEST_KWSYS_CXX_HAS_LONG_LONG
  15. long long f(long long n) { return n; }
  16. int main()
  17. {
  18. long long n = 0;
  19. return static_cast<int>(f(n));
  20. }
  21. #endif
  22. #ifdef TEST_KWSYS_CXX_HAS___INT64
  23. __int64 f(__int64 n) { return n; }
  24. int main()
  25. {
  26. __int64 n = 0;
  27. return static_cast<int>(f(n));
  28. }
  29. #endif
  30. #ifdef TEST_KWSYS_CXX_STAT_HAS_ST_MTIM
  31. #include <sys/types.h>
  32. #include <sys/stat.h>
  33. #include <unistd.h>
  34. int main()
  35. {
  36. struct stat stat1;
  37. (void)stat1.st_mtim.tv_sec;
  38. (void)stat1.st_mtim.tv_nsec;
  39. return 0;
  40. }
  41. #endif
  42. #ifdef TEST_KWSYS_CXX_STAT_HAS_ST_MTIMESPEC
  43. #include <sys/types.h>
  44. #include <sys/stat.h>
  45. #include <unistd.h>
  46. int main()
  47. {
  48. struct stat stat1;
  49. (void)stat1.st_mtimespec.tv_sec;
  50. (void)stat1.st_mtimespec.tv_nsec;
  51. return 0;
  52. }
  53. #endif
  54. #ifdef TEST_KWSYS_CXX_SAME_LONG_AND___INT64
  55. void function(long**) {}
  56. int main()
  57. {
  58. __int64** p = 0;
  59. function(p);
  60. return 0;
  61. }
  62. #endif
  63. #ifdef TEST_KWSYS_CXX_SAME_LONG_LONG_AND___INT64
  64. void function(long long**) {}
  65. int main()
  66. {
  67. __int64** p = 0;
  68. function(p);
  69. return 0;
  70. }
  71. #endif
  72. #ifdef TEST_KWSYS_IOS_HAS_ISTREAM_LONG_LONG
  73. # include <iostream>
  74. int test_istream(std::istream& is, long long& x)
  75. {
  76. return (is >> x)? 1:0;
  77. }
  78. int main()
  79. {
  80. long long x = 0;
  81. return test_istream(std::cin, x);
  82. }
  83. #endif
  84. #ifdef TEST_KWSYS_IOS_HAS_OSTREAM_LONG_LONG
  85. # include <iostream>
  86. int test_ostream(std::ostream& os, long long x)
  87. {
  88. return (os << x)? 1:0;
  89. }
  90. int main()
  91. {
  92. long long x = 0;
  93. return test_ostream(std::cout, x);
  94. }
  95. #endif
  96. #ifdef TEST_KWSYS_IOS_HAS_ISTREAM___INT64
  97. # include <iostream>
  98. int test_istream(std::istream& is, __int64& x)
  99. {
  100. return (is >> x)? 1:0;
  101. }
  102. int main()
  103. {
  104. __int64 x = 0;
  105. return test_istream(std::cin, x);
  106. }
  107. #endif
  108. #ifdef TEST_KWSYS_IOS_HAS_OSTREAM___INT64
  109. # include <iostream>
  110. int test_ostream(std::ostream& os, __int64 x)
  111. {
  112. return (os << x)? 1:0;
  113. }
  114. int main()
  115. {
  116. __int64 x = 0;
  117. return test_ostream(std::cout, x);
  118. }
  119. #endif
  120. #ifdef TEST_KWSYS_LFS_WORKS
  121. /* Return 0 when LFS is available and 1 otherwise. */
  122. #define _LARGEFILE_SOURCE
  123. #define _LARGEFILE64_SOURCE
  124. #define _LARGE_FILES
  125. #define _FILE_OFFSET_BITS 64
  126. #include <sys/types.h>
  127. #include <sys/stat.h>
  128. #include <assert.h>
  129. #if KWSYS_CXX_HAS_CSTDIO
  130. # include <cstdio>
  131. #endif
  132. #include <stdio.h>
  133. int main(int, char **argv)
  134. {
  135. /* check that off_t can hold 2^63 - 1 and perform basic operations... */
  136. #define OFF_T_64 (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
  137. if (OFF_T_64 % 2147483647 != 1)
  138. return 1;
  139. // stat breaks on SCO OpenServer
  140. struct stat buf;
  141. stat( argv[0], &buf );
  142. if (!S_ISREG(buf.st_mode))
  143. return 2;
  144. FILE *file = fopen( argv[0], "r" );
  145. off_t offset = ftello( file );
  146. fseek( file, offset, SEEK_CUR );
  147. fclose( file );
  148. return 0;
  149. }
  150. #endif
  151. #ifdef TEST_KWSYS_CXX_HAS_SETENV
  152. #include <stdlib.h>
  153. int main()
  154. {
  155. return setenv("A", "B", 1);
  156. }
  157. #endif
  158. #ifdef TEST_KWSYS_CXX_HAS_UNSETENV
  159. #include <stdlib.h>
  160. int main()
  161. {
  162. unsetenv("A");
  163. return 0;
  164. }
  165. #endif
  166. #ifdef TEST_KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H
  167. #include <stdlib.h>
  168. int main()
  169. {
  170. char* e = environ[0];
  171. return e? 0:1;
  172. }
  173. #endif
  174. #ifdef TEST_KWSYS_CXX_HAS_GETLOADAVG
  175. // Match feature definitions from SystemInformation.cxx
  176. #if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE)
  177. # define _GNU_SOURCE
  178. #endif
  179. #include <stdlib.h>
  180. int main()
  181. {
  182. double loadavg[3] = { 0.0, 0.0, 0.0 };
  183. return getloadavg(loadavg, 3);
  184. }
  185. #endif
  186. #ifdef TEST_KWSYS_CXX_HAS_RLIMIT64
  187. # if defined(KWSYS_HAS_LFS)
  188. # define _LARGEFILE_SOURCE
  189. # define _LARGEFILE64_SOURCE
  190. # define _LARGE_FILES
  191. # define _FILE_OFFSET_BITS 64
  192. # endif
  193. # include <sys/resource.h>
  194. int main()
  195. {
  196. struct rlimit64 rlim;
  197. return getrlimit64(0,&rlim);
  198. }
  199. #endif
  200. #ifdef TEST_KWSYS_CXX_HAS_ATOLL
  201. #include <stdlib.h>
  202. int main()
  203. {
  204. const char *str="1024";
  205. return static_cast<int>(atoll(str));
  206. }
  207. #endif
  208. #ifdef TEST_KWSYS_CXX_HAS_ATOL
  209. #include <stdlib.h>
  210. int main()
  211. {
  212. const char *str="1024";
  213. return static_cast<int>(atol(str));
  214. }
  215. #endif
  216. #ifdef TEST_KWSYS_CXX_HAS__ATOI64
  217. #include <stdlib.h>
  218. int main()
  219. {
  220. const char *str="1024";
  221. return static_cast<int>(_atoi64(str));
  222. }
  223. #endif
  224. #ifdef TEST_KWSYS_CXX_HAS_UTIMES
  225. #include <sys/time.h>
  226. int main()
  227. {
  228. struct timeval* current_time = 0;
  229. return utimes("/example", current_time);
  230. }
  231. #endif
  232. #ifdef TEST_KWSYS_CXX_HAS_UTIMENSAT
  233. #include <fcntl.h>
  234. #include <sys/stat.h>
  235. int main()
  236. {
  237. struct timespec times[2] = {{0,UTIME_OMIT},{0,UTIME_NOW}};
  238. return utimensat(AT_FDCWD, "/example", times, AT_SYMLINK_NOFOLLOW);
  239. }
  240. #endif
  241. #ifdef TEST_KWSYS_CXX_HAS_BACKTRACE
  242. #if defined(__PATHSCALE__) || defined(__PATHCC__) \
  243. || (defined(__LSB_VERSION__) && (__LSB_VERSION__ < 41))
  244. backtrace doesnt work with this compiler or os
  245. #endif
  246. #if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE)
  247. # define _GNU_SOURCE
  248. #endif
  249. #include <execinfo.h>
  250. int main()
  251. {
  252. void *stackSymbols[256];
  253. backtrace(stackSymbols,256);
  254. backtrace_symbols(&stackSymbols[0],1);
  255. return 0;
  256. }
  257. #endif
  258. #ifdef TEST_KWSYS_CXX_HAS_DLADDR
  259. #if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE)
  260. # define _GNU_SOURCE
  261. #endif
  262. #include <dlfcn.h>
  263. int main()
  264. {
  265. Dl_info info;
  266. int ierr=dladdr((void*)main,&info);
  267. return 0;
  268. }
  269. #endif
  270. #ifdef TEST_KWSYS_CXX_HAS_CXXABI
  271. #if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE)
  272. # define _GNU_SOURCE
  273. #endif
  274. #if defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5130 \
  275. && __linux && __SUNPRO_CC_COMPAT == 'G'
  276. # include <iostream>
  277. #endif
  278. #include <cxxabi.h>
  279. int main()
  280. {
  281. int status = 0;
  282. size_t bufferLen = 512;
  283. char buffer[512] = {'\0'};
  284. const char *function="_ZN5kwsys17SystemInformation15GetProgramStackEii";
  285. char *demangledFunction =
  286. abi::__cxa_demangle(function, buffer, &bufferLen, &status);
  287. return status;
  288. }
  289. #endif
  290. #ifdef TEST_KWSYS_CXX_HAS_BORLAND_ASM
  291. int main()
  292. {
  293. int a = 1;
  294. __asm {
  295. xor EBX, EBX;
  296. mov a, EBX;
  297. }
  298. return a;
  299. }
  300. #endif
  301. #ifdef TEST_KWSYS_CXX_HAS_BORLAND_ASM_CPUID
  302. int main()
  303. {
  304. int a = 0;
  305. __asm {
  306. xor EAX, EAX;
  307. cpuid;
  308. mov a, EAX;
  309. }
  310. return a;
  311. }
  312. #endif
  313. #ifdef TEST_KWSYS_STL_HAS_WSTRING
  314. #include <string>
  315. void f(std ::wstring*) {}
  316. int main() { return 0; }
  317. #endif
  318. #ifdef TEST_KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H
  319. #include <ext/stdio_filebuf.h>
  320. int main() { return 0; }
  321. #endif