Blob Blame History Raw
Define _GNU_SOURCE for a declaration of vasprintf. This is necessary
to build with compilers which do not support implicit function
declarations (a language feature that was removed from C99).

Defining _GNU_SOURCE during the build exposes that the imported
util-linux sources are not built with some HAVE_* macros defined,
for things that the glibc headers provide with _GNU_SOURCE.  These
HAVE_* macros need to be defined as well.

Submitted upstream:

  <https://github.com/linuxdeepin/deepin-system-monitor/pull/237>

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a68288eb92241dff..6fcfa4501aa26434 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -44,6 +44,25 @@ else()
     SET(IS_LOONGARCH_TYPE 0)
 endif()
 
+# For vasprintf in deepin-system-monitor-main/3rdparty/include/xalloc.h.
+# Also needed by the tests subdirectory.
+add_definitions("-D_GNU_SOURCE")
+
+# HAVE_CLOSE_RANGE is used by
+# deepin-system-monitor-main/3rdparty/include/fileutils.h to define
+# close_range if needed.
+try_compile(CLOSE_RANGE_RESULT "${CMAKE_CURRENT_BINARY_DIR}/try_compile"
+  "${PROJECT_SOURCE_DIR}/cmake/check-close_range.c")
+if(CLOSE_RANGE_RESULT)
+  add_definitions("-DHAVE_CLOSE_RANGE")
+endif()
+
+# Likewise, HAVE_DECL_CPU_ALLOC is used in
+# deepin-system-monitor-main/3rdparty/include/cpuset.h.  Support for
+# the <sched.h> macros was added in glibc 2.7, so define it
+# unconditionally.
+add_definitions("-DHAVE_DECL_CPU_ALLOC")
+
 #系统监视器主应用
 ADD_SUBDIRECTORY(deepin-system-monitor-main)
 #系统监视器插件
diff --git a/cmake/check-close_range.c b/cmake/check-close_range.c
new file mode 100644
index 0000000000000000..2dd24d44d40cfd99
--- /dev/null
+++ b/cmake/check-close_range.c
@@ -0,0 +1,14 @@
+/* Check whether <unistd.h> declares close_range, for HAVE_CLOSE_RANGE. */
+
+/* Supplied by the build environment later. */
+#define _GNU_SOURCE
+
+#include <unistd.h>
+
+void *volatile p;
+
+int
+main(void)
+{
+  p = (void *) close_range;
+}