Skip to content

Commit 6aaee16

Browse files
authored
Skip sys/sysctl.h on linux in mono (#61110)
Fixes three warnings: ```sh [ 56%] Building C object mono/mini/CMakeFiles/monosgen-objects.dir/__/utils/mono-mmap.c.o In file included from /runtime/src/mono/mono/utils/mono-mmap.c:23: /usr/include/x86_64-linux-gnu/sys/sysctl.h:21:2: warning: #warning "The <sys/sysctl.h> header is deprecated and will be removed." [-Wcpp] 21 | #warning "The <sys/sysctl.h> header is deprecated and will be removed." | ^~~~~~~ # snip [ 59%] Building C object mono/mini/CMakeFiles/monosgen-objects.dir/__/utils/mono-time.c.o In file included from /runtime/src/mono/mono/utils/mono-proclib.c:42: /usr/include/x86_64-linux-gnu/sys/sysctl.h:21:2: warning: #warning "The <sys/sysctl.h> header is deprecated and will be removed." [-Wcpp] 21 | #warning "The <sys/sysctl.h> header is deprecated and will be removed." | ^~~~~~~ [ 59%] Building C object mono/mini/CMakeFiles/monosgen-objects.dir/__/utils/mono-uri.c.o [ 59%] Building C object mono/mini/CMakeFiles/monosgen-objects.dir/__/utils/mono-poll.c.o In file included from /runtime/src/mono/mono/utils/mono-time.c:107: /usr/include/x86_64-linux-gnu/sys/sysctl.h:21:2: warning: #warning "The <sys/sysctl.h> header is deprecated and will be removed." [-Wcpp] 21 | #warning "The <sys/sysctl.h> header is deprecated and will be removed." | ^~~~~~~ ``` With this PR: 0 warnings - http://sprunge.us/96kyq9 Like in src/libraries/Native, skip linux from sys/sysctl.h check. For other systems, `check_include_files` (instead of `check_include_file` (singular)) when a header depends on another one. Also, simplified few conditions: "is linux" check supersedes "is android".
1 parent 3950381 commit 6aaee16

File tree

2 files changed

+21
-25
lines changed

2 files changed

+21
-25
lines changed

src/libraries/Native/Unix/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ if (CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS
106106
add_definitions(-D__APPLE_USE_RFC_3542)
107107
endif ()
108108

109-
if (CLR_CMAKE_TARGET_LINUX OR CLR_CMAKE_TARGET_ANDROID)
109+
if (CLR_CMAKE_TARGET_LINUX)
110110
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE")
111111
endif ()
112112

src/mono/cmake/configure.cmake

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
# Configure checks
33
#
44

5-
include(CheckTypeSize)
6-
include(CheckStructHasMember)
7-
include(CheckSymbolExists)
85
include(CheckCCompilerFlag)
96
include(CheckCSourceCompiles)
7+
include(CheckIncludeFiles)
8+
include(CheckStructHasMember)
9+
include(CheckSymbolExists)
10+
include(CheckTypeSize)
1011

1112
# Apple platforms like macOS/iOS allow targeting older operating system versions with a single SDK,
1213
# the mere presence of a symbol in the SDK doesn't tell us whether the deployment target really supports it.
@@ -64,8 +65,8 @@ function(ac_check_type type suffix includes)
6465
endfunction()
6566

6667
ac_check_headers (
67-
sys/types.h sys/stat.h sys/filio.h sys/sockio.h sys/utime.h sys/un.h sys/syscall.h sys/uio.h sys/param.h sys/sysctl.h
68-
sys/prctl.h sys/socket.h sys/utsname.h sys/select.h sys/user.h sys/poll.h sys/wait.h sts/auxv.h sys/resource.h
68+
sys/types.h sys/stat.h sys/filio.h sys/sockio.h sys/utime.h sys/un.h sys/syscall.h sys/uio.h sys/param.h
69+
sys/prctl.h sys/socket.h sys/utsname.h sys/select.h sys/poll.h sys/wait.h sts/auxv.h sys/resource.h
6970
sys/ioctl.h sys/errno.h sys/sendfile.h sys/statvfs.h sys/statfs.h sys/mman.h sys/mount.h sys/time.h sys/random.h
7071
strings.h stdint.h unistd.h signal.h setjmp.h syslog.h netdb.h utime.h semaphore.h libproc.h alloca.h ucontext.h pwd.h elf.h
7172
gnu/lib-names.h netinet/tcp.h netinet/in.h link.h arpa/inet.h unwind.h poll.h wchar.h linux/magic.h
@@ -84,6 +85,15 @@ ac_check_funcs (
8485
gethrtime read_real_time gethostbyname gethostbyname2 getnameinfo getifaddrs
8586
access inet_ntop Qp2getifaddrs getpid mktemp)
8687

88+
if (HOST_LINUX)
89+
# sysctl is deprecated on Linux
90+
set(HAVE_SYS_SYSCTL_H 0)
91+
else ()
92+
check_include_files("sys/types.h;sys/sysctl.h" HAVE_SYS_SYSCTL_H)
93+
endif()
94+
95+
check_include_files("sys/types.h;sys/user.h" HAVE_SYS_USER_H)
96+
8797
if(NOT HOST_DARWIN)
8898
# getentropy was introduced in macOS 10.12 / iOS 10.0
8999
ac_check_funcs (getentropy)
@@ -125,7 +135,7 @@ check_type_size("long" SIZEOF_LONG)
125135
check_type_size("long long" SIZEOF_LONG_LONG)
126136
check_type_size("size_t" SIZEOF_SIZE_T)
127137

128-
if (HOST_LINUX OR HOST_ANDROID)
138+
if (HOST_LINUX)
129139
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
130140
endif()
131141

@@ -175,9 +185,7 @@ if(HOST_WIN32)
175185
set(HAVE_STRUCT_SOCKADDR_IN6 1)
176186
set(HAVE_STRTOK_R 1)
177187
set(HAVE_EXECVP 0)
178-
endif()
179-
180-
if(HOST_IOS)
188+
elseif(HOST_IOS)
181189
set(HAVE_SYSTEM 0)
182190
set(HAVE_GETPWUID_R 0)
183191
set(HAVE_SYS_USER_H 0)
@@ -193,25 +201,13 @@ if(HOST_IOS)
193201
endif()
194202
elseif(HOST_MACCAT)
195203
set(HAVE_SYSTEM 0)
196-
endif()
197-
198-
if(HOST_BROWSER)
204+
elseif(HOST_BROWSER)
199205
set(HAVE_FORK 0)
200-
endif()
201-
202-
if(HOST_SOLARIS)
206+
elseif(HOST_SOLARIS)
203207
set(HAVE_GETPROTOBYNAME 1)
204208
set(HAVE_NETINET_TCP_H 1)
205209
set(HAVE_GETADDRINFO 1)
206-
endif()
207-
208-
if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
209-
# FreeBSD fails earlier ac_check_headers for these because <sys/types.h> is needed.
210-
set(HAVE_SYS_SYSCTL_H 1)
211-
set(HAVE_SYS_USER_H 1)
212-
endif()
213-
214-
if(CMAKE_SYSTEM_NAME STREQUAL "WASI")
210+
elseif(HOST_WASI)
215211
# Redirected to errno.h
216212
set(SYS_ERRNO_H 0)
217213
# Some headers exist, but don't compile (wasi sdk 12.0)

0 commit comments

Comments
 (0)