mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-08-05 20:55:46 +03:00
cmake: Fix detection of clock_gettime.
This commit is contained in:
@@ -107,11 +107,13 @@ if (UNIX)
|
|||||||
|
|
||||||
# librt
|
# librt
|
||||||
check_library_exists(rt nanosleep "" HAVE_LIBRT)
|
check_library_exists(rt nanosleep "" HAVE_LIBRT)
|
||||||
if (HAVE_LIBRT)
|
|
||||||
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} rt)
|
|
||||||
endif (HAVE_LIBRT)
|
|
||||||
endif (NOT LINUX)
|
endif (NOT LINUX)
|
||||||
|
|
||||||
|
check_library_exists(rt clock_gettime "" HAVE_CLOCK_GETTIME)
|
||||||
|
if (HAVE_LIBRT OR HAVE_CLOCK_GETTIME)
|
||||||
|
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} rt)
|
||||||
|
endif (HAVE_LIBRT OR HAVE_CLOCK_GETTIME)
|
||||||
|
|
||||||
check_library_exists(util forkpty "" HAVE_LIBUTIL)
|
check_library_exists(util forkpty "" HAVE_LIBUTIL)
|
||||||
check_function_exists(getaddrinfo HAVE_GETADDRINFO)
|
check_function_exists(getaddrinfo HAVE_GETADDRINFO)
|
||||||
check_function_exists(poll HAVE_POLL)
|
check_function_exists(poll HAVE_POLL)
|
||||||
@@ -120,11 +122,6 @@ if (UNIX)
|
|||||||
check_function_exists(regcomp HAVE_REGCOMP)
|
check_function_exists(regcomp HAVE_REGCOMP)
|
||||||
endif (UNIX)
|
endif (UNIX)
|
||||||
|
|
||||||
check_library_exists(rt clock_gettime "" HAVE_LIBRT)
|
|
||||||
if (HAVE_LIBRT)
|
|
||||||
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} rt)
|
|
||||||
endif (HAVE_LIBRT)
|
|
||||||
|
|
||||||
set(LIBSSH_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CACHE INTERNAL "libssh required system libraries")
|
set(LIBSSH_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CACHE INTERNAL "libssh required system libraries")
|
||||||
|
|
||||||
# LIBRARIES
|
# LIBRARIES
|
||||||
|
@@ -77,6 +77,9 @@
|
|||||||
/* Define to 1 if you have the `regcomp' function. */
|
/* Define to 1 if you have the `regcomp' function. */
|
||||||
#cmakedefine HAVE_REGCOMP 1
|
#cmakedefine HAVE_REGCOMP 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `clock_gettime' function. */
|
||||||
|
#cmakedefine HAVE_CLOCK_GETTIME 1
|
||||||
|
|
||||||
/*************************** LIBRARIES ***************************/
|
/*************************** LIBRARIES ***************************/
|
||||||
|
|
||||||
/* Define to 1 if you have the `crypto' library (-lcrypto). */
|
/* Define to 1 if you have the `crypto' library (-lcrypto). */
|
||||||
|
14
src/misc.c
14
src/misc.c
@@ -42,7 +42,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#ifndef HAVE_RT
|
#ifndef HAVE_CLOCK_GETTIME
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -872,18 +872,20 @@ int ssh_analyze_banner(ssh_session session, int server, int *ssh1, int *ssh2) {
|
|||||||
* @param[out] ts pointer to an allocated ssh_timestamp structure
|
* @param[out] ts pointer to an allocated ssh_timestamp structure
|
||||||
*/
|
*/
|
||||||
void ssh_timestamp_init(struct ssh_timestamp *ts){
|
void ssh_timestamp_init(struct ssh_timestamp *ts){
|
||||||
#ifndef HAVE_RT
|
#ifdef HAVE_CLOCK_GETTIME
|
||||||
struct timeval tp;
|
|
||||||
gettimeofday(&tp, NULL);
|
|
||||||
ts->useconds = tp.tv_usec;
|
|
||||||
#else
|
|
||||||
struct timespec tp;
|
struct timespec tp;
|
||||||
clock_gettime(CLOCK, &tp);
|
clock_gettime(CLOCK, &tp);
|
||||||
ts->useconds = tp.tv_nsec / 1000;
|
ts->useconds = tp.tv_nsec / 1000;
|
||||||
|
#else
|
||||||
|
struct timeval tp;
|
||||||
|
gettimeofday(&tp, NULL);
|
||||||
|
ts->useconds = tp.tv_usec;
|
||||||
#endif
|
#endif
|
||||||
ts->seconds = tp.tv_sec;
|
ts->seconds = tp.tv_sec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef CLOCK
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
* @brief gets the time difference between two timestamps in ms
|
* @brief gets the time difference between two timestamps in ms
|
||||||
|
Reference in New Issue
Block a user