From 021f6556944546534979d734ec19a5597a456399 Mon Sep 17 00:00:00 2001 From: Luca Bacci Date: Fri, 27 Mar 2026 10:22:12 +0100 Subject: [PATCH 1/5] MSVC: Add necessary includes Fixes the following warnings: ../cairo/test/cairo-test.c(317): warning C4013: '_access' undefined; assuming extern returning int ../cairo/test/pdf-tagged-text.c(553): warning C4013: 'open' undefined; assuming extern returning int ../cairo/test/pdf-tagged-text.c(562): warning C4013: 'close' undefined; assuming extern returning int ../cairo/test/any2ppm.c(118): warning C4013: 'write' undefined; assuming extern returning int ../cairo/test/any2ppm.c(887): warning C4013: '_setmode' undefined; assuming extern returning int https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4013 --- test/any2ppm.c | 4 ++++ test/cairo-test.c | 1 + test/pdf-tagged-text.c | 7 +++++++ 3 files changed, 12 insertions(+) diff --git a/test/any2ppm.c b/test/any2ppm.c index f601ec835..c0efdede1 100644 --- a/test/any2ppm.c +++ b/test/any2ppm.c @@ -87,6 +87,10 @@ #include #endif +#ifdef _WIN32 +#include +#endif + #if HAVE_UNISTD_H && HAVE_SIGNAL_H && HAVE_SYS_STAT_H && HAVE_SYS_SOCKET_H && (HAVE_POLL_H || HAVE_SYS_POLL_H) && HAVE_SYS_UN_H #include #include diff --git a/test/cairo-test.c b/test/cairo-test.c index 49dfadb15..347ade7a8 100644 --- a/test/cairo-test.c +++ b/test/cairo-test.c @@ -67,6 +67,7 @@ #ifdef _MSC_VER #include #include +#include #define F_OK 0 #define HAVE_MKDIR 1 #define mkdir _mkdir diff --git a/test/pdf-tagged-text.c b/test/pdf-tagged-text.c index 094b1c8b0..5e58d2b71 100644 --- a/test/pdf-tagged-text.c +++ b/test/pdf-tagged-text.c @@ -41,6 +41,13 @@ #include #endif +#ifdef _WIN32 +#include +#include +#include +#include +#endif + #include #if CAIRO_HAS_PDF_SURFACE From ad631c609a9b09fb7184483c7b3b5f1ac0100001 Mon Sep 17 00:00:00 2001 From: Luca Bacci Date: Fri, 27 Mar 2026 10:44:25 +0100 Subject: [PATCH 2/5] MSVC: Turn warning C4013 into an error This is the analogous of -Werror=implicit-function-declaration. Even though implicit function declaration was removed in C99, most compilers continue supporting it as an extension. Turn it into an error (as we do for GCC / CLang). https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4013 --- meson.build | 2 ++ 1 file changed, 2 insertions(+) diff --git a/meson.build b/meson.build index 11525ea84..2fb22007b 100644 --- a/meson.build +++ b/meson.build @@ -97,6 +97,8 @@ if cc.get_id() == 'msvc' '/wd4305', # Don't warn about _cairo_status -> _cairo_int_status conversion '/wd5286', + # Turn " undefined, assuming extern returning int" to an error + '/we4013', language : ['c', 'cpp']) add_project_arguments('-D_CRT_SECURE_NO_WARNINGS', language : ['c', 'cpp']) endif From 1ec2a448e9966d99c5f969c926d6e09da4058a1f Mon Sep 17 00:00:00 2001 From: Luca Bacci Date: Fri, 27 Mar 2026 10:27:22 +0100 Subject: [PATCH 3/5] MSVC: Define _CRT_NONSTDC_NO_WARNINGS We follow the convention that POSIX functions which aren't part of C don't have an underscore. --- meson.build | 4 +++- src/cairo-compiler-private.h | 9 --------- test/cairo-test.c | 1 - test/cairo-test.h | 5 ----- util/cairo-script/cairo-script-operators.c | 1 - 5 files changed, 3 insertions(+), 17 deletions(-) diff --git a/meson.build b/meson.build index 2fb22007b..0251a88ed 100644 --- a/meson.build +++ b/meson.build @@ -100,7 +100,9 @@ if cc.get_id() == 'msvc' # Turn " undefined, assuming extern returning int" to an error '/we4013', language : ['c', 'cpp']) - add_project_arguments('-D_CRT_SECURE_NO_WARNINGS', language : ['c', 'cpp']) + add_project_arguments(['-D_CRT_SECURE_NO_WARNINGS', + '-D_CRT_NONSTDC_NO_WARNINGS', + ], language : ['c', 'cpp']) endif add_project_arguments('-D_GNU_SOURCE', language: ['c', 'cpp']) diff --git a/src/cairo-compiler-private.h b/src/cairo-compiler-private.h index 1aaced394..90fd28019 100644 --- a/src/cairo-compiler-private.h +++ b/src/cairo-compiler-private.h @@ -154,20 +154,11 @@ #endif #if (defined(__WIN32__) && !defined(__WINE__)) || defined(_MSC_VER) -#define access _access #ifndef R_OK #define R_OK 4 #endif -#define fdopen _fdopen -#define hypot _hypot #define pclose _pclose #define popen _popen -#define strdup _strdup -#define unlink _unlink -#if defined (_MSC_VER) && _MSC_VER < 1900 - #define vsnprintf _vsnprintf - #define snprintf _snprintf -#endif #endif #if defined(_MSC_VER) && defined(_M_IX86) diff --git a/test/cairo-test.c b/test/cairo-test.c index 347ade7a8..f6e25647c 100644 --- a/test/cairo-test.c +++ b/test/cairo-test.c @@ -70,7 +70,6 @@ #include #define F_OK 0 #define HAVE_MKDIR 1 -#define mkdir _mkdir #endif #ifndef FALSE diff --git a/test/cairo-test.h b/test/cairo-test.h index b70654654..4a853c0d1 100644 --- a/test/cairo-test.h +++ b/test/cairo-test.h @@ -56,12 +56,7 @@ typedef unsigned __int64 uint64_t; #ifdef _MSC_VER #define _USE_MATH_DEFINES - #include -#if _MSC_VER <= 1600 -#define isnan(x) _isnan(x) -#endif - #endif #if HAVE_FENV_H diff --git a/util/cairo-script/cairo-script-operators.c b/util/cairo-script/cairo-script-operators.c index a5eca6ffc..27116ca6d 100644 --- a/util/cairo-script/cairo-script-operators.c +++ b/util/cairo-script/cairo-script-operators.c @@ -48,7 +48,6 @@ #ifdef _MSC_VER #define _USE_MATH_DEFINES /* for M_LN2, M_PI and M_SQRT2 on win32 */ -#define snprintf _snprintf #endif #include From c988a8e36ef102a53489bdc897800f2a48e4c2df Mon Sep 17 00:00:00 2001 From: Luca Bacci Date: Fri, 27 Mar 2026 10:34:33 +0100 Subject: [PATCH 4/5] MSVC: Define _USE_MATH_DEFINES via meson.build This way M_PI and other constants are available everywhere. The constants are behind a preprocessor macro because they aren't part of standard C. --- meson.build | 1 + perf/micro/pythagoras-tree.c | 2 +- src/cairoint.h | 3 --- test/cairo-test.h | 1 - util/cairo-script/cairo-script-operators.c | 4 ---- 5 files changed, 2 insertions(+), 9 deletions(-) diff --git a/meson.build b/meson.build index 0251a88ed..98e007bca 100644 --- a/meson.build +++ b/meson.build @@ -102,6 +102,7 @@ if cc.get_id() == 'msvc' language : ['c', 'cpp']) add_project_arguments(['-D_CRT_SECURE_NO_WARNINGS', '-D_CRT_NONSTDC_NO_WARNINGS', + '-D_USE_MATH_DEFINES', ], language : ['c', 'cpp']) endif diff --git a/perf/micro/pythagoras-tree.c b/perf/micro/pythagoras-tree.c index 9d3ca1155..6581e4ed6 100644 --- a/perf/micro/pythagoras-tree.c +++ b/perf/micro/pythagoras-tree.c @@ -24,7 +24,7 @@ */ #include "cairo-perf.h" -#define _USE_MATH_DEFINES /* for M_SQRT2 on win32 */ + #include static void diff --git a/src/cairoint.h b/src/cairoint.h index b18a579be..fa8f5d395 100644 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -55,9 +55,6 @@ #include #include -#ifdef _MSC_VER -#define _USE_MATH_DEFINES -#endif #include #include #include diff --git a/test/cairo-test.h b/test/cairo-test.h index 4a853c0d1..0a36cd7a3 100644 --- a/test/cairo-test.h +++ b/test/cairo-test.h @@ -55,7 +55,6 @@ typedef unsigned __int64 uint64_t; #endif #ifdef _MSC_VER -#define _USE_MATH_DEFINES #include #endif diff --git a/util/cairo-script/cairo-script-operators.c b/util/cairo-script/cairo-script-operators.c index 27116ca6d..301080b31 100644 --- a/util/cairo-script/cairo-script-operators.c +++ b/util/cairo-script/cairo-script-operators.c @@ -46,10 +46,6 @@ #include /* mkstemp */ #include -#ifdef _MSC_VER -#define _USE_MATH_DEFINES /* for M_LN2, M_PI and M_SQRT2 on win32 */ -#endif - #include #include /* INT_MAX */ #include From af2dbc14b78289b4e8cc8dacd8f8cf2a19f22161 Mon Sep 17 00:00:00 2001 From: Luca Bacci Date: Fri, 27 Mar 2026 14:35:28 +0100 Subject: [PATCH 5/5] Meson: Fix warnings on clang-cl Treat CLangCL as MSVC --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 98e007bca..73985d5c6 100644 --- a/meson.build +++ b/meson.build @@ -90,7 +90,7 @@ if cc.get_id() != 'msvc' conf.set('WARN_UNUSED_RESULT', warn_unused_result) endif -if cc.get_id() == 'msvc' +if cc.get_argument_syntax() == 'msvc' # Basic usage in the cairo type system that causes spammy and useless warnings add_project_arguments('/wd4244', '/wd4146', # Don't warn about double -> float truncation