mirror of
https://github.com/libssh2/libssh2.git
synced 2025-07-29 13:01:14 +03:00
cmake: fix ENABLE_WERROR=ON
breaking auto-detections
- cmake: fix compiler warnings in `CheckNonblockingSocketSupport`. detection functions. Without this, these detections fail when `ENABLE_WERROR=ON`. - cmake: disable ENABLE_WERROR for MSVC during symbol checks in `src`. CMake's built-in symbol check function `check_symbol_exists()` generate warnings with MSVC. With warnings considered errors, these detections fail permanently. Our workaround is to disable warnings-as-errors while running these checks. ``` CheckSymbolExists.c(8): warning C4054: 'type cast': from function pointer '__int64 (__cdecl *)(const char *,char **,int)' to data pointer 'int *' in `return ((int*)(&strtoll))[argc];` ``` Ref: https://ci.appveyor.com/project/libssh2org/libssh2/builds/46537222/job/4vg4yg333mu2lg9b - example: replace `strcasecmp()` with C89 `strcmp()`. To avoid using CMake symbol checks in `example`. Another option is to duplicate the `check_symbol_exists()` workaround from `src`, but I figure it's not worth the complexity. We use `strcasecmp()` solely to check optional command-line options for example programs, and those are fine as lower-case. Without this, these detections fail when `ENABLE_WERROR=ON`. - also delete `__function__` detection/use in `example`. To avoid the complexity for the sake of using it at a single place in of the example's error branch. Replace that use with a literal name of the function. - cmake: also use `CMakePushCheckState` functions instead of manual save/restore. Closes #857
This commit is contained in:
@ -34,7 +34,6 @@
|
||||
# OF SUCH DAMAGE.
|
||||
|
||||
include(CheckIncludeFiles)
|
||||
include(CheckSymbolExists)
|
||||
include(CopyRuntimeDependencies)
|
||||
|
||||
set(EXAMPLES
|
||||
@ -87,12 +86,6 @@ check_include_files(arpa/inet.h HAVE_ARPA_INET_H)
|
||||
check_include_files(netinet/in.h HAVE_NETINET_IN_H)
|
||||
check_include_files(winsock2.h HAVE_WINSOCK2_H)
|
||||
|
||||
check_symbol_exists(strcasecmp strings.h HAVE_STRCASECMP)
|
||||
check_symbol_exists(_stricmp string.h HAVE__STRICMP)
|
||||
|
||||
check_symbol_exists(__func__ "" HAVE___FUNC__)
|
||||
check_symbol_exists(__FUNCTION__ "" HAVE___FUNCTION__)
|
||||
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/libssh2_config_cmake.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/libssh2_config.h)
|
||||
|
@ -170,9 +170,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* check for options */
|
||||
if(argc > 8) {
|
||||
if((auth & AUTH_PASSWORD) && !strcasecmp(argv[8], "-p"))
|
||||
if((auth & AUTH_PASSWORD) && !strcmp(argv[8], "-p"))
|
||||
auth = AUTH_PASSWORD;
|
||||
if((auth & AUTH_PUBLICKEY) && !strcasecmp(argv[8], "-k"))
|
||||
if((auth & AUTH_PUBLICKEY) && !strcmp(argv[8], "-k"))
|
||||
auth = AUTH_PUBLICKEY;
|
||||
}
|
||||
|
||||
|
@ -44,27 +44,3 @@
|
||||
#cmakedefine HAVE_ARPA_INET_H
|
||||
#cmakedefine HAVE_NETINET_IN_H
|
||||
#cmakedefine HAVE_WINSOCK2_H
|
||||
|
||||
/* Functions */
|
||||
#cmakedefine HAVE_STRCASECMP
|
||||
#cmakedefine HAVE__STRICMP
|
||||
|
||||
/* Workaround for platforms without POSIX strcasecmp (e.g. Windows) */
|
||||
#ifndef HAVE_STRCASECMP
|
||||
# ifdef HAVE__STRICMP
|
||||
# define strcasecmp _stricmp
|
||||
# define HAVE_STRCASECMP
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Symbols */
|
||||
#cmakedefine HAVE___FUNC__
|
||||
#cmakedefine HAVE___FUNCTION__
|
||||
|
||||
/* Workaround for platforms without C90 __func__ */
|
||||
#ifndef HAVE___FUNC__
|
||||
# ifdef HAVE___FUNCTION__
|
||||
# define __func__ __FUNCTION__
|
||||
# define HAVE___FUNC__
|
||||
# endif
|
||||
#endif
|
||||
|
@ -209,13 +209,13 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* if we got an 4. argument we set this option if supported */
|
||||
if(argc > 5) {
|
||||
if((auth_pw & 1) && !strcasecmp(argv[5], "-p")) {
|
||||
if((auth_pw & 1) && !strcmp(argv[5], "-p")) {
|
||||
auth_pw = 1;
|
||||
}
|
||||
if((auth_pw & 2) && !strcasecmp(argv[5], "-i")) {
|
||||
if((auth_pw & 2) && !strcmp(argv[5], "-i")) {
|
||||
auth_pw = 2;
|
||||
}
|
||||
if((auth_pw & 4) && !strcasecmp(argv[5], "-k")) {
|
||||
if((auth_pw & 4) && !strcmp(argv[5], "-k")) {
|
||||
auth_pw = 4;
|
||||
}
|
||||
}
|
||||
|
@ -180,13 +180,13 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* if we got an 5. argument we set this option if supported */
|
||||
if(argc > 5) {
|
||||
if((auth_pw & 1) && !strcasecmp(argv[5], "-p")) {
|
||||
if((auth_pw & 1) && !strcmp(argv[5], "-p")) {
|
||||
auth_pw = 1;
|
||||
}
|
||||
if((auth_pw & 2) && !strcasecmp(argv[5], "-i")) {
|
||||
if((auth_pw & 2) && !strcmp(argv[5], "-i")) {
|
||||
auth_pw = 2;
|
||||
}
|
||||
if((auth_pw & 4) && !strcasecmp(argv[5], "-k")) {
|
||||
if((auth_pw & 4) && !strcmp(argv[5], "-k")) {
|
||||
auth_pw = 4;
|
||||
}
|
||||
}
|
||||
|
@ -185,13 +185,13 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* if we got an 4. argument we set this option if supported */
|
||||
if(argc > 4) {
|
||||
if((auth_pw & 1) && !strcasecmp(argv[4], "-p")) {
|
||||
if((auth_pw & 1) && !strcmp(argv[4], "-p")) {
|
||||
auth_pw = 1;
|
||||
}
|
||||
if((auth_pw & 2) && !strcasecmp(argv[4], "-i")) {
|
||||
if((auth_pw & 2) && !strcmp(argv[4], "-i")) {
|
||||
auth_pw = 2;
|
||||
}
|
||||
if((auth_pw & 4) && !strcasecmp(argv[4], "-k")) {
|
||||
if((auth_pw & 4) && !strcmp(argv[4], "-k")) {
|
||||
auth_pw = 4;
|
||||
}
|
||||
}
|
||||
|
@ -102,8 +102,8 @@ static int netconf_read_until(LIBSSH2_CHANNEL *channel, const char *endtag,
|
||||
} while(!specialsequence && rd < buflen);
|
||||
|
||||
if(!specialsequence) {
|
||||
fprintf(stderr, "%s: ]]>]]> not found! read buffer too small?\n",
|
||||
__func__);
|
||||
fprintf(stderr, "netconf_read_until(): ]]>]]> not found!"
|
||||
" read buffer too small?\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -211,9 +211,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* check for options */
|
||||
if(argc > 4) {
|
||||
if((auth & AUTH_PASSWORD) && !strcasecmp(argv[4], "-p"))
|
||||
if((auth & AUTH_PASSWORD) && !strcmp(argv[4], "-p"))
|
||||
auth = AUTH_PASSWORD;
|
||||
if((auth & AUTH_PUBLICKEY) && !strcasecmp(argv[4], "-k"))
|
||||
if((auth & AUTH_PUBLICKEY) && !strcmp(argv[4], "-k"))
|
||||
auth = AUTH_PUBLICKEY;
|
||||
}
|
||||
|
||||
|
@ -166,9 +166,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* check for options */
|
||||
if(argc > 8) {
|
||||
if((auth & AUTH_PASSWORD) && !strcasecmp(argv[8], "-p"))
|
||||
if((auth & AUTH_PASSWORD) && !strcmp(argv[8], "-p"))
|
||||
auth = AUTH_PASSWORD;
|
||||
if((auth & AUTH_PUBLICKEY) && !strcasecmp(argv[8], "-k"))
|
||||
if((auth & AUTH_PUBLICKEY) && !strcmp(argv[8], "-k"))
|
||||
auth = AUTH_PUBLICKEY;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user