]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
msvc: tidy up `_CRT_*_NO_DEPRECATE` definitions
authorViktor Szakats <commit@vsz.me>
Thu, 9 Jan 2025 17:19:35 +0000 (18:19 +0100)
committerViktor Szakats <commit@vsz.me>
Sat, 11 Jan 2025 23:34:21 +0000 (00:34 +0100)
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

CMakeLists.txt
docs/examples/CMakeLists.txt
lib/config-win32.h
lib/config-win32ce.h
lib/curl_setup.h
tests/http/clients/CMakeLists.txt

index 4f1404ea60ac5c536fdd7c9deba939882d19b8ed..bd11cd61de308e88162cdf91414d485bdb1d46b6 100644 (file)
@@ -1892,7 +1892,6 @@ if(MSVC)
   # Disable default manifest added by CMake
   set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
 
-  add_definitions("-D_CRT_SECURE_NO_DEPRECATE" "-D_CRT_NONSTDC_NO_DEPRECATE")
   if(CMAKE_C_FLAGS MATCHES "/W[0-4]")
     string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
   else()
index 83948d8e795f06f7acb010ce3bd43bf3d0ab373f..ff7cf9b6cf0af2d4c249aa8fe79f00cde4e9aa5b 100644 (file)
@@ -33,7 +33,7 @@ foreach(_target IN LISTS check_PROGRAMS)
   add_executable(${_target_name} EXCLUDE_FROM_ALL "${_target}.c")
   add_dependencies(curl-examples ${_target_name})
   target_link_libraries(${_target_name} ${LIB_SELECTED} ${CURL_LIBS})
-  target_compile_definitions(${_target_name} PRIVATE "CURL_NO_OLDIES")
+  target_compile_definitions(${_target_name} PRIVATE "CURL_NO_OLDIES" "$<$<BOOL:MSVC>:_CRT_SECURE_NO_DEPRECATE>")
   if(LIB_SELECTED STREQUAL LIB_STATIC AND WIN32)
     set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_STATICLIB")
   endif()
index 3237c715be294a1868378d756468ac794ce65ff3..028acf4482ca0ae1e434141de86aa96748d3d9ce 100644 (file)
 #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__)
index c50f12691b331627b127d05f88b44b8d79cb7104..99c8f2d7d5ae8f514a82de5e820eb2f9f9d33289 100644 (file)
 /* 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)
index 05ccb21e55d80f378d9f7ec9ab27cb24b8dd0703..c3805ce8271804225a552fe5da58b41eed187c4d 100644 (file)
 #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
 /*
index c7ea188926c8f8f1f811a8951385ebe70af597ac..f8a6a5face4bf8352585445453eeff2b06120bac 100644 (file)
@@ -38,7 +38,7 @@ foreach(_target IN LISTS check_PROGRAMS)
     "${PROJECT_SOURCE_DIR}/lib"  # for "curl_setup.h"
   )
   target_link_libraries(${_target_name} ${LIB_SELECTED} ${CURL_LIBS})
-  target_compile_definitions(${_target_name} PRIVATE "CURL_NO_OLDIES")
+  target_compile_definitions(${_target_name} PRIVATE "CURL_NO_OLDIES" "$<$<BOOL:MSVC>:_CRT_SECURE_NO_DEPRECATE>")
   if(LIB_SELECTED STREQUAL LIB_STATIC AND WIN32)
     set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_STATICLIB")
   endif()