diff --git a/cmake/max_warnings.cmake b/cmake/max_warnings.cmake index 182738b7..e14c67a8 100644 --- a/cmake/max_warnings.cmake +++ b/cmake/max_warnings.cmake @@ -28,8 +28,7 @@ if(MSVC) endif() endif() - # Disable broken warnings - add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE) + add_definitions(-D_CRT_SECURE_NO_WARNINGS) elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER_ID MATCHES "Clang") if(NOT CMAKE_CXX_FLAGS MATCHES "-Wall") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 66e5deba..f062634f 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -39,6 +39,11 @@ list(APPEND LIBRARIES ${SOCKET_LIBRARIES}) add_definitions(-DHAVE_CONFIG_H) +if(MSVC) + add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) + add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS) +endif() + set(EXAMPLES direct_tcpip scp diff --git a/example/direct_tcpip.c b/example/direct_tcpip.c index 5cbccf50..f724373c 100644 --- a/example/direct_tcpip.c +++ b/example/direct_tcpip.c @@ -1,9 +1,3 @@ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include diff --git a/example/scp.c b/example/scp.c index f02944f9..ead7a84b 100644 --- a/example/scp.c +++ b/example/scp.c @@ -2,12 +2,6 @@ * Sample showing how to do a simple SCP transfer. */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include diff --git a/example/scp_nonblock.c b/example/scp_nonblock.c index fd8ab99d..d7b97bed 100644 --- a/example/scp_nonblock.c +++ b/example/scp_nonblock.c @@ -7,12 +7,6 @@ * "scp_nonblock 192.168.0.1 user password /tmp/secrets" */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include diff --git a/example/scp_write.c b/example/scp_write.c index 833b6018..0962a89d 100644 --- a/example/scp_write.c +++ b/example/scp_write.c @@ -2,12 +2,6 @@ * Sample showing how to do an SCP upload. */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include diff --git a/example/scp_write_nonblock.c b/example/scp_write_nonblock.c index 0e6a1beb..f9f12b1d 100644 --- a/example/scp_write_nonblock.c +++ b/example/scp_write_nonblock.c @@ -2,12 +2,6 @@ * Sample showing how to do an SCP non-blocking upload transfer. */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include diff --git a/example/sftp.c b/example/sftp.c index 96fdea70..78a4e4cb 100644 --- a/example/sftp.c +++ b/example/sftp.c @@ -7,12 +7,6 @@ * "sftp 192.168.0.1 user password /tmp/secrets -p|-i|-k" */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include #include diff --git a/example/sftp_append.c b/example/sftp_append.c index 012af2f2..0278009c 100644 --- a/example/sftp_append.c +++ b/example/sftp_append.c @@ -7,12 +7,6 @@ * sftp_append 192.168.0.1 user password localfile /tmp/remotefile */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include #include diff --git a/example/sftp_mkdir.c b/example/sftp_mkdir.c index 9c9dc526..30231ee9 100644 --- a/example/sftp_mkdir.c +++ b/example/sftp_mkdir.c @@ -7,12 +7,6 @@ * "sftp 192.168.0.1 user password /tmp/sftp_mkdir" */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include #include diff --git a/example/sftp_mkdir_nonblock.c b/example/sftp_mkdir_nonblock.c index a24a1745..be5f7afe 100644 --- a/example/sftp_mkdir_nonblock.c +++ b/example/sftp_mkdir_nonblock.c @@ -7,12 +7,6 @@ * "sftp 192.168.0.1 user password /tmp/sftp_write_nonblock.c" */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include #include diff --git a/example/sftp_nonblock.c b/example/sftp_nonblock.c index 5932ad05..ea16f238 100644 --- a/example/sftp_nonblock.c +++ b/example/sftp_nonblock.c @@ -7,12 +7,6 @@ * "sftp_nonblock 192.168.0.1 user password /tmp/secrets" */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include #include diff --git a/example/sftp_write.c b/example/sftp_write.c index 5c6e5a80..e3725d1b 100644 --- a/example/sftp_write.c +++ b/example/sftp_write.c @@ -7,12 +7,6 @@ * "sftp 192.168.0.1 user password sftp_write.c /tmp/secrets" */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include #include diff --git a/example/sftp_write_nonblock.c b/example/sftp_write_nonblock.c index ef90210e..b907109c 100644 --- a/example/sftp_write_nonblock.c +++ b/example/sftp_write_nonblock.c @@ -7,12 +7,6 @@ * "sftp 192.168.0.1 user password thisfile /tmp/storehere" */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include #include diff --git a/example/sftp_write_sliding.c b/example/sftp_write_sliding.c index 3c3d9113..26223140 100644 --- a/example/sftp_write_sliding.c +++ b/example/sftp_write_sliding.c @@ -7,12 +7,6 @@ * "sftp 192.168.0.1 user password file /tmp/storehere" */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include #include diff --git a/example/sftpdir.c b/example/sftpdir.c index e137a8a6..8d6dad58 100644 --- a/example/sftpdir.c +++ b/example/sftpdir.c @@ -7,12 +7,6 @@ * "sftpdir 192.168.0.1 user password /tmp/secretdir" */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include #include diff --git a/example/sftpdir_nonblock.c b/example/sftpdir_nonblock.c index fb229b99..457ed7e0 100644 --- a/example/sftpdir_nonblock.c +++ b/example/sftpdir_nonblock.c @@ -7,12 +7,6 @@ * "sftpdir 192.168.0.1 user password /tmp/secretdir" */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include #include diff --git a/example/ssh2.c b/example/ssh2.c index 7d87b2b9..afd1d647 100644 --- a/example/ssh2.c +++ b/example/ssh2.c @@ -11,12 +11,6 @@ * command executes on the remote machine */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include #include diff --git a/example/ssh2_agent.c b/example/ssh2_agent.c index 33d41be4..1815c10d 100644 --- a/example/ssh2_agent.c +++ b/example/ssh2_agent.c @@ -6,12 +6,6 @@ * "ssh2_agent host user" */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include #include diff --git a/example/ssh2_agent_forwarding.c b/example/ssh2_agent_forwarding.c index 0d813502..2110d6fa 100644 --- a/example/ssh2_agent_forwarding.c +++ b/example/ssh2_agent_forwarding.c @@ -13,12 +13,6 @@ * */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include diff --git a/example/ssh2_echo.c b/example/ssh2_echo.c index d5fa7635..c08b4bef 100644 --- a/example/ssh2_echo.c +++ b/example/ssh2_echo.c @@ -8,12 +8,6 @@ * */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include diff --git a/example/ssh2_exec.c b/example/ssh2_exec.c index ae4d57ef..7d0db115 100644 --- a/example/ssh2_exec.c +++ b/example/ssh2_exec.c @@ -10,12 +10,6 @@ * */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include diff --git a/example/subsystem_netconf.c b/example/subsystem_netconf.c index 79034116..b3198770 100644 --- a/example/subsystem_netconf.c +++ b/example/subsystem_netconf.c @@ -1,9 +1,3 @@ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include diff --git a/example/tcpip-forward.c b/example/tcpip-forward.c index c7affdc6..c90865fd 100644 --- a/example/tcpip-forward.c +++ b/example/tcpip-forward.c @@ -1,9 +1,3 @@ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "libssh2_config.h" #include diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 53f6fa61..91ce4f66 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -39,6 +39,11 @@ list(APPEND LIBRARIES ${SOCKET_LIBRARIES}) add_definitions(-DHAVE_CONFIG_H) +if(MSVC) + add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) + add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS) +endif() + set(TESTS warmup hostkey diff --git a/tests/openssh_fixture.c b/tests/openssh_fixture.c index a34e4b9b..3e453d93 100644 --- a/tests/openssh_fixture.c +++ b/tests/openssh_fixture.c @@ -35,12 +35,6 @@ * OF SUCH DAMAGE. */ -#ifdef WIN32 -#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS -#define _WINSOCK_DEPRECATED_NO_WARNINGS -#endif -#endif - #include "session_fixture.h" #include "openssh_fixture.h" #include "libssh2_config.h" diff --git a/win32/libssh2_config.h b/win32/libssh2_config.h index 371ae634..60c14676 100644 --- a/win32/libssh2_config.h +++ b/win32/libssh2_config.h @@ -5,10 +5,6 @@ #define WIN32 #endif -#ifndef _CRT_SECURE_NO_DEPRECATE -#define _CRT_SECURE_NO_DEPRECATE 1 -#endif - #define HAVE_IOCTLSOCKET #define HAVE_SELECT #define HAVE_SNPRINTF @@ -21,6 +17,9 @@ # define HAVE_LONGLONG # define HAVE_STRTOLL #elif defined(_MSC_VER) +# ifndef _CRT_SECURE_NO_WARNINGS +# define _CRT_SECURE_NO_WARNINGS +# endif # if _MSC_VER >= 1310 # define HAVE_LONGLONG # endif