From 92b18462550fa3c4add2679470d0d015cdfa205a Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 18 Mar 2025 22:23:14 +0100 Subject: [PATCH 1/2] Define _POSIX_C_SOURCE globally Other Sway projects have switched to this approach. --- log.c | 1 - loop.c | 1 - main.c | 1 - meson.build | 2 ++ password-buffer.c | 1 - pool-buffer.c | 1 - shadow.c | 1 + 7 files changed, 3 insertions(+), 5 deletions(-) diff --git a/log.c b/log.c index cb4603966..dcb50909f 100644 --- a/log.c +++ b/log.c @@ -1,4 +1,3 @@ -#define _POSIX_C_SOURCE 199506L #include #include #include diff --git a/loop.c b/loop.c index 8cbfaa6fc..7081b131a 100644 --- a/loop.c +++ b/loop.c @@ -1,4 +1,3 @@ -#define _POSIX_C_SOURCE 200809L #include #include #include diff --git a/main.c b/main.c index 3a3a68f5e..479481737 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,3 @@ -#define _POSIX_C_SOURCE 200809L #include #include #include diff --git a/meson.build b/meson.build index f69ebfb8d..a530a2db6 100644 --- a/meson.build +++ b/meson.build @@ -11,6 +11,8 @@ project( ], ) +add_project_arguments('-D_POSIX_C_SOURCE=200809L', language: 'c') + add_project_arguments( [ '-Wno-unused-parameter', diff --git a/password-buffer.c b/password-buffer.c index 7b1e46582..1af992aea 100644 --- a/password-buffer.c +++ b/password-buffer.c @@ -1,4 +1,3 @@ -#define _POSIX_C_SOURCE 200809L #include "password-buffer.h" #include "log.h" #include "swaylock.h" diff --git a/pool-buffer.c b/pool-buffer.c index dfb4d0d4b..96271e11c 100644 --- a/pool-buffer.c +++ b/pool-buffer.c @@ -1,4 +1,3 @@ -#define _POSIX_C_SOURCE 200809L #include #include #include diff --git a/shadow.c b/shadow.c index 3399d040d..83b0cc09e 100644 --- a/shadow.c +++ b/shadow.c @@ -1,3 +1,4 @@ +#undef _POSIX_C_SOURCE #define _XOPEN_SOURCE // for crypt #include #include From 0534a2cf6cdb74459d8ccf19a469ae002281d1fa Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 18 Mar 2025 22:24:13 +0100 Subject: [PATCH 2/2] build: use cc.get_supported_arguments() for warnings Let's not require the C compiler to support specific warnings, especially if half the flags are used to turn off the warnings anyways. --- meson.build | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/meson.build b/meson.build index a530a2db6..cdbe6ff85 100644 --- a/meson.build +++ b/meson.build @@ -11,22 +11,18 @@ project( ], ) -add_project_arguments('-D_POSIX_C_SOURCE=200809L', language: 'c') +cc = meson.get_compiler('c') -add_project_arguments( - [ - '-Wno-unused-parameter', - '-Wno-unused-result', - '-Wundef', - '-Wvla', - ], - language: 'c', -) +add_project_arguments('-D_POSIX_C_SOURCE=200809L', language: 'c') -cc = meson.get_compiler('c') +add_project_arguments(cc.get_supported_arguments([ + '-Wno-unused-parameter', + '-Wno-unused-result', + '-Wundef', + '-Wvla', +]), language: 'c') is_freebsd = host_machine.system().startswith('freebsd') - if is_freebsd add_project_arguments('-D_C11_SOURCE', language: 'c') endif