From 95769eb87ba2247dc4739d7e36d730c9a251ac62 Mon Sep 17 00:00:00 2001
From: Romain Vimont <rom@rom1v.com>
Date: Sat, 20 Nov 2021 21:24:56 +0100
Subject: [PATCH] Configure feature test macros in meson

Refs #2807 <https://github.com/Genymobile/scrcpy/pull/2807>

Co-authored-by: RipleyTom <RipleyTom@users.noreply.github.com>
---
 app/meson.build           | 8 ++++++++
 app/src/compat.h          | 7 -------
 app/src/sys/win/process.c | 3 ---
 3 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/app/meson.build b/app/meson.build
index 4894babc9f..9dfe6f5478 100644
--- a/app/meson.build
+++ b/app/meson.build
@@ -44,11 +44,19 @@ if host_machine.system() == 'windows'
         'src/sys/win/file.c',
         'src/sys/win/process.c',
     ]
+    add_project_arguments('-D_WIN32_WINNT=0x0600', language: 'c')
+    add_project_arguments('-DWINVER=0x0600', language: 'c')
 else
     src += [
         'src/sys/unix/file.c',
         'src/sys/unix/process.c',
     ]
+    add_project_arguments('-D_POSIX_C_SOURCE=200809L', language: 'c')
+    add_project_arguments('-D_XOPEN_SOURCE=700', language: 'c')
+    add_project_arguments('-D_GNU_SOURCE', language: 'c')
+    if host_machine.system() == 'darwin'
+        add_project_arguments('-D_DARWIN_C_SOURCE', language: 'c')
+    endif
 endif
 
 v4l2_support = host_machine.system() == 'linux'
diff --git a/app/src/compat.h b/app/src/compat.h
index 9f66ce95c7..44300c36e0 100644
--- a/app/src/compat.h
+++ b/app/src/compat.h
@@ -1,13 +1,6 @@
 #ifndef COMPAT_H
 #define COMPAT_H
 
-#define _POSIX_C_SOURCE 200809L
-#define _XOPEN_SOURCE 700
-#define _GNU_SOURCE
-#ifdef __APPLE__
-# define _DARWIN_C_SOURCE
-#endif
-
 #include <libavformat/version.h>
 #include <SDL2/SDL_version.h>
 
diff --git a/app/src/sys/win/process.c b/app/src/sys/win/process.c
index 6566b80e94..326a3d99a7 100644
--- a/app/src/sys/win/process.c
+++ b/app/src/sys/win/process.c
@@ -1,6 +1,3 @@
-// <https://devblogs.microsoft.com/oldnewthing/20111216-00/?p=8873>
-#define _WIN32_WINNT 0x0600 // For extended process API
-
 #include "util/process.h"
 
 #include <processthreadsapi.h>