From: Viktor Szakats Date: Thu, 9 Jan 2025 17:19:35 +0000 (+0100) Subject: msvc: tidy up `_CRT_*_NO_DEPRECATE` definitions X-Git-Tag: curl-8_12_0~150 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=de3e662ce1efca317e9d9d51c4ba35279f10d637;p=thirdparty%2Fcurl.git 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 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f1404ea60..bd11cd61de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/docs/examples/CMakeLists.txt b/docs/examples/CMakeLists.txt index 83948d8e79..ff7cf9b6cf 100644 --- a/docs/examples/CMakeLists.txt +++ b/docs/examples/CMakeLists.txt @@ -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" "$<$:_CRT_SECURE_NO_DEPRECATE>") if(LIB_SELECTED STREQUAL LIB_STATIC AND WIN32) set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_STATICLIB") endif() diff --git a/lib/config-win32.h b/lib/config-win32.h index 3237c715be..028acf4482 100644 --- a/lib/config-win32.h +++ b/lib/config-win32.h @@ -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__) diff --git a/lib/config-win32ce.h b/lib/config-win32ce.h index c50f12691b..99c8f2d7d5 100644 --- a/lib/config-win32ce.h +++ b/lib/config-win32ce.h @@ -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) diff --git a/lib/curl_setup.h b/lib/curl_setup.h index 05ccb21e55..c3805ce827 100644 --- a/lib/curl_setup.h +++ b/lib/curl_setup.h @@ -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 /* diff --git a/tests/http/clients/CMakeLists.txt b/tests/http/clients/CMakeLists.txt index c7ea188926..f8a6a5face 100644 --- a/tests/http/clients/CMakeLists.txt +++ b/tests/http/clients/CMakeLists.txt @@ -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" "$<$:_CRT_SECURE_NO_DEPRECATE>") if(LIB_SELECTED STREQUAL LIB_STATIC AND WIN32) set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_STATICLIB") endif()