From 95eb086b5002eb916cbb87ba100802987e2f2c16 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexander=20K=C3=B6plinger?= Date: Wed, 6 Nov 2019 16:09:40 +0100 Subject: [PATCH] System.Native: Make configure.cmake checks work for iOS (dotnet/corefx#42408) Apple platforms like macOS/iOS allow targeting older operating system versions with a single SDK, the mere presence of a symbol in the SDK doesn't tell us whether the deployment target really supports it. The compiler raises a warning when using an unsupported API, turn that into an error so `check_symbol_exists()` can correctly identify whether the API is supported on the target. This fixes compile errors after https://github.com/dotnet/corefx/pull/37583 was merged since `clonefile()` is iOS10+. Replace usages of `check_function_exists()` since it only tests for existence of functions and the CMake docs recommend using `check_symbol_exists()`: https://cmake.org/cmake/help/v3.15/module/CheckFunctionExists.html Commit migrated from https://github.com/dotnet/corefx/commit/879127eb87346200b4ddf40a7fce96e79ec211fe --- src/libraries/Native/Unix/configure.cmake | 67 ++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 20 deletions(-) diff --git a/src/libraries/Native/Unix/configure.cmake b/src/libraries/Native/Unix/configure.cmake index 6c4e7c2..9109927 100644 --- a/src/libraries/Native/Unix/configure.cmake +++ b/src/libraries/Native/Unix/configure.cmake @@ -1,6 +1,6 @@ +include(CheckCCompilerFlag) include(CheckCSourceCompiles) include(CheckCSourceRuns) -include(CheckFunctionExists) include(CheckIncludeFiles) include(CheckPrototypeDefinition) include(CheckStructHasMember) @@ -32,6 +32,15 @@ endif () # which are not distinguished from the test failing. So no error for that one. set(CMAKE_REQUIRED_FLAGS "-Werror -Wno-error=unused-value") +# Apple platforms like macOS/iOS allow targeting older operating system versions with a single SDK, +# the mere presence of a symbol in the SDK doesn't tell us whether the deployment target really supports it. +# The compiler raises a warning when using an unsupported API, turn that into an error so check_symbol_exists() +# can correctly identify whether the API is supported on the target. +check_c_compiler_flag("-Wunguarded-availability" "C_SUPPORTS_WUNGUARDED_AVAILABILITY") +if(C_SUPPORTS_WUNGUARDED_AVAILABILITY) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Wunguarded-availability") +endif() + # in_pktinfo: Find whether this struct exists check_include_files( "sys/socket.h;linux/in.h" @@ -90,8 +99,9 @@ check_symbol_exists( fcntl.h HAVE_F_DUPFD_CLOEXEC) -check_function_exists( +check_symbol_exists( getifaddrs + ifaddrs.h HAVE_GETIFADDRS) check_symbol_exists( @@ -139,16 +149,19 @@ check_symbol_exists( string.h HAVE_STRCPY_S) -check_function_exists( +check_symbol_exists( strlcpy + string.h HAVE_STRLCPY) -check_function_exists( +check_symbol_exists( posix_fadvise + fcntl.h HAVE_POSIX_ADVISE) -check_function_exists( +check_symbol_exists( ioctl + sys/ioctl.h HAVE_IOCTL) check_symbol_exists( @@ -171,12 +184,14 @@ check_symbol_exists( "sys/ioctl.h" HAVE_TIOCGWINSZ) -check_function_exists( +check_symbol_exists( tcgetattr + termios.h HAVE_TCGETATTR) -check_function_exists( +check_symbol_exists( tcsetattr + termios.h HAVE_TCSETATTR) check_symbol_exists( @@ -264,7 +279,7 @@ set(CMAKE_EXTRA_INCLUDE_FILES ${STATFS_INCLUDES}) check_symbol_exists( "statfs" - STATFS_INCLUDES + ${STATFS_INCLUDES} HAVE_STATFS ) @@ -344,7 +359,8 @@ check_c_source_compiles( " HAVE_SENDFILE_6) -check_include_files( +check_symbol_exists( + clonefile "sys/clonefile.h" HAVE_CLONEFILE) @@ -360,12 +376,14 @@ check_include_files( "sys/poll.h" HAVE_SYS_POLL_H) -check_function_exists( +check_symbol_exists( epoll_create1 + sys/epoll.h HAVE_EPOLL) -check_function_exists( +check_symbol_exists( accept4 + sys/socket.h HAVE_ACCEPT4) check_symbol_exists( @@ -378,6 +396,7 @@ check_symbol_exists( "sys/socket.h" HAVE_DISCONNECTX) +set(PREVIOUS_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) set(CMAKE_REQUIRED_FLAGS "-Werror -Wsign-conversion") check_c_source_compiles( " @@ -398,7 +417,7 @@ check_c_source_compiles( } " HAVE_GETNAMEINFO_SIGNED_FLAGS) -set(CMAKE_REQUIRED_FLAGS -Werror) +set(CMAKE_REQUIRED_FLAGS ${PREVIOUS_CMAKE_REQUIRED_FLAGS}) set(HAVE_SUPPORT_FOR_DUAL_MODE_IPV4_PACKET_INFO 0) @@ -448,16 +467,19 @@ check_symbol_exists( mach/mach_time.h HAVE_MACH_ABSOLUTE_TIME) -check_function_exists( +check_symbol_exists( futimes + sys/time.h HAVE_FUTIMES) -check_function_exists( +check_symbol_exists( futimens + sys/stat.h HAVE_FUTIMENS) -check_function_exists( +check_symbol_exists( utimensat + sys/stat.h HAVE_UTIMENSAT) set (PREVIOUS_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) @@ -663,12 +685,14 @@ check_symbol_exists( unistd.h HAVE_GETPEEREID) -check_function_exists( +check_symbol_exists( getdomainname + unistd.h HAVE_GETDOMAINNAME) -check_function_exists( +check_symbol_exists( uname + sys/utsname.h HAVE_UNAME) # getdomainname on OSX takes an 'int' instead of a 'size_t' @@ -689,16 +713,19 @@ if (HAVE_SYS_INOTIFY_H AND CMAKE_SYSTEM_NAME STREQUAL FreeBSD) set (CMAKE_REQUIRED_LIBRARIES "-linotify -L/usr/local/lib") endif() -check_function_exists( +check_symbol_exists( inotify_init + sys/inotify.h HAVE_INOTIFY_INIT) -check_function_exists( +check_symbol_exists( inotify_add_watch + sys/inotify.h HAVE_INOTIFY_ADD_WATCH) -check_function_exists( +check_symbol_exists( inotify_rm_watch + sys/inotify.h HAVE_INOTIFY_RM_WATCH) set (CMAKE_REQUIRED_LIBRARIES ${PREVIOUS_CMAKE_REQUIRED_LIBRARIES}) -- 2.7.4