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