Add native configurations for SunOS (#34756)
[platform/upstream/dotnet/runtime.git] / src / libraries / Native / Unix / configure.cmake
1 include(CheckCCompilerFlag)
2 include(CheckCSourceCompiles)
3 include(CheckCSourceRuns)
4 include(CheckIncludeFiles)
5 include(CheckPrototypeDefinition)
6 include(CheckStructHasMember)
7 include(CheckSymbolExists)
8 include(CheckTypeSize)
9
10
11 if (CLR_CMAKE_TARGET_ANDROID)
12     set(PAL_UNIX_NAME \"ANDROID\")
13 elseif (CLR_CMAKE_TARGET_ARCH_WASM)
14     set(PAL_UNIX_NAME \"WEBASSEMBLY\")
15 elseif (CLR_CMAKE_TARGET_LINUX)
16     set(PAL_UNIX_NAME \"LINUX\")
17 elseif (CLR_CMAKE_TARGET_OSX)
18     set(PAL_UNIX_NAME \"OSX\")
19
20     # Xcode's clang does not include /usr/local/include by default, but brew's does.
21     # This ensures an even playing field.
22     include_directories(SYSTEM /usr/local/include)
23 elseif (CLR_CMAKE_TARGET_IOS)
24     set(PAL_UNIX_NAME \"IOS\")
25 elseif (CLR_CMAKE_TARGET_TVOS)
26     set(PAL_UNIX_NAME \"TVOS\")
27 elseif (CLR_CMAKE_TARGET_FREEBSD)
28     set(PAL_UNIX_NAME \"FREEBSD\")
29     include_directories(SYSTEM ${CROSS_ROOTFS}/usr/local/include)
30     set(CMAKE_REQUIRED_INCLUDES ${CROSS_ROOTFS}/usr/local/include)
31 elseif (CLR_CMAKE_TARGET_NETBSD)
32     set(PAL_UNIX_NAME \"NETBSD\")
33 elseif (CLR_CMAKE_TARGET_SUNOS)
34     set(PAL_UNIX_NAME \"SUNOS\")
35     set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} /opt/local/include)
36     set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /opt/local/lib)
37     include_directories(SYSTEM /opt/local/include)
38 else ()
39     message(FATAL_ERROR "Unknown platform.  Cannot define PAL_UNIX_NAME, used by RuntimeInformation.")
40 endif ()
41
42 # We compile with -Werror, so we need to make sure these code fragments compile without warnings.
43 # Older CMake versions (3.8) do not assign the result of their tests, causing unused-value errors
44 # which are not distinguished from the test failing. So no error for that one.
45 # For clang-5.0 avoid errors like "unused variable 'err' [-Werror,-Wunused-variable]".
46 set(CMAKE_REQUIRED_FLAGS "-Werror -Wno-error=unused-value -Wno-error=unused-variable")
47
48 # Apple platforms like macOS/iOS allow targeting older operating system versions with a single SDK,
49 # the mere presence of a symbol in the SDK doesn't tell us whether the deployment target really supports it.
50 # The compiler raises a warning when using an unsupported API, turn that into an error so check_symbol_exists()
51 # can correctly identify whether the API is supported on the target.
52 check_c_compiler_flag("-Wunguarded-availability" "C_SUPPORTS_WUNGUARDED_AVAILABILITY")
53 if(C_SUPPORTS_WUNGUARDED_AVAILABILITY)
54   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Wunguarded-availability")
55 endif()
56
57 # in_pktinfo: Find whether this struct exists
58 check_include_files(
59     "sys/socket.h;linux/in.h"
60     HAVE_LINUX_IN_H)
61
62 if (HAVE_LINUX_IN_H)
63     set (SOCKET_INCLUDES linux/in.h)
64 else ()
65     set (SOCKET_INCLUDES netinet/in.h)
66 endif ()
67
68 check_c_source_compiles(
69     "
70     #include <sys/socket.h>
71     #include <${SOCKET_INCLUDES}>
72     int main(void)
73     {
74         struct in_pktinfo pktinfo;
75         return 0;
76     }
77     "
78     HAVE_IN_PKTINFO)
79
80 check_c_source_compiles(
81     "
82     #include <sys/socket.h>
83     #include <${SOCKET_INCLUDES}>
84     int main(void)
85     {
86         struct ip_mreqn mreqn;
87         return 0;
88     }
89     "
90     HAVE_IP_MREQN)
91
92 # /in_pktinfo
93
94 check_c_source_compiles(
95     "
96     #include <fcntl.h>
97     int main(void)
98     {
99         struct flock64 l;
100         return 0;
101     }
102     "
103     HAVE_FLOCK64)
104
105 check_symbol_exists(
106     O_CLOEXEC
107     fcntl.h
108     HAVE_O_CLOEXEC)
109
110 check_symbol_exists(
111     F_DUPFD_CLOEXEC
112     fcntl.h
113     HAVE_F_DUPFD_CLOEXEC)
114
115 check_symbol_exists(
116     getifaddrs
117     ifaddrs.h
118     HAVE_GETIFADDRS)
119
120 check_symbol_exists(
121     fork
122     unistd.h
123     HAVE_FORK)
124
125 check_symbol_exists(
126     lseek64
127     unistd.h
128     HAVE_LSEEK64)
129
130 check_symbol_exists(
131     mmap64
132     sys/mman.h
133     HAVE_MMAP64)
134
135 check_symbol_exists(
136     ftruncate64
137     unistd.h
138     HAVE_FTRUNCATE64)
139
140 check_symbol_exists(
141     posix_fadvise64
142     fcntl.h
143     HAVE_POSIX_FADVISE64)
144
145 check_symbol_exists(
146     stat64
147     sys/stat.h
148     HAVE_STAT64)
149
150 check_symbol_exists(
151     vfork
152     unistd.h
153     HAVE_VFORK)
154
155 check_symbol_exists(
156     pipe2
157     unistd.h
158     HAVE_PIPE2)
159
160 check_symbol_exists(
161     getmntinfo
162     sys/mount.h
163     HAVE_MNTINFO)
164
165 check_symbol_exists(
166     strcpy_s
167     string.h
168     HAVE_STRCPY_S)
169
170 check_symbol_exists(
171     strlcpy
172     string.h
173     HAVE_STRLCPY)
174
175 check_symbol_exists(
176     posix_fadvise
177     fcntl.h
178     HAVE_POSIX_ADVISE)
179
180 check_symbol_exists(
181     ioctl
182     sys/ioctl.h
183     HAVE_IOCTL)
184
185 check_symbol_exists(
186     sched_getaffinity
187     "sched.h"
188     HAVE_SCHED_GETAFFINITY)
189
190 check_symbol_exists(
191     sched_setaffinity
192     "sched.h"
193     HAVE_SCHED_SETAFFINITY)
194
195 check_symbol_exists(
196     pthread_setcancelstate
197     "pthread.h"
198     HAVE_PTHREAD_SETCANCELSTATE)
199
200 check_symbol_exists(
201     arc4random_buf
202     "stdlib.h"
203     HAVE_ARC4RANDOM_BUF)
204
205 check_symbol_exists(
206     TIOCGWINSZ
207     "sys/ioctl.h"
208     HAVE_TIOCGWINSZ)
209
210 check_symbol_exists(
211     tcgetattr
212     termios.h
213     HAVE_TCGETATTR)
214
215 check_symbol_exists(
216     tcsetattr
217     termios.h
218     HAVE_TCSETATTR)
219
220 check_symbol_exists(
221     ECHO
222     "termios.h"
223     HAVE_ECHO)
224
225 check_symbol_exists(
226     ICANON
227     "termios.h"
228     HAVE_ICANON)
229
230 check_symbol_exists(
231     TCSANOW
232     "termios.h"
233     HAVE_TCSANOW)
234
235 check_struct_has_member(
236     "struct utsname"
237     domainname
238     "sys/utsname.h"
239     HAVE_UTSNAME_DOMAINNAME)
240
241 check_struct_has_member(
242     "struct stat"
243     st_birthtimespec
244     "sys/types.h;sys/stat.h"
245     HAVE_STAT_BIRTHTIME)
246
247 check_struct_has_member(
248     "struct stat"
249     st_flags
250     "sys/types.h;sys/stat.h"
251     HAVE_STAT_FLAGS)
252
253 check_symbol_exists(
254     lchflags
255     "sys/types.h;sys/stat.h"
256     HAVE_LCHFLAGS)
257
258 check_struct_has_member(
259     "struct stat"
260     st_atimespec
261     "sys/types.h;sys/stat.h"
262     HAVE_STAT_TIMESPEC)
263
264 check_struct_has_member(
265     "struct stat"
266     st_atim
267     "sys/types.h;sys/stat.h"
268     HAVE_STAT_TIM)
269
270 check_struct_has_member(
271     "struct stat"
272     st_atimensec
273     "sys/types.h;sys/stat.h"
274     HAVE_STAT_NSEC)
275
276 check_struct_has_member(
277     "struct dirent"
278     d_namlen
279     "dirent.h"
280     HAVE_DIRENT_NAME_LEN)
281
282 check_struct_has_member(
283     "struct statfs"
284     f_fstypename
285     "sys/mount.h"
286     HAVE_STATFS_FSTYPENAME)
287
288 check_struct_has_member(
289     "struct statvfs"
290     f_fstypename
291     "sys/mount.h"
292     HAVE_STATVFS_FSTYPENAME)
293
294 # statfs: Find whether this struct exists
295 if (HAVE_STATFS_FSTYPENAME OR HAVE_STATVFS_FSTYPENAME)
296     set (STATFS_INCLUDES sys/mount.h)
297 else ()
298     set (STATFS_INCLUDES sys/statfs.h)
299 endif ()
300
301 set(CMAKE_EXTRA_INCLUDE_FILES ${STATFS_INCLUDES})
302
303 check_symbol_exists(
304     "statfs"
305     ${STATFS_INCLUDES}
306     HAVE_STATFS
307 )
308
309 check_type_size(
310     "struct statfs"
311     STATFS_SIZE
312     BUILTIN_TYPES_ONLY)
313 set(CMAKE_EXTRA_INCLUDE_FILES) # reset CMAKE_EXTRA_INCLUDE_FILES
314 # /statfs
315
316 check_c_source_compiles(
317     "
318     #include <string.h>
319     int main(void)
320     {
321         char buffer[1];
322         char c = *strerror_r(0, buffer, 0);
323         return 0;
324     }
325     "
326     HAVE_GNU_STRERROR_R)
327
328 check_c_source_compiles(
329     "
330     #include <dirent.h>
331     #include <stddef.h>
332     int main(void)
333     {
334         DIR* dir = NULL;
335         struct dirent* entry = NULL;
336         struct dirent* result;
337         readdir_r(dir, entry, &result);
338         return 0;
339     }
340     "
341     HAVE_READDIR_R)
342
343 check_c_source_compiles(
344     "
345     #include <sys/types.h>
346     #include <sys/event.h>
347     int main(void)
348     {
349         struct kevent event;
350         void* data;
351         EV_SET(&event, 0, EVFILT_READ, 0, 0, 0, data);
352         return 0;
353     }
354     "
355     KEVENT_HAS_VOID_UDATA)
356
357 check_struct_has_member(
358     "struct fd_set"
359     fds_bits
360     "sys/select.h"
361     HAVE_FDS_BITS)
362
363 check_struct_has_member(
364     "struct fd_set"
365     __fds_bits
366     "sys/select.h"
367     HAVE_PRIVATE_FDS_BITS)
368
369 check_c_source_compiles(
370     "
371     #include <sys/sendfile.h>
372     int main(void) { int i = sendfile(0, 0, 0, 0); return 0; }
373     "
374     HAVE_SENDFILE_4)
375
376 check_c_source_compiles(
377     "
378     #include <stdlib.h>
379     #include <sys/types.h>
380     #include <sys/socket.h>
381     #include <sys/uio.h>
382     int main(void) { int i = sendfile(0, 0, 0, NULL, NULL, 0); return 0; }
383     "
384     HAVE_SENDFILE_6)
385
386 check_c_source_compiles(
387     "
388     #include <stdlib.h>
389     #include <sys/types.h>
390     #include <sys/socket.h>
391     #include <sys/uio.h>
392     int main(void) { int i = sendfile(0, 0, 0, 0, NULL, NULL, 0); return 0; }
393     "
394     HAVE_SENDFILE_7)
395
396 check_symbol_exists(
397     clonefile
398     "sys/clonefile.h"
399     HAVE_CLONEFILE)
400
401 check_include_files(
402      "sys/sockio.h"
403      HAVE_SYS_SOCKIO_H)
404
405 check_include_files(
406      "linux/ethtool.h"
407      HAVE_ETHTOOL_H)
408
409 check_include_files(
410      "sys/poll.h"
411      HAVE_SYS_POLL_H)
412
413 check_symbol_exists(
414     epoll_create1
415     sys/epoll.h
416     HAVE_EPOLL)
417
418 check_symbol_exists(
419     accept4
420     sys/socket.h
421     HAVE_ACCEPT4)
422
423 check_symbol_exists(
424     kqueue
425     "sys/types.h;sys/event.h"
426     HAVE_KQUEUE)
427
428 check_symbol_exists(
429     disconnectx
430     "sys/socket.h"
431     HAVE_DISCONNECTX)
432
433 set(PREVIOUS_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
434 set(CMAKE_REQUIRED_FLAGS "-Werror -Wsign-conversion")
435 check_c_source_compiles(
436      "
437      #include <stddef.h>
438      #include <sys/types.h>
439      #include <netdb.h>
440
441      int main(void)
442      {
443         const struct sockaddr *addr;
444         socklen_t addrlen = 0;
445         char *host = NULL;
446         socklen_t hostlen = 0;
447         char *serv = NULL;
448         socklen_t servlen = 0;
449         int flags = 0;
450         int result = getnameinfo(addr, addrlen, host, hostlen, serv, servlen, flags);
451         return 0;
452      }
453      "
454      HAVE_GETNAMEINFO_SIGNED_FLAGS)
455 set(CMAKE_REQUIRED_FLAGS ${PREVIOUS_CMAKE_REQUIRED_FLAGS})
456
457 set(HAVE_SUPPORT_FOR_DUAL_MODE_IPV4_PACKET_INFO 0)
458
459 if (CLR_CMAKE_TARGET_LINUX)
460     if (NOT CLR_CMAKE_TARGET_ANDROID)
461         set(CMAKE_REQUIRED_LIBRARIES rt)
462     endif ()
463
464     set(HAVE_SUPPORT_FOR_DUAL_MODE_IPV4_PACKET_INFO 1)
465 endif ()
466
467 if(CLR_CMAKE_TARGET_IOS)
468     # Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking
469     unset(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP)
470     unset(HAVE_CLOCK_MONOTONIC) # only exists on iOS 10+
471     unset(HAVE_CLOCK_REALTIME)  # only exists on iOS 10+
472     unset(HAVE_FORK) # exists but blocked by kernel
473 elseif(CLR_CMAKE_TARGET_TVOS)
474     # Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking
475     unset(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP)
476     unset(HAVE_CLOCK_MONOTONIC) # only exists on iOS 10+
477     unset(HAVE_CLOCK_REALTIME)  # only exists on iOS 10+
478     unset(HAVE_FORK) # exists but blocked by kernel
479 elseif(CLR_CMAKE_TARGET_ANDROID)
480     # Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking
481     unset(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP)
482     set(HAVE_CLOCK_MONOTONIC 1)
483     set(HAVE_CLOCK_REALTIME 1)
484 else()
485     check_c_source_runs(
486         "
487         #include <sys/mman.h>
488         #include <fcntl.h>
489         #include <unistd.h>
490
491         int main(void)
492         {
493             int fd = shm_open(\"/corefx_configure_shm_open\", O_CREAT | O_RDWR, 0777);
494             if (fd == -1)
495                 return -1;
496
497             shm_unlink(\"/corefx_configure_shm_open\");
498
499             // NOTE: PROT_EXEC and MAP_PRIVATE don't work well with shm_open
500             //       on at least the current version of Mac OS X
501
502             if (mmap(NULL, 1, PROT_EXEC, MAP_PRIVATE, fd, 0) == MAP_FAILED)
503                 return -1;
504
505             return 0;
506         }
507         "
508         HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP)
509
510     check_c_source_runs(
511         "
512         #include <stdlib.h>
513         #include <time.h>
514         #include <sys/time.h>
515         int main(void)
516         {
517             int ret;
518             struct timespec ts;
519             ret = clock_gettime(CLOCK_MONOTONIC, &ts);
520             exit(ret);
521             return 0;
522         }
523         "
524         HAVE_CLOCK_MONOTONIC)
525
526     check_c_source_runs(
527         "
528         #include <stdlib.h>
529         #include <time.h>
530         #include <sys/time.h>
531         int main(void)
532         {
533             int ret;
534             struct timespec ts;
535             ret = clock_gettime(CLOCK_REALTIME, &ts);
536             exit(ret);
537             return 0;
538         }
539         "
540         HAVE_CLOCK_REALTIME)
541 endif()
542
543 check_symbol_exists(
544     mach_absolute_time
545     mach/mach_time.h
546     HAVE_MACH_ABSOLUTE_TIME)
547
548 check_symbol_exists(
549     futimes
550     sys/time.h
551     HAVE_FUTIMES)
552
553 check_symbol_exists(
554     futimens
555     sys/stat.h
556     HAVE_FUTIMENS)
557
558 check_symbol_exists(
559     utimensat
560     sys/stat.h
561     HAVE_UTIMENSAT)
562
563 set (PREVIOUS_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
564 set (CMAKE_REQUIRED_FLAGS "-Werror -Wsign-conversion")
565
566 check_c_source_compiles(
567     "
568     #include <stddef.h>
569     #include <sys/socket.h>
570
571     int main(void)
572     {
573         int fd = -1;
574         struct sockaddr* addr = NULL;
575         socklen_t addrLen = 0;
576
577         int err = bind(fd, addr, addrLen);
578         return 0;
579     }
580     "
581     BIND_ADDRLEN_UNSIGNED
582 )
583
584 check_c_source_compiles(
585     "
586     #include <netinet/in.h>
587     #include <netinet/tcp.h>
588
589     int main(void)
590     {
591         struct ipv6_mreq opt;
592         unsigned int index = 0;
593         opt.ipv6mr_interface = index;
594         return 0;
595     }
596     "
597     IPV6MR_INTERFACE_UNSIGNED
598 )
599
600 check_include_files(
601     "sys/inotify.h"
602     HAVE_SYS_INOTIFY_H)
603
604 check_c_source_compiles(
605     "
606     #include <sys/inotify.h>
607
608     int main(void)
609     {
610         intptr_t fd;
611         uint32_t wd;
612         return inotify_rm_watch(fd, wd);
613     }
614     "
615     INOTIFY_RM_WATCH_WD_UNSIGNED)
616
617 set (CMAKE_REQUIRED_FLAGS ${PREVIOUS_CMAKE_REQUIRED_FLAGS})
618
619 check_prototype_definition(
620     getpriority
621     "int getpriority(int which, int who)"
622     0
623     "sys/resource.h"
624     PRIORITY_REQUIRES_INT_WHO)
625
626 check_prototype_definition(
627     kevent
628     "int kevent(int kg, const struct kevent* chagelist, int nchanges, struct kevent* eventlist, int nevents, const struct timespec* timeout)"
629     0
630     "sys/types.h;sys/event.h"
631     KEVENT_REQUIRES_INT_PARAMS)
632
633 check_c_source_compiles(
634     "
635     #include <stdlib.h>
636     #include <unistd.h>
637     #include <string.h>
638
639     int main(void)
640     {
641         return mkstemps(\"abc\", 3);
642     }
643     "
644     HAVE_MKSTEMPS)
645
646 check_c_source_compiles(
647     "
648     #include <stdlib.h>
649     #include <unistd.h>
650     #include <string.h>
651
652     int main(void)
653     {
654         return mkstemp(\"abc\");
655     }
656     "
657     HAVE_MKSTEMP)
658
659 if (NOT HAVE_MKSTEMPS AND NOT HAVE_MKSTEMP)
660     message(FATAL_ERROR "Cannot find mkstemp nor mkstemp on this platform.")
661 endif()
662
663 check_c_source_compiles(
664     "
665     #include <sys/types.h>
666     #include <sys/socketvar.h>
667     #include <sys/queue.h>
668     #include <netinet/in.h>
669     #include <netinet/ip.h>
670     #include <netinet/tcp.h>
671     #include <netinet/tcp_var.h>
672     int main(void) { return 0; }
673     "
674     HAVE_NETINET_TCP_VAR_H
675 )
676
677 check_c_source_compiles(
678     "
679     #include <sys/types.h>
680     #include <sys/socketvar.h>
681     #include <sys/queue.h>
682     #include <netinet/in.h>
683     #include <netinet/ip.h>
684     #include <netinet/ip_var.h>
685     #include <netinet/udp.h>
686     #include <netinet/udp_var.h>
687     int main(void) { return 0; }
688     "
689     HAVE_NETINET_UDP_VAR_H
690 )
691
692 check_c_source_compiles(
693     "
694     #include <sys/types.h>
695     #include <sys/socketvar.h>
696     #include <sys/queue.h>
697     #include <netinet/in.h>
698     #include <netinet/ip.h>
699     #include <netinet/ip_var.h>
700     int main(void) { return 0; }
701     "
702     HAVE_NETINET_IP_VAR_H
703 )
704
705 check_c_source_compiles(
706     "
707     #include <sys/types.h>
708     #include <sys/socketvar.h>
709     #include <sys/queue.h>
710     #include <netinet/in.h>
711     #include <netinet/ip.h>
712     #include <netinet/ip_icmp.h>
713     #include <netinet/icmp_var.h>
714     int main(void) { return 0; }
715     "
716     HAVE_NETINET_ICMP_VAR_H
717 )
718
719 check_include_files(
720     sys/cdefs.h
721     HAVE_SYS_CDEFS_H)
722
723 if (HAVE_SYS_CDEFS_H)
724     set(CMAKE_REQUIRED_DEFINITIONS "-DHAVE_SYS_CDEFS_H")
725 endif()
726
727 # If sys/cdefs is not included on Android, this check will fail because
728 # __BEGIN_DECLS is not defined
729 check_c_source_compiles(
730     "
731 #ifdef HAVE_SYS_CDEFS_H
732     #include <sys/cdefs.h>
733 #endif
734     #include <netinet/tcp.h>
735     int main(void) { int x = TCP_ESTABLISHED; return x; }
736     "
737     HAVE_TCP_H_TCPSTATE_ENUM
738 )
739
740 set(CMAKE_REQUIRED_DEFINITIONS)
741
742 check_symbol_exists(
743     TCPS_ESTABLISHED
744     "netinet/tcp_fsm.h"
745     HAVE_TCP_FSM_H
746 )
747
748 if(CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS)
749     set(HAVE_IOS_NET_ROUTE_H 1)
750     set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h "${CMAKE_CURRENT_SOURCE_DIR}/System.Native/ios/net/route.h")
751 else()
752     set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h net/if.h net/route.h)
753 endif()
754
755 check_type_size(
756     "struct rt_msghdr"
757      HAVE_RT_MSGHDR
758      BUILTIN_TYPES_ONLY)
759 check_type_size(
760     "struct rt_msghdr2"
761      HAVE_RT_MSGHDR2
762      BUILTIN_TYPES_ONLY)
763 set(CMAKE_EXTRA_INCLUDE_FILES) # reset CMAKE_EXTRA_INCLUDE_FILES
764
765 set(CMAKE_EXTRA_INCLUDE_FILES net/if.h)
766 check_type_size(
767     "struct if_msghdr2"
768      HAVE_IF_MSGHDR2
769      BUILTIN_TYPES_ONLY)
770 set(CMAKE_EXTRA_INCLUDE_FILES) # reset CMAKE_EXTRA_INCLUDE_FILES
771
772 check_include_files(
773     "sys/types.h;sys/sysctl.h"
774     HAVE_SYS_SYSCTL_H)
775
776 check_include_files(
777     "stdint.h;net/if_media.h"
778     HAVE_NET_IFMEDIA_H)
779
780 check_include_files(
781     linux/rtnetlink.h
782     HAVE_LINUX_RTNETLINK_H)
783
784 check_include_files(
785     linux/can.h
786     HAVE_LINUX_CAN_H)
787
788 check_symbol_exists(
789     getpeereid
790     unistd.h
791     HAVE_GETPEEREID)
792
793 check_symbol_exists(
794     getdomainname
795     unistd.h
796     HAVE_GETDOMAINNAME)
797
798 check_symbol_exists(
799     uname
800     sys/utsname.h
801     HAVE_UNAME)
802
803 # getdomainname on OSX takes an 'int' instead of a 'size_t'
804 # check if compiling with 'size_t' would cause a warning
805 set (PREVIOUS_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
806 set (CMAKE_REQUIRED_FLAGS "-Werror -Weverything")
807 check_c_source_compiles(
808     "
809     #include <unistd.h>
810     int main(void)
811     {
812         size_t namelen = 20;
813         char name[20];
814         int dummy = getdomainname(name, namelen);
815         (void)dummy;
816         return 0;
817     }
818     "
819     HAVE_GETDOMAINNAME_SIZET
820 )
821 set (CMAKE_REQUIRED_FLAGS ${PREVIOUS_CMAKE_REQUIRED_FLAGS})
822
823 set (PREVIOUS_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
824 if (HAVE_SYS_INOTIFY_H AND CLR_CMAKE_TARGET_FREEBSD)
825     set (CMAKE_REQUIRED_LIBRARIES "-linotify -L/usr/local/lib")
826 endif()
827
828 check_symbol_exists(
829     inotify_init
830     sys/inotify.h
831     HAVE_INOTIFY_INIT)
832
833 check_symbol_exists(
834     inotify_add_watch
835     sys/inotify.h
836     HAVE_INOTIFY_ADD_WATCH)
837
838 check_symbol_exists(
839     inotify_rm_watch
840     sys/inotify.h
841     HAVE_INOTIFY_RM_WATCH)
842 set (CMAKE_REQUIRED_LIBRARIES ${PREVIOUS_CMAKE_REQUIRED_LIBRARIES})
843
844 set (HAVE_INOTIFY 0)
845 if (HAVE_INOTIFY_INIT AND HAVE_INOTIFY_ADD_WATCH AND HAVE_INOTIFY_RM_WATCH)
846     set (HAVE_INOTIFY 1)
847 elseif (CLR_CMAKE_TARGET_LINUX AND NOT CLR_CMAKE_TARGET_ARCH_WASM)
848     message(FATAL_ERROR "Cannot find inotify functions on a Linux platform.")
849 endif()
850
851 option(HeimdalGssApi "use heimdal implementation of GssApi" OFF)
852
853 if (HeimdalGssApi)
854    check_include_files(
855        gssapi/gssapi.h
856        HAVE_HEIMDAL_HEADERS)
857 endif()
858
859 check_include_files(
860     GSS/GSS.h
861     HAVE_GSSFW_HEADERS)
862
863 if (HAVE_GSSFW_HEADERS)
864     check_symbol_exists(
865         GSS_SPNEGO_MECHANISM
866         "GSS/GSS.h"
867         HAVE_GSS_SPNEGO_MECHANISM)
868 else ()
869     check_symbol_exists(
870         GSS_SPNEGO_MECHANISM
871         "gssapi/gssapi.h"
872         HAVE_GSS_SPNEGO_MECHANISM)
873 endif ()
874
875 if (HAVE_GSSFW_HEADERS)
876     check_symbol_exists(
877         GSS_KRB5_CRED_NO_CI_FLAGS_X
878         "GSS/GSS.h"
879         HAVE_GSS_KRB5_CRED_NO_CI_FLAGS_X)
880 else ()
881     check_symbol_exists(
882         GSS_KRB5_CRED_NO_CI_FLAGS_X
883         "gssapi/gssapi_krb5.h"
884         HAVE_GSS_KRB5_CRED_NO_CI_FLAGS_X)
885 endif ()
886
887 check_include_files(crt_externs.h HAVE_CRT_EXTERNS_H)
888
889 if (HAVE_CRT_EXTERNS_H)
890     check_c_source_compiles(
891     "
892     #include <crt_externs.h>
893     int main(void) { char** e = *(_NSGetEnviron()); return 0; }
894     "
895     HAVE_NSGETENVIRON)
896 endif()
897
898 set (CMAKE_REQUIRED_LIBRARIES)
899
900 check_c_source_compiles(
901     "
902     #include <sys/inotify.h>
903     int main(void)
904     {
905         uint32_t mask = IN_EXCL_UNLINK;
906         return 0;
907     }
908     "
909     HAVE_IN_EXCL_UNLINK)
910
911 check_c_source_compiles(
912     "
913     #include <netinet/tcp.h>
914     int main(void)
915     {
916         int x = TCP_KEEPALIVE;
917         return x;
918     }
919     "
920     HAVE_TCP_H_TCP_KEEPALIVE)
921
922 check_c_source_compiles(
923     "
924     #include <unistd.h>
925     int main(void)
926     {
927         size_t result;
928         (void)__builtin_mul_overflow(0, 0, &result);
929     }
930     "
931     HAVE_BUILTIN_MUL_OVERFLOW)
932
933 configure_file(
934     ${CMAKE_CURRENT_SOURCE_DIR}/Common/pal_config.h.in
935     ${CMAKE_CURRENT_BINARY_DIR}/Common/pal_config.h)