1 include(CheckCCompilerFlag)
2 include(CheckCSourceCompiles)
3 include(CheckCSourceRuns)
4 include(CheckIncludeFiles)
5 include(CheckPrototypeDefinition)
6 include(CheckStructHasMember)
7 include(CheckSymbolExists)
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\")
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)
39 message(FATAL_ERROR "Unknown platform. Cannot define PAL_UNIX_NAME, used by RuntimeInformation.")
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")
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")
57 # in_pktinfo: Find whether this struct exists
59 "sys/socket.h;linux/in.h"
63 set (SOCKET_INCLUDES linux/in.h)
65 set (SOCKET_INCLUDES netinet/in.h)
68 check_c_source_compiles(
70 #include <sys/socket.h>
71 #include <${SOCKET_INCLUDES}>
74 struct in_pktinfo pktinfo;
80 check_c_source_compiles(
82 #include <sys/socket.h>
83 #include <${SOCKET_INCLUDES}>
86 struct ip_mreqn mreqn;
94 check_c_source_compiles(
113 HAVE_F_DUPFD_CLOEXEC)
143 HAVE_POSIX_FADVISE64)
188 HAVE_SCHED_GETAFFINITY)
193 HAVE_SCHED_SETAFFINITY)
196 pthread_setcancelstate
198 HAVE_PTHREAD_SETCANCELSTATE)
235 check_struct_has_member(
239 HAVE_UTSNAME_DOMAINNAME)
241 check_struct_has_member(
244 "sys/types.h;sys/stat.h"
247 check_struct_has_member(
250 "sys/types.h;sys/stat.h"
255 "sys/types.h;sys/stat.h"
258 check_struct_has_member(
261 "sys/types.h;sys/stat.h"
264 check_struct_has_member(
267 "sys/types.h;sys/stat.h"
270 check_struct_has_member(
273 "sys/types.h;sys/stat.h"
276 check_struct_has_member(
280 HAVE_DIRENT_NAME_LEN)
282 check_struct_has_member(
286 HAVE_STATFS_FSTYPENAME)
288 check_struct_has_member(
292 HAVE_STATVFS_FSTYPENAME)
294 # statfs: Find whether this struct exists
295 if (HAVE_STATFS_FSTYPENAME OR HAVE_STATVFS_FSTYPENAME)
296 set (STATFS_INCLUDES sys/mount.h)
298 set (STATFS_INCLUDES sys/statfs.h)
301 set(CMAKE_EXTRA_INCLUDE_FILES ${STATFS_INCLUDES})
313 set(CMAKE_EXTRA_INCLUDE_FILES) # reset CMAKE_EXTRA_INCLUDE_FILES
316 check_c_source_compiles(
322 char c = *strerror_r(0, buffer, 0);
328 check_c_source_compiles(
335 struct dirent* entry = NULL;
336 struct dirent* result;
337 readdir_r(dir, entry, &result);
343 check_c_source_compiles(
345 #include <sys/types.h>
346 #include <sys/event.h>
351 EV_SET(&event, 0, EVFILT_READ, 0, 0, 0, data);
355 KEVENT_HAS_VOID_UDATA)
357 check_struct_has_member(
363 check_struct_has_member(
367 HAVE_PRIVATE_FDS_BITS)
369 check_c_source_compiles(
371 #include <sys/sendfile.h>
372 int main(void) { int i = sendfile(0, 0, 0, 0); return 0; }
376 check_c_source_compiles(
379 #include <sys/types.h>
380 #include <sys/socket.h>
382 int main(void) { int i = sendfile(0, 0, 0, NULL, NULL, 0); return 0; }
386 check_c_source_compiles(
389 #include <sys/types.h>
390 #include <sys/socket.h>
392 int main(void) { int i = sendfile(0, 0, 0, 0, NULL, NULL, 0); return 0; }
425 "sys/types.h;sys/event.h"
433 set(PREVIOUS_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
434 set(CMAKE_REQUIRED_FLAGS "-Werror -Wsign-conversion")
435 check_c_source_compiles(
438 #include <sys/types.h>
443 const struct sockaddr *addr;
444 socklen_t addrlen = 0;
446 socklen_t hostlen = 0;
448 socklen_t servlen = 0;
450 int result = getnameinfo(addr, addrlen, host, hostlen, serv, servlen, flags);
454 HAVE_GETNAMEINFO_SIGNED_FLAGS)
455 set(CMAKE_REQUIRED_FLAGS ${PREVIOUS_CMAKE_REQUIRED_FLAGS})
457 set(HAVE_SUPPORT_FOR_DUAL_MODE_IPV4_PACKET_INFO 0)
459 if (CLR_CMAKE_TARGET_LINUX)
460 if (NOT CLR_CMAKE_TARGET_ANDROID)
461 set(CMAKE_REQUIRED_LIBRARIES rt)
464 set(HAVE_SUPPORT_FOR_DUAL_MODE_IPV4_PACKET_INFO 1)
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)
487 #include <sys/mman.h>
493 int fd = shm_open(\"/corefx_configure_shm_open\", O_CREAT | O_RDWR, 0777);
497 shm_unlink(\"/corefx_configure_shm_open\");
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
502 if (mmap(NULL, 1, PROT_EXEC, MAP_PRIVATE, fd, 0) == MAP_FAILED)
508 HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP)
514 #include <sys/time.h>
519 ret = clock_gettime(CLOCK_MONOTONIC, &ts);
524 HAVE_CLOCK_MONOTONIC)
530 #include <sys/time.h>
535 ret = clock_gettime(CLOCK_REALTIME, &ts);
546 HAVE_MACH_ABSOLUTE_TIME)
563 set (PREVIOUS_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
564 set (CMAKE_REQUIRED_FLAGS "-Werror -Wsign-conversion")
566 check_c_source_compiles(
569 #include <sys/socket.h>
574 struct sockaddr* addr = NULL;
575 socklen_t addrLen = 0;
577 int err = bind(fd, addr, addrLen);
581 BIND_ADDRLEN_UNSIGNED
584 check_c_source_compiles(
586 #include <netinet/in.h>
587 #include <netinet/tcp.h>
591 struct ipv6_mreq opt;
592 unsigned int index = 0;
593 opt.ipv6mr_interface = index;
597 IPV6MR_INTERFACE_UNSIGNED
604 check_c_source_compiles(
606 #include <sys/inotify.h>
612 return inotify_rm_watch(fd, wd);
615 INOTIFY_RM_WATCH_WD_UNSIGNED)
617 set (CMAKE_REQUIRED_FLAGS ${PREVIOUS_CMAKE_REQUIRED_FLAGS})
619 check_prototype_definition(
621 "int getpriority(int which, int who)"
624 PRIORITY_REQUIRES_INT_WHO)
626 check_prototype_definition(
628 "int kevent(int kg, const struct kevent* chagelist, int nchanges, struct kevent* eventlist, int nevents, const struct timespec* timeout)"
630 "sys/types.h;sys/event.h"
631 KEVENT_REQUIRES_INT_PARAMS)
633 check_c_source_compiles(
641 return mkstemps(\"abc\", 3);
646 check_c_source_compiles(
654 return mkstemp(\"abc\");
659 if (NOT HAVE_MKSTEMPS AND NOT HAVE_MKSTEMP)
660 message(FATAL_ERROR "Cannot find mkstemp nor mkstemp on this platform.")
663 check_c_source_compiles(
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; }
674 HAVE_NETINET_TCP_VAR_H
677 check_c_source_compiles(
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; }
689 HAVE_NETINET_UDP_VAR_H
692 check_c_source_compiles(
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; }
702 HAVE_NETINET_IP_VAR_H
705 check_c_source_compiles(
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; }
716 HAVE_NETINET_ICMP_VAR_H
723 if (HAVE_SYS_CDEFS_H)
724 set(CMAKE_REQUIRED_DEFINITIONS "-DHAVE_SYS_CDEFS_H")
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(
731 #ifdef HAVE_SYS_CDEFS_H
732 #include <sys/cdefs.h>
734 #include <netinet/tcp.h>
735 int main(void) { int x = TCP_ESTABLISHED; return x; }
737 HAVE_TCP_H_TCPSTATE_ENUM
740 set(CMAKE_REQUIRED_DEFINITIONS)
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")
752 set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h net/if.h net/route.h)
763 set(CMAKE_EXTRA_INCLUDE_FILES) # reset CMAKE_EXTRA_INCLUDE_FILES
765 set(CMAKE_EXTRA_INCLUDE_FILES net/if.h)
770 set(CMAKE_EXTRA_INCLUDE_FILES) # reset CMAKE_EXTRA_INCLUDE_FILES
773 "sys/types.h;sys/sysctl.h"
777 "stdint.h;net/if_media.h"
782 HAVE_LINUX_RTNETLINK_H)
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(
814 int dummy = getdomainname(name, namelen);
819 HAVE_GETDOMAINNAME_SIZET
821 set (CMAKE_REQUIRED_FLAGS ${PREVIOUS_CMAKE_REQUIRED_FLAGS})
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")
836 HAVE_INOTIFY_ADD_WATCH)
841 HAVE_INOTIFY_RM_WATCH)
842 set (CMAKE_REQUIRED_LIBRARIES ${PREVIOUS_CMAKE_REQUIRED_LIBRARIES})
845 if (HAVE_INOTIFY_INIT AND HAVE_INOTIFY_ADD_WATCH AND HAVE_INOTIFY_RM_WATCH)
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.")
851 option(HeimdalGssApi "use heimdal implementation of GssApi" OFF)
856 HAVE_HEIMDAL_HEADERS)
863 if (HAVE_GSSFW_HEADERS)
867 HAVE_GSS_SPNEGO_MECHANISM)
872 HAVE_GSS_SPNEGO_MECHANISM)
875 if (HAVE_GSSFW_HEADERS)
877 GSS_KRB5_CRED_NO_CI_FLAGS_X
879 HAVE_GSS_KRB5_CRED_NO_CI_FLAGS_X)
882 GSS_KRB5_CRED_NO_CI_FLAGS_X
883 "gssapi/gssapi_krb5.h"
884 HAVE_GSS_KRB5_CRED_NO_CI_FLAGS_X)
887 check_include_files(crt_externs.h HAVE_CRT_EXTERNS_H)
889 if (HAVE_CRT_EXTERNS_H)
890 check_c_source_compiles(
892 #include <crt_externs.h>
893 int main(void) { char** e = *(_NSGetEnviron()); return 0; }
898 set (CMAKE_REQUIRED_LIBRARIES)
900 check_c_source_compiles(
902 #include <sys/inotify.h>
905 uint32_t mask = IN_EXCL_UNLINK;
911 check_c_source_compiles(
913 #include <netinet/tcp.h>
916 int x = TCP_KEEPALIVE;
920 HAVE_TCP_H_TCP_KEEPALIVE)
922 check_c_source_compiles(
928 (void)__builtin_mul_overflow(0, 0, &result);
931 HAVE_BUILTIN_MUL_OVERFLOW)
934 ${CMAKE_CURRENT_SOURCE_DIR}/Common/pal_config.h.in
935 ${CMAKE_CURRENT_BINARY_DIR}/Common/pal_config.h)