From 372f03ba20a62eab9f2c35e076732ec7bffcce98 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Thu, 20 Jan 2022 11:04:40 -0600 Subject: [PATCH] Fix sys/sysctl.h depreciation error under glibc 2.30+ glibc 2.30 and up emit an ugly depreciation warning on `#include ` - this patch makes the build system fail the include test for `sys/sysctl.h` by forcibly setting `-Werror` before the call to `check_include_files` (which internally uses `try_compile`) to get `HAVE_SYS_SYSCTL` to not be defined (even if it's there) if it would cause such a depreciation message to be emitted. Ideally, we would not have to manually massage `CMAKE_C_FLAGS` before calling `check_include_files` and could just tweak that to either always or conditionally try compilation with `-Werror`, but try_compile doesn't actually use any overridden `CMAKE_C_FLAGS` values [0] (dating back to 2006). [0]: https://cmake.org/pipermail/cmake/2006-October/011649.html --- cmake/ConfigureChecks.cmake | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake index 9c75ae668..2e2d5e567 100644 --- a/cmake/ConfigureChecks.cmake +++ b/cmake/ConfigureChecks.cmake @@ -115,7 +115,14 @@ check_struct_has_member("struct stat" st_mtim.tv_nsec "sys/stat.h" HAVE_STRUCT_S LANGUAGE CXX) check_include_file_cxx(sys/ioctl.h HAVE_SYS_IOCTL_H) check_include_file_cxx(sys/select.h HAVE_SYS_SELECT_H) + +# glibc 2.30 deprecated because that's what glibc does. +# Checking for that here rather than hardcoding a check on the glibc +# version in the C++ sources at point of use makes more sense. +SET(OLD_CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") check_include_files("sys/types.h;sys/sysctl.h" HAVE_SYS_SYSCTL_H) +SET(CMAKE_C_FLAGS "${OLD_CMAKE_C_FLAGS}") check_cxx_symbol_exists(eventfd sys/eventfd.h HAVE_EVENTFD) check_cxx_symbol_exists(pipe2 unistd.h HAVE_PIPE2)