configure.cmake 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
  1. # xplat-todo: Cleanup this file!
  2. # we have `feature detection` for direct compilation target and manual entries for cross-compilation below
  3. if (NOT CC_TARGET_OS_ANDROID)
  4. include(CheckCXXSourceCompiles)
  5. include(CheckCXXSourceRuns)
  6. include(CheckCXXSymbolExists)
  7. include(CheckFunctionExists)
  8. include(CheckIncludeFiles)
  9. include(CheckStructHasMember)
  10. include(CheckTypeSize)
  11. include(CheckLibraryExists)
  12. if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
  13. set(CMAKE_REQUIRED_INCLUDES /usr/local/include)
  14. elseif(CMAKE_SYSTEM_NAME STREQUAL SunOS)
  15. set(CMAKE_REQUIRED_INCLUDES /opt/local/include)
  16. endif()
  17. if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin AND NOT CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
  18. set(CMAKE_REQUIRED_DEFINITIONS "-D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L")
  19. endif()
  20. list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_FILE_OFFSET_BITS=64)
  21. check_include_files(ieeefp.h HAVE_IEEEFP_H)
  22. check_include_files(alloca.h HAVE_ALLOCA_H)
  23. check_include_files(sys/vmparam.h HAVE_SYS_VMPARAM_H)
  24. check_include_files(mach/vm_types.h HAVE_MACH_VM_TYPES_H)
  25. check_include_files(mach/vm_param.h HAVE_MACH_VM_PARAM_H)
  26. check_include_files(procfs.h HAVE_PROCFS_H)
  27. check_include_files(crt_externs.h HAVE_CRT_EXTERNS_H)
  28. check_include_files(sys/time.h HAVE_SYS_TIME_H)
  29. check_include_files(pthread_np.h HAVE_PTHREAD_NP_H)
  30. check_include_files(sys/lwp.h HAVE_SYS_LWP_H)
  31. check_include_files(runetype.h HAVE_RUNETYPE_H)
  32. check_include_files(unicode/uchar.h HAVE_LIBICU_UCHAR_H)
  33. check_function_exists(kqueue HAVE_KQUEUE)
  34. check_function_exists(getpwuid_r HAVE_GETPWUID_R)
  35. check_library_exists(pthread pthread_suspend "" HAVE_PTHREAD_SUSPEND)
  36. check_library_exists(pthread pthread_suspend_np "" HAVE_PTHREAD_SUSPEND_NP)
  37. check_library_exists(pthread pthread_continue "" HAVE_PTHREAD_CONTINUE)
  38. check_library_exists(pthread pthread_continue_np "" HAVE_PTHREAD_CONTINUE_NP)
  39. check_library_exists(pthread pthread_resume_np "" HAVE_PTHREAD_RESUME_NP)
  40. check_library_exists(pthread pthread_attr_get_np "" HAVE_PTHREAD_ATTR_GET_NP)
  41. check_library_exists(pthread pthread_getattr_np "" HAVE_PTHREAD_GETATTR_NP)
  42. check_library_exists(pthread pthread_sigqueue "" HAVE_PTHREAD_SIGQUEUE)
  43. check_function_exists(sigreturn HAVE_SIGRETURN)
  44. check_function_exists(_thread_sys_sigreturn HAVE__THREAD_SYS_SIGRETURN)
  45. check_function_exists(copysign HAVE_COPYSIGN)
  46. check_function_exists(fsync HAVE_FSYNC)
  47. check_function_exists(futimes HAVE_FUTIMES)
  48. check_function_exists(utimes HAVE_UTIMES)
  49. check_function_exists(sysctl HAVE_SYSCTL)
  50. check_function_exists(sysconf HAVE_SYSCONF)
  51. check_function_exists(localtime_r HAVE_LOCALTIME_R)
  52. check_function_exists(gmtime_r HAVE_GMTIME_R)
  53. check_function_exists(timegm HAVE_TIMEGM)
  54. check_function_exists(_snwprintf HAVE__SNWPRINTF)
  55. check_function_exists(poll HAVE_POLL)
  56. check_function_exists(statvfs HAVE_STATVFS)
  57. check_function_exists(thread_self HAVE_THREAD_SELF)
  58. check_function_exists(_lwp_self HAVE__LWP_SELF)
  59. check_function_exists(pthread_mach_thread_np HAVE_MACH_THREADS)
  60. check_function_exists(thread_set_exception_ports HAVE_MACH_EXCEPTIONS)
  61. check_function_exists(vm_allocate HAVE_VM_ALLOCATE)
  62. check_function_exists(vm_read HAVE_VM_READ)
  63. check_function_exists(directio HAVE_DIRECTIO)
  64. check_function_exists(semget HAS_SYSV_SEMAPHORES)
  65. check_function_exists(pthread_mutex_init HAS_PTHREAD_MUTEXES)
  66. check_function_exists(ttrace HAVE_TTRACE)
  67. check_struct_has_member ("struct stat" st_atimespec "sys/types.h;sys/stat.h" HAVE_STAT_TIMESPEC)
  68. check_struct_has_member ("struct stat" st_atimensec "sys/types.h;sys/stat.h" HAVE_STAT_NSEC)
  69. check_struct_has_member ("struct tm" tm_gmtoff time.h HAVE_TM_GMTOFF)
  70. check_struct_has_member ("ucontext_t" uc_mcontext.gregs[0] ucontext.h HAVE_GREGSET_T)
  71. set(CMAKE_EXTRA_INCLUDE_FILES machine/reg.h)
  72. check_type_size("struct reg" BSD_REGS_T)
  73. set(CMAKE_EXTRA_INCLUDE_FILES)
  74. set(CMAKE_EXTRA_INCLUDE_FILES asm/ptrace.h)
  75. check_type_size("struct pt_regs" PT_REGS)
  76. set(CMAKE_EXTRA_INCLUDE_FILES)
  77. set(CMAKE_EXTRA_INCLUDE_FILES signal.h)
  78. check_type_size(siginfo_t SIGINFO_T)
  79. set(CMAKE_EXTRA_INCLUDE_FILES)
  80. set(CMAKE_EXTRA_INCLUDE_FILES ucontext.h)
  81. check_type_size(ucontext_t UCONTEXT_T)
  82. set(CMAKE_EXTRA_INCLUDE_FILES)
  83. set(CMAKE_EXTRA_INCLUDE_FILES pthread.h)
  84. check_type_size(pthread_rwlock_t PTHREAD_RWLOCK_T)
  85. set(CMAKE_EXTRA_INCLUDE_FILES)
  86. set(CMAKE_EXTRA_INCLUDE_FILE procfs.h)
  87. check_type_size(prwatch_t PRWATCH_T)
  88. set(CMAKE_EXTRA_INCLUDE_FILE)
  89. check_type_size(off_t SIZEOF_OFF_T)
  90. check_cxx_symbol_exists(SYS_yield sys/syscall.h HAVE_YIELD_SYSCALL)
  91. check_cxx_symbol_exists(INFTIM poll.h HAVE_INFTIM)
  92. check_cxx_symbol_exists(CHAR_BIT sys/limits.h HAVE_CHAR_BIT)
  93. check_cxx_symbol_exists(_DEBUG sys/user.h USER_H_DEFINES_DEBUG)
  94. check_cxx_symbol_exists(_SC_PHYS_PAGES unistd.h HAVE__SC_PHYS_PAGES)
  95. check_cxx_symbol_exists(_SC_AVPHYS_PAGES unistd.h HAVE__SC_AVPHYS_PAGES)
  96. check_cxx_source_runs("
  97. #include <stdlib.h>
  98. #include <stdio.h>
  99. extern \"C++\" {
  100. inline long long abs(long long _X) {
  101. return llabs(_X);
  102. }
  103. }
  104. int main(int argc, char **argv) {
  105. long long X = 123456789 + argc;
  106. printf(\"%lld\", abs(X));
  107. exit(0);
  108. }" PLATFORM_ACCEPTS_ABS_OVERLOAD)
  109. check_cxx_source_runs("
  110. #include <sys/param.h>
  111. #include <stdlib.h>
  112. int main(void) {
  113. char *path;
  114. #ifdef PATH_MAX
  115. char resolvedPath[PATH_MAX];
  116. #elif defined(MAXPATHLEN)
  117. char resolvedPath[MAXPATHLEN];
  118. #else
  119. char resolvedPath[1024];
  120. #endif
  121. path = realpath(\"a_nonexistent_file\", resolvedPath);
  122. if (path == NULL) {
  123. exit(1);
  124. }
  125. exit(0);
  126. }" REALPATH_SUPPORTS_NONEXISTENT_FILES)
  127. check_cxx_source_runs("
  128. #include <stdio.h>
  129. #include <stdlib.h>
  130. int main(void)
  131. {
  132. long long n = 0;
  133. sscanf(\"5000000000\", \"%qu\", &n);
  134. exit (n != 5000000000);
  135. }" SSCANF_SUPPORT_ll)
  136. check_cxx_source_runs("
  137. #include <stdio.h>
  138. #include <stdlib.h>
  139. int main()
  140. {
  141. int ret;
  142. float f = 0;
  143. char * strin = \"12.34e\";
  144. ret = sscanf (strin, \"%e\", &f);
  145. if (ret <= 0)
  146. exit (0);
  147. exit(1);
  148. }" SSCANF_CANNOT_HANDLE_MISSING_EXPONENT)
  149. check_cxx_source_runs("
  150. #include <stdio.h>
  151. #include <stdlib.h>
  152. int main(void) {
  153. char buf[256] = { 0 };
  154. snprintf(buf, 0x7fffffff, \"%#x\", 0x12345678);
  155. if (buf[0] == 0x0) {
  156. exit(1);
  157. }
  158. exit(0);
  159. }" HAVE_LARGE_SNPRINTF_SUPPORT)
  160. check_cxx_source_runs("
  161. #include <stdio.h>
  162. #include <stdlib.h>
  163. #include <fcntl.h>
  164. #include <string.h>
  165. #include <sys/stat.h>
  166. #include <sys/types.h>
  167. #include <sys/time.h>
  168. #include <unistd.h>
  169. int main(void) {
  170. int fd, numFDs;
  171. fd_set readFDs, writeFDs, exceptFDs;
  172. struct timeval time = { 0 };
  173. char * filename = NULL;
  174. filename = (char *)malloc(L_tmpnam * sizeof(char)); /* ok to leak this at exit */
  175. if (NULL == filename) {
  176. exit(0);
  177. }
  178. /* On some platforms (e.g. HP-UX) the multithreading c-runtime does not
  179. support the tmpnam(NULL) semantics, and it returns NULL. Therefore
  180. we need to use the tmpnam(pbuffer) version.
  181. */
  182. if (NULL == tmpnam(filename)) {
  183. exit(0);
  184. }
  185. if (mkfifo(filename, S_IRWXU) != 0) {
  186. if (unlink(filename) != 0) {
  187. exit(0);
  188. }
  189. if (mkfifo(filename, S_IRWXU) != 0) {
  190. exit(0);
  191. }
  192. }
  193. fd = open(filename, O_RDWR | O_NONBLOCK);
  194. if (fd == -1) {
  195. exit(0);
  196. }
  197. FD_ZERO(&readFDs);
  198. FD_ZERO(&writeFDs);
  199. FD_ZERO(&exceptFDs);
  200. FD_SET(fd, &readFDs);
  201. numFDs = select(fd + 1, &readFDs, &writeFDs, &exceptFDs, &time);
  202. close(fd);
  203. unlink(filename);
  204. /* numFDs is zero if select() works correctly */
  205. exit(numFD==0);
  206. }" HAVE_BROKEN_FIFO_SELECT)
  207. check_cxx_source_runs("
  208. #include <stdio.h>
  209. #include <stdlib.h>
  210. #include <unistd.h>
  211. #include <fcntl.h>
  212. #include <string.h>
  213. #include <errno.h>
  214. #include <sys/types.h>
  215. #include <sys/event.h>
  216. #include <sys/time.h>
  217. #include <sys/stat.h>
  218. int main(void)
  219. {
  220. int ikq;
  221. int iRet;
  222. int fd;
  223. struct kevent ke, keChangeList;
  224. struct timespec ts = { 0, 0 };
  225. char * filename = NULL;
  226. filename = (char *)malloc(L_tmpnam * sizeof(char)); /* ok to leak this at exit */
  227. if (NULL == filename)
  228. {
  229. exit(1);
  230. }
  231. /* On some platforms (e.g. HP-UX) the multithreading c-runtime does not
  232. support the tmpnam(NULL) semantics, and it returns NULL. Therefore
  233. we need to use the tmpnam(pbuffer) version.
  234. */
  235. if (NULL == tmpnam(filename)) {
  236. exit(0);
  237. }
  238. if (mkfifo(filename, S_IRWXU) != 0) {
  239. if (unlink(filename) != 0) {
  240. exit(0);
  241. }
  242. if (mkfifo(filename, S_IRWXU) != 0) {
  243. exit(0);
  244. }
  245. }
  246. fd = open(filename, O_RDWR | O_NONBLOCK);
  247. if (fd == -1) {
  248. exit(0);
  249. }
  250. EV_SET(&keChangeList, fd, EVFILT_READ, EV_ADD | EV_CLEAR, 0, 0, NULL);
  251. ikq = kqueue();
  252. iRet = kevent(ikq, &keChangeList, 1, &ke, 1, &ts);
  253. close(fd);
  254. unlink(filename);
  255. /* iRet is zero is kevent() works correctly */
  256. return(iRet==0);
  257. }" HAVE_BROKEN_FIFO_KEVENT)
  258. set(CMAKE_REQUIRED_LIBRARIES pthread)
  259. check_cxx_source_runs("
  260. #include <stdio.h>
  261. #include <stdlib.h>
  262. #include <pthread.h>
  263. #include <sched.h>
  264. int main(void)
  265. {
  266. int policy;
  267. struct sched_param schedParam;
  268. int max_priority;
  269. int min_priority;
  270. if (0 != pthread_getschedparam(pthread_self(), &policy, &schedParam))
  271. {
  272. exit(1);
  273. }
  274. max_priority = sched_get_priority_max(policy);
  275. min_priority = sched_get_priority_min(policy);
  276. exit(-1 == max_priority || -1 == min_priority);
  277. }" HAVE_SCHED_GET_PRIORITY)
  278. set(CMAKE_REQUIRED_LIBRARIES pthread)
  279. check_cxx_source_runs("
  280. #include <stdlib.h>
  281. #include <sched.h>
  282. int main(void)
  283. {
  284. if (sched_getcpu() >= 0)
  285. {
  286. exit(0);
  287. }
  288. exit(1);
  289. }" HAVE_SCHED_GETCPU)
  290. set(CMAKE_REQUIRED_LIBRARIES)
  291. check_cxx_source_runs("
  292. #include <stdlib.h>
  293. #include <time.h>
  294. #include <sys/time.h>
  295. int main()
  296. {
  297. int ret;
  298. struct timeval tv;
  299. ret = gettimeofday(&tv, NULL);
  300. exit(ret);
  301. }" HAVE_WORKING_GETTIMEOFDAY)
  302. check_cxx_source_runs("
  303. #include <stdlib.h>
  304. #include <time.h>
  305. #include <sys/time.h>
  306. int main()
  307. {
  308. int ret;
  309. #ifndef __APPLE__
  310. struct timespec ts;
  311. ret = clock_gettime(CLOCK_REALTIME, &ts);
  312. #else
  313. ret = 1; // do not use clock_gettime on osx/ios (backward compatibility)
  314. #endif
  315. exit(ret);
  316. }" HAVE_WORKING_CLOCK_GETTIME)
  317. check_cxx_source_runs("
  318. #include <stdlib.h>
  319. #include <time.h>
  320. #include <sys/time.h>
  321. int main()
  322. {
  323. int ret;
  324. #ifndef __APPLE__
  325. struct timespec ts;
  326. ret = clock_gettime(CLOCK_MONOTONIC, &ts);
  327. #else
  328. ret = 1; // do not use clock_gettime on osx/ios (backward compatibility)
  329. #endif
  330. exit(ret);
  331. }" HAVE_CLOCK_MONOTONIC)
  332. check_cxx_source_runs("
  333. #include <stdlib.h>
  334. #include <time.h>
  335. #include <sys/time.h>
  336. int main()
  337. {
  338. int ret;
  339. #ifndef __APPLE__
  340. struct timespec ts;
  341. ret = clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
  342. #else
  343. ret = 1; // do not use clock_gettime on osx/ios (backward compatibility)
  344. #endif
  345. exit(ret);
  346. }" HAVE_CLOCK_MONOTONIC_COARSE)
  347. check_cxx_source_runs("
  348. #include <stdlib.h>
  349. #include <mach/mach_time.h>
  350. int main()
  351. {
  352. int ret;
  353. mach_timebase_info_data_t timebaseInfo;
  354. ret = mach_timebase_info(&timebaseInfo);
  355. mach_absolute_time();
  356. exit(ret);
  357. }" HAVE_MACH_ABSOLUTE_TIME)
  358. check_cxx_source_runs("
  359. #include <stdlib.h>
  360. #include <time.h>
  361. #include <sys/time.h>
  362. int main()
  363. {
  364. int ret;
  365. #ifndef __APPLE__
  366. struct timespec ts;
  367. ret = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
  368. #else
  369. ret = 1; // do not use clock_gettime on osx/ios (backward compatibility)
  370. #endif
  371. exit(ret);
  372. }" HAVE_CLOCK_THREAD_CPUTIME)
  373. check_cxx_source_runs("
  374. #include <stdlib.h>
  375. #include <sys/types.h>
  376. #include <sys/mman.h>
  377. #include <fcntl.h>
  378. int main(void) {
  379. int devzero;
  380. void *retval;
  381. devzero = open(\"/dev/zero\", O_RDWR);
  382. if (-1 == devzero) {
  383. exit(1);
  384. }
  385. retval = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, devzero, 0);
  386. if (retval == (void *)-1) {
  387. exit(1);
  388. }
  389. exit(0);
  390. }" HAVE_MMAP_DEV_ZERO)
  391. check_cxx_source_runs("
  392. #include <fcntl.h>
  393. #include <stdlib.h>
  394. #include <sys/types.h>
  395. #include <sys/mman.h>
  396. #include <unistd.h>
  397. #ifndef MAP_ANON
  398. #define MAP_ANON MAP_ANONYMOUS
  399. #endif
  400. int main(void) {
  401. void *hint, *ptr;
  402. int pagesize;
  403. int fd;
  404. pagesize = getpagesize();
  405. fd = open(\"/etc/passwd\", O_RDONLY);
  406. if (fd == -1) {
  407. exit(0);
  408. }
  409. ptr = mmap(NULL, pagesize, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0);
  410. if (ptr == MAP_FAILED) {
  411. exit(0);
  412. }
  413. hint = mmap(NULL, pagesize, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0);
  414. if (hint == MAP_FAILED) {
  415. exit(0);
  416. }
  417. if (munmap(ptr, pagesize) != 0) {
  418. exit(0);
  419. }
  420. if (munmap(hint, pagesize) != 0) {
  421. exit(0);
  422. }
  423. ptr = mmap(hint, pagesize, PROT_NONE, MAP_FIXED | MAP_PRIVATE, fd, 0);
  424. if (ptr == MAP_FAILED || ptr != hint) {
  425. exit(0);
  426. }
  427. exit(1);
  428. }" MMAP_IGNORES_HINT)
  429. check_cxx_source_runs("
  430. #include <sys/types.h>
  431. #include <sys/mman.h>
  432. #include <signal.h>
  433. #include <stdlib.h>
  434. #include <unistd.h>
  435. #ifndef MAP_ANON
  436. #define MAP_ANON MAP_ANONYMOUS
  437. #endif
  438. void *handle_signal(int signal) {
  439. /* If we reach this, we've crashed due to mmap honoring
  440. PROT_NONE. */
  441. _exit(1);
  442. }
  443. int main(void) {
  444. int *ptr;
  445. struct sigaction action;
  446. ptr = (int *) mmap(NULL, getpagesize(), PROT_NONE,
  447. MAP_ANON | MAP_PRIVATE, -1, 0);
  448. if (ptr == (int *) MAP_FAILED) {
  449. exit(0);
  450. }
  451. action.sa_handler = &handle_signal;
  452. action.sa_flags = 0;
  453. sigemptyset(&action.sa_mask);
  454. if (sigaction(SIGBUS, &action, NULL) != 0) {
  455. exit(0);
  456. }
  457. if (sigaction(SIGSEGV, &action, NULL) != 0) {
  458. exit(0);
  459. }
  460. /* This will drop us into the signal handler if PROT_NONE
  461. is honored. */
  462. *ptr = 123;
  463. exit(0);
  464. }" MMAP_ANON_IGNORES_PROTECTION)
  465. check_cxx_source_runs("
  466. #include <stdlib.h>
  467. #include <unistd.h>
  468. #include <sys/types.h>
  469. #include <sys/mman.h>
  470. #ifndef MAP_ANON
  471. #define MAP_ANON MAP_ANONYMOUS
  472. #endif
  473. int main()
  474. {
  475. int iRet = 1;
  476. void * pAddr = MAP_FAILED;
  477. int MemSize = 1024;
  478. MemSize = getpagesize();
  479. pAddr = mmap(0x0, MemSize, PROT_NONE, MAP_PRIVATE | MAP_ANON, -1, 0);
  480. if (pAddr == MAP_FAILED)
  481. exit(0);
  482. pAddr = mmap(pAddr, MemSize, PROT_WRITE | PROT_READ, MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0);
  483. if (pAddr == MAP_FAILED)
  484. iRet = 0;
  485. munmap(pAddr, MemSize); // don't care of this
  486. exit (iRet);
  487. }" MMAP_DOESNOT_ALLOW_REMAP)
  488. check_cxx_source_runs("
  489. #include <stdio.h>
  490. #include <unistd.h>
  491. #include <stdlib.h>
  492. #include <string.h>
  493. #include <sys/types.h>
  494. #include <sys/mman.h>
  495. #define MEM_SIZE 1024
  496. int main(void)
  497. {
  498. char * fname;
  499. int fd;
  500. int ret;
  501. void * pAddr0, * pAddr1;
  502. fname = (char *)malloc(MEM_SIZE);
  503. if (!fname)
  504. exit(1);
  505. strcpy(fname, \"/tmp/name/multiplemaptestXXXXXX\");
  506. fd = mkstemp(fname);
  507. if (fd < 0)
  508. exit(1);
  509. ret = write (fd, (void *)fname, MEM_SIZE);
  510. if (ret < 0)
  511. exit(1);
  512. pAddr0 = mmap(0, MEM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  513. pAddr1 = mmap(0, MEM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  514. /* In theory we should look for (pAddr1 == MAP_FAILED) && (pAddr1 != MAP_FAILED)
  515. but in case the first test also failed, i.e. we failed to run the test,
  516. let's assume that the system might not allow multiple shared mapping of the
  517. same file region in the same process. The code enabled in this case is
  518. only a fall-back code path. In case the double mmap actually works, virtually
  519. nothing will change and the normal code path will be executed */
  520. if (pAddr1 == MAP_FAILED)
  521. ret = 1;
  522. else
  523. ret = 0;
  524. if (pAddr0)
  525. munmap (pAddr0, MEM_SIZE);
  526. if (pAddr1)
  527. munmap (pAddr1, MEM_SIZE);
  528. close(fd);
  529. unlink(fname);
  530. free(fname);
  531. exit(ret != 1);
  532. }" ONE_SHARED_MAPPING_PER_FILEREGION_PER_PROCESS)
  533. set(CMAKE_REQUIRED_LIBRARIES pthread)
  534. check_cxx_source_runs("
  535. #include <errno.h>
  536. #include <pthread.h>
  537. #include <stdlib.h>
  538. void *start_routine(void *param) { return NULL; }
  539. int main() {
  540. int result;
  541. pthread_t tid;
  542. errno = 0;
  543. result = pthread_create(&tid, NULL, start_routine, NULL);
  544. if (result != 0) {
  545. exit(1);
  546. }
  547. if (errno != 0) {
  548. exit(0);
  549. }
  550. exit(1);
  551. }" PTHREAD_CREATE_MODIFIES_ERRNO)
  552. set(CMAKE_REQUIRED_LIBRARIES)
  553. set(CMAKE_REQUIRED_LIBRARIES pthread)
  554. check_cxx_source_runs("
  555. #include <errno.h>
  556. #include <semaphore.h>
  557. #include <stdlib.h>
  558. int main() {
  559. int result;
  560. sem_t sema;
  561. errno = 50;
  562. result = sem_init(&sema, 0, 0);
  563. if (result != 0)
  564. {
  565. exit(1);
  566. }
  567. if (errno != 50)
  568. {
  569. exit(0);
  570. }
  571. exit(1);
  572. }" SEM_INIT_MODIFIES_ERRNO)
  573. set(CMAKE_REQUIRED_LIBRARIES)
  574. check_cxx_source_runs("
  575. #include <fcntl.h>
  576. #include <stdlib.h>
  577. #include <stdio.h>
  578. #include <unistd.h>
  579. int main(void) {
  580. int fd;
  581. #ifdef PATH_MAX
  582. char path[PATH_MAX];
  583. #elif defined(MAXPATHLEN)
  584. char path[MAXPATHLEN];
  585. #else
  586. char path[1024];
  587. #endif
  588. sprintf(path, \"/proc/%u/$1\", getpid());
  589. fd = open(path, $2);
  590. if (fd == -1) {
  591. exit(1);
  592. }
  593. exit(0);
  594. }" HAVE_PROCFS_CTL)
  595. set(CMAKE_REQUIRED_LIBRARIES m)
  596. check_cxx_source_runs("
  597. #include <math.h>
  598. #include <stdlib.h>
  599. int main(void) {
  600. if (!isnan(acos(10))) {
  601. exit(1);
  602. }
  603. exit(0);
  604. }" HAVE_COMPATIBLE_ACOS)
  605. set(CMAKE_REQUIRED_LIBRARIES)
  606. set(CMAKE_REQUIRED_LIBRARIES m)
  607. check_cxx_source_runs("
  608. #include <math.h>
  609. #include <stdlib.h>
  610. int main(void) {
  611. if (!isnan(asin(10))) {
  612. exit(1);
  613. }
  614. exit(0);
  615. }" HAVE_COMPATIBLE_ASIN)
  616. set(CMAKE_REQUIRED_LIBRARIES)
  617. set(CMAKE_REQUIRED_LIBRARIES m)
  618. check_cxx_source_runs("
  619. #include <math.h>
  620. #include <stdlib.h>
  621. int main(void) {
  622. double pi = 3.14159265358979323846;
  623. double result;
  624. result = atan2(0.0, -0.0);
  625. if (fabs(pi - result) > 0.0000001) {
  626. exit(1);
  627. }
  628. result = atan2(-0.0, -0.0);
  629. if (fabs(-pi - result) > 0.0000001) {
  630. exit(1);
  631. }
  632. result = atan2 (-0.0, 0.0);
  633. if (result != 0.0 || copysign (1.0, result) > 0) {
  634. exit(1);
  635. }
  636. result = atan2 (0.0, 0.0);
  637. if (result != 0.0 || copysign (1.0, result) < 0) {
  638. exit(1);
  639. }
  640. exit (0);
  641. }" HAVE_COMPATIBLE_ATAN2)
  642. set(CMAKE_REQUIRED_LIBRARIES)
  643. set(CMAKE_REQUIRED_LIBRARIES m)
  644. check_cxx_source_runs("
  645. #include <math.h>
  646. #include <stdlib.h>
  647. int main(void) {
  648. double d = exp(1.0), e = M_E;
  649. /* Used memcmp rather than == to test that the doubles are equal to
  650. prevent gcc's optimizer from using its 80 bit internal long
  651. doubles. If you use ==, then on BSD you get a false negative since
  652. exp(1.0) == M_E to 64 bits, but not 80.
  653. */
  654. if (memcmp (&d, &e, sizeof (double)) == 0) {
  655. exit(0);
  656. }
  657. exit(1);
  658. }" HAVE_COMPATIBLE_EXP)
  659. set(CMAKE_REQUIRED_LIBRARIES)
  660. set(CMAKE_REQUIRED_LIBRARIES m)
  661. check_cxx_source_runs("
  662. #include <math.h>
  663. #include <stdlib.h>
  664. int main(void) {
  665. if (!isnan(log(-10000))) {
  666. exit(1);
  667. }
  668. exit(0);
  669. }" HAVE_COMPATIBLE_LOG)
  670. set(CMAKE_REQUIRED_LIBRARIES)
  671. set(CMAKE_REQUIRED_LIBRARIES m)
  672. check_cxx_source_runs("
  673. #include <math.h>
  674. #include <stdlib.h>
  675. int main(void) {
  676. if (!isnan(log10(-10000))) {
  677. exit(1);
  678. }
  679. exit(0);
  680. }" HAVE_COMPATIBLE_LOG10)
  681. set(CMAKE_REQUIRED_LIBRARIES)
  682. check_cxx_source_runs("
  683. #include <stdio.h>
  684. #include <stdlib.h>
  685. #include <unistd.h>
  686. int main(void)
  687. {
  688. char* szFileName;
  689. FILE* pFile = NULL;
  690. int ret = 1;
  691. szFileName = tempnam(\".\", \"tmp\");
  692. /* open the file write-only */
  693. pFile = fopen(szFileName, \"a\");
  694. if (pFile == NULL)
  695. {
  696. exit(0);
  697. }
  698. if (ungetc('A', pFile) != EOF)
  699. {
  700. ret = 0;
  701. }
  702. unlink(szFileName);
  703. exit(ret);
  704. }" UNGETC_NOT_RETURN_EOF)
  705. set(CMAKE_REQUIRED_LIBRARIES pthread)
  706. check_cxx_source_runs("
  707. #include <stdlib.h>
  708. #include <errno.h>
  709. #include <semaphore.h>
  710. int main() {
  711. sem_t sema;
  712. if (sem_init(&sema, 0, 0) == -1){
  713. exit(1);
  714. }
  715. exit(0);
  716. }" HAS_POSIX_SEMAPHORES)
  717. set(CMAKE_REQUIRED_LIBRARIES)
  718. check_cxx_source_runs("
  719. #include <sys/types.h>
  720. #include <pwd.h>
  721. #include <errno.h>
  722. #include <unistd.h>
  723. #include <stdlib.h>
  724. int main(void)
  725. {
  726. struct passwd sPasswd;
  727. struct passwd *pPasswd;
  728. char buf[1];
  729. int bufLen = sizeof(buf)/sizeof(buf[0]);
  730. int euid = geteuid();
  731. int ret = 0;
  732. errno = 0; // clear errno
  733. ret = getpwuid_r(euid, &sPasswd, buf, bufLen, &pPasswd);
  734. if (0 != ret)
  735. {
  736. if (ERANGE == errno)
  737. {
  738. return 0;
  739. }
  740. }
  741. return 1; // assume errno is NOT set for all other cases
  742. }" GETPWUID_R_SETS_ERRNO)
  743. check_cxx_source_runs("
  744. #include <stdio.h>
  745. #include <stdlib.h>
  746. int main()
  747. {
  748. FILE *fp = NULL;
  749. char *fileName = \"/dev/zero\";
  750. char buf[10];
  751. /*
  752. * Open the file in append mode and try to read some text.
  753. * And, make sure ferror() is set.
  754. */
  755. fp = fopen (fileName, \"a\");
  756. if ( (NULL == fp) ||
  757. (fread (buf, sizeof(buf), 1, fp) > 0) ||
  758. (!ferror(fp))
  759. )
  760. {
  761. return 0;
  762. }
  763. /*
  764. * Now that ferror() is set, try to close the file.
  765. * If we get an error, we can conclude that this
  766. * fgets() depended on the previous ferror().
  767. */
  768. if ( fclose(fp) != 0 )
  769. {
  770. return 0;
  771. }
  772. return 1;
  773. }" FILE_OPS_CHECK_FERROR_OF_PREVIOUS_CALL)
  774. set(CMAKE_REQUIRED_DEFINITIONS)
  775. set(SYNCHMGR_SUSPENSION_SAFE_CONDITION_SIGNALING 1)
  776. set(ERROR_FUNC_FOR_GLOB_HAS_FIXED_PARAMS 1)
  777. if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
  778. set(HAVE_COREFOUNDATION 1)
  779. set(HAVE__NSGETENVIRON 1)
  780. set(DEADLOCK_WHEN_THREAD_IS_SUSPENDED_WHILE_BLOCKED_ON_MUTEX 1)
  781. set(PAL_PTRACE "ptrace((cmd), (pid), (caddr_t)(addr), (data))")
  782. set(PAL_PT_ATTACH PT_ATTACH)
  783. set(PAL_PT_DETACH PT_DETACH)
  784. set(PAL_PT_READ_D PT_READ_D)
  785. set(PAL_PT_WRITE_D PT_WRITE_D)
  786. set(JA_JP_LOCALE_NAME ja_JP.SJIS)
  787. set(KO_KR_LOCALE_NAME ko_KR.eucKR)
  788. set(ZH_TW_LOCALE_NAME zh_TG.BIG5)
  789. set(HAS_FTRUNCATE_LENGTH_ISSUE 1)
  790. elseif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
  791. set(DEADLOCK_WHEN_THREAD_IS_SUSPENDED_WHILE_BLOCKED_ON_MUTEX 0)
  792. set(PAL_PTRACE "ptrace((cmd), (pid), (caddr_t)(addr), (data))")
  793. set(PAL_PT_ATTACH PT_ATTACH)
  794. set(PAL_PT_DETACH PT_DETACH)
  795. set(PAL_PT_READ_D PT_READ_D)
  796. set(PAL_PT_WRITE_D PT_WRITE_D)
  797. set(JA_JP_LOCALE_NAME ja_JP_LOCALE_NOT_FOUND)
  798. set(KO_KR_LOCALE_NAME ko_KR_LOCALE_NOT_FOUND)
  799. set(ZH_TW_LOCALE_NAME zh_TW_LOCALE_NOT_FOUND)
  800. set(HAS_FTRUNCATE_LENGTH_ISSUE 0)
  801. if(EXISTS "/lib/libc.so.7")
  802. set(FREEBSD_LIBC "/lib/libc.so.7")
  803. else()
  804. message(FATAL_ERROR "Cannot find libc on this system.")
  805. endif()
  806. else() # Anything else is Linux
  807. set(DEADLOCK_WHEN_THREAD_IS_SUSPENDED_WHILE_BLOCKED_ON_MUTEX 0)
  808. set(PAL_PTRACE "ptrace((cmd), (pid), (void*)(addr), (data))")
  809. set(PAL_PT_ATTACH PTRACE_ATTACH)
  810. set(PAL_PT_DETACH PTRACE_DETACH)
  811. set(PAL_PT_READ_D PTRACE_PEEKDATA)
  812. set(PAL_PT_WRITE_D PTRACE_POKEDATA)
  813. set(JA_JP_LOCALE_NAME ja_JP_LOCALE_NOT_FOUND)
  814. set(KO_KR_LOCALE_NAME ko_KR_LOCALE_NOT_FOUND)
  815. set(ZH_TW_LOCALE_NAME zh_TW_LOCALE_NOT_FOUND)
  816. set(HAS_FTRUNCATE_LENGTH_ISSUE 0)
  817. endif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
  818. if(NOT NO_ICU OR EMBED_ICU)
  819. if(NOT HAVE_LIBICU_UCHAR_H)
  820. unset(HAVE_LIBICU_UCHAR_H CACHE)
  821. message(FATAL_ERROR "Cannot find ICU. Try installing libicu-dev or the appropriate packages for your platform. You may also disable icu/unicode with '--no-icu' argument")
  822. endif()
  823. endif()
  824. else() # ANDROID
  825. set(HAVE_IEEEFP_H 0)
  826. set(HAVE_ALLOCA_H 1)
  827. set(HAVE_SYS_VMPARAM_H 0)
  828. set(HAVE_PROCFS_H 0)
  829. set(HAVE_CRT_EXTERNS_H 0)
  830. set(HAVE_SYS_TIME_H 1)
  831. set(HAVE_PTHREAD_NP_H 0)
  832. set(HAVE_SYS_LWP_H 0)
  833. set(HAVE_RUNETYPE_H 0)
  834. set(HAVE_KQUEUE 0)
  835. set(HAVE_GETPWUID_R 1)
  836. set(HAVE_PTHREAD_SUSPEND 1)
  837. set(HAVE_PTHREAD_SUSPEND_NP 1)
  838. set(HAVE_PTHREAD_CONTINUE 1)
  839. # -DHAVE_PTHREAD_RESUME_NP 1
  840. # -DHAVE_PTHREAD_CONTINUE_NP 1
  841. # -DHAVE_PTHREAD_ATTR_GET_NP 1
  842. set(HAVE_PTHREAD_GETATTR_NP 1)
  843. set(HAVE_PTHREAD_SIGQUEUE 1)
  844. set(HAVE_SIGRETURN 1)
  845. set(HAVE__THREAD_SYS_SIGRETURN 1)
  846. set(HAVE_COPYSIGN 1)
  847. set(HAVE_FSYNC 1)
  848. set(HAVE_FUTIMES 0)
  849. set(HAVE_UTIMES 1)
  850. set(HAVE_SYSCTL 0)
  851. set(HAVE_SYSCONF 1)
  852. set(HAVE_LOCALTIME_R 1)
  853. set(HAVE_GMTIME_R 1)
  854. set(HAVE_TIMEGM 1)
  855. set(HAVE_POLL 1)
  856. set(HAVE_STATVFS 1)
  857. set(HAVE_THREAD_SELF 0)
  858. set(HAVE__LWP_SELF 0)
  859. set(HAVE_VM_ALLOCATE 0)
  860. set(HAVE_VM_READ 0)
  861. set(HAS_SYSV_SEMAPHORES 0)
  862. set(HAS_PTHREAD_MUTEXES 1)
  863. # -DHAVE_TTRACE
  864. set(HAVE_STAT_TIMESPEC 0)
  865. set(HAVE_STAT_NSEC 0)
  866. set(HAVE_TM_GMTOFF 1)
  867. # -DHAVE_PT_REGS 1)
  868. # -DHAVE_GREGSET_T
  869. set(HAVE_SIGINFO_T 1)
  870. set(HAVE_UCONTEXT_T 1)
  871. set(HAVE_PTHREAD_RWLOCK_T 1)
  872. set(HAVE_PRWATCH_T 0)
  873. set(HAVE_YIELD_SYSCALL 0)
  874. set(HAVE_INFTIM 0)
  875. set(HAVE_CHAR_BIT 1)
  876. # -DUSER_H_DEFINES_DEBUG 1
  877. set(HAVE__SC_PHYS_PAGES 1)
  878. set(HAVE__SC_AVPHYS_PAGES 1)
  879. # -DREALPATH_SUPPORTS_NONEXISTENT_FILES
  880. # -DSSCANF_CANNOT_HANDLE_MISSING_EXPONENT
  881. # -DSSCANF_SUPPORT_ll
  882. # -DHAVE_LARGE_SNPRINTF_SUPPORT 1)
  883. # -DHAVE_BROKEN_FIFO_SELECT 1)
  884. # -DHAVE_BROKEN_FIFO_KEVENT 1)
  885. # -DHAS_FTRUNCATE_LENGTH_ISSUE
  886. # -DHAVE_SCHED_GET_PRIORITY 1)
  887. # -DHAVE_SCHED_GETCPU 1)
  888. set(HAVE_WORKING_GETTIMEOFDAY 1)
  889. set(HAVE_WORKING_CLOCK_GETTIME 1)
  890. set(HAVE_CLOCK_MONOTONIC 1)
  891. set(HAVE_CLOCK_MONOTONIC_COARSE 1)
  892. set(HAVE_MACH_ABSOLUTE_TIME 0)
  893. set(HAVE_CLOCK_THREAD_CPUTIME 1)
  894. # -DSTATVFS64_PROTOTYPE_BROKEN
  895. # -DHAVE_MMAP_DEV_ZERO
  896. # -DMMAP_IGNORES_HINT
  897. # -DMMAP_ANON_IGNORES_PROTECTION
  898. set(MMAP_DOESNOT_ALLOW_REMAP 1)
  899. # -DONE_SHARED_MAPPING_PER_FILEREGION_PER_PROCESS
  900. # -DPTHREAD_CREATE_MODIFIES_ERRNO 1)
  901. # -DSEM_INIT_MODIFIES_ERRNO 1)
  902. # -DHAVE_PROCFS_CTL
  903. set(HAVE_COMPATIBLE_ACOS 1)
  904. set(HAVE_COMPATIBLE_ASIN 1)
  905. set(HAVE_COMPATIBLE_ATAN2 1)
  906. set(HAVE_COMPATIBLE_EXP 1)
  907. set(HAVE_COMPATIBLE_LOG 1)
  908. set(HAVE_COMPATIBLE_LOG10 1)
  909. set(UNGETC_NOT_RETURN_EOF 1)
  910. set(HAS_POSIX_SEMAPHORES 1)
  911. # -DGETPWUID_R_SETS_ERRNO
  912. # -DFILE_OPS_CHECK_FERROR_OF_PREVIOUS_CALL
  913. # -DPAL_THREAD_PRIORITY_MIN 0
  914. # -DPAL_THREAD_PRIORITY_MAX 0
  915. # -DDEADLOCK_WHEN_THREAD_IS_SUSPENDED_WHILE_BLOCKED_ON_MUTEX
  916. # -DSYNCHMGR_SUSPENSION_SAFE_CONDITION_SIGNALING
  917. # -DERROR_FUNC_FOR_GLOB_HAS_FIXED_PARAMS
  918. # -DHAS_FTRUNCATE_LENGTH_ISSUE
  919. # -DCHECK_TRACE_SPECIFIERS 0)
  920. # -DPROCFS_MEM_NAME=""
  921. # -DHAVE_GETHRTIME 1)
  922. set(HAVE_LOWERCASE_ISO_NAME 1)
  923. set(HAVE_READ_REAL_TIME 1)
  924. set(HAVE_UNDERSCORE_ISO_NAME 0)
  925. set(MKSTEMP64_IS_USED_INSTEAD_OF_MKSTEMP 0)
  926. set(NEED_DLCOMPAT 0)
  927. # set(OPEN64_IS_USED_INSTEAD_OF_OPEN 0)
  928. set(SELF_SUSPEND_FAILS_WITH_NATIVE_SUSPENSION 0)
  929. set(SET_SCHEDPARAM_NEEDS_PRIVS 0)
  930. set(SIGWAIT_FAILS_WHEN_PASSED_FULL_SIGSET 0)
  931. set(SYNCHMGR_PIPE_BASED_THREAD_BLOCKING 0)
  932. set(WRITE_0_BYTES_HANGS_TTY 0)
  933. set(HAVE_FTRUNCATE_LARGE_LENGTH_SUPPORT 1)
  934. set(HAVE_MACH_EXCEPTIONS 0)
  935. set(DEADLOCK_WHEN_THREAD_IS_SUSPENDED_WHILE_BLOCKED_ON_MUTEX 0)
  936. set(PAL_PTRACE "ptrace((cmd), (pid), (void*)(addr), (data))")
  937. set(PAL_PT_ATTACH PTRACE_ATTACH)
  938. set(PAL_PT_DETACH PTRACE_DETACH)
  939. set(PAL_PT_READ_D PTRACE_PEEKDATA)
  940. set(PAL_PT_WRITE_D PTRACE_POKEDATA)
  941. set(JA_JP_LOCALE_NAME ja_JP_LOCALE_NOT_FOUND)
  942. set(KO_KR_LOCALE_NAME ko_KR_LOCALE_NOT_FOUND)
  943. set(ZH_TW_LOCALE_NAME zh_TW_LOCALE_NOT_FOUND)
  944. set(HAS_FTRUNCATE_LENGTH_ISSUE 0)
  945. endif()
  946. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/pal/src/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/pal/src/config.h)