msvc: tidy up _CRT_*_NO_DEPRECATE definitions

Dedupe and migrate MSVC-specific warning suppressions to `curl_setup.h`.
Make cmake set `_CRT_SECURE_NO_DEPRECATE` for examples and standalone
tests, and stop setting `_CRT_NONSTDC_NO_DEPRECATE` for them.

Details:
- drop version guards. On ancient MSVC version these macro are a no-op.
- move to `curl_setup.h` from `config-win32*.h`.
- sync macro values with CMake.
- cmake: stop setting them globally in favour of `curl_setup.h`.
- cmake: re-add these macros to `docs/examples` and `tests/http/clients`,
  which do not use `curl_setup.h`.
- cmake: drop `_CRT_NONSTDC_NO_DEPRECATE` for examples and tests.
  They build fine without.
- update comments.

Closes #15960
This commit is contained in:
Viktor Szakats 2025-01-09 18:19:35 +01:00
parent c8d800a2f0
commit de3e662ce1
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
6 changed files with 10 additions and 19 deletions

View file

@ -293,12 +293,6 @@
#define HAVE_LONGLONG 1
#endif
/* Define to avoid VS2005 complaining about portable C functions. */
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
#define _CRT_SECURE_NO_DEPRECATE 1
#define _CRT_NONSTDC_NO_DEPRECATE 1
#endif
/* mingw-w64 and visual studio >= 2005 (MSVCR80)
all default to 64-bit time_t unless _USE_32BIT_TIME_T is defined */
#if (defined(_MSC_VER) && (_MSC_VER >= 1400)) || defined(__MINGW32__)

View file

@ -218,12 +218,6 @@
/* Undef keyword 'const' if it does not work. */
/* #undef const */
/* Define to avoid VS2005 complaining about portable C functions. */
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
#define _CRT_SECURE_NO_DEPRECATE 1
#define _CRT_NONSTDC_NO_DEPRECATE 1
#endif
/* VS2005 and later default size for time_t is 64-bit, unless */
/* _USE_32BIT_TIME_T has been defined to get a 32-bit time_t. */
#if defined(_MSC_VER) && (_MSC_VER >= 1400)

View file

@ -85,13 +85,17 @@
#endif
#endif
/*
* Disable Visual Studio warnings:
* 4127 "conditional expression is constant"
*/
#ifdef _MSC_VER
/* Disable Visual Studio warnings: 4127 "conditional expression is constant" */
#pragma warning(disable:4127)
/* Avoid VS2005 and upper complaining about portable C functions. */
#ifndef _CRT_NONSTDC_NO_DEPRECATE
#define _CRT_NONSTDC_NO_DEPRECATE /* for strdup(), write(), etc. */
#endif
#ifndef _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_DEPRECATE /* for fopen(), getenv(), etc. */
#endif
#endif /* _MSC_VER */
#ifdef _WIN32
/*