kwsysPlatformTestsCXX.cxx 5.7 KB

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