# Checks for libsocket, libm, ... and if we need to specify them
# explicitly
#
# Result variables:
# - WT_SOCKET_LIBRARY: the socket library on this system
# - WT_MATH_LIBRARY: the math library on this system

INCLUDE(CheckFunctionExists)
INCLUDE(CheckLibraryExists)

IF(WIN32)
  SET(WT_SOCKET_LIBRARY ws2_32 mswsock)
ELSE(WIN32)
  CHECK_FUNCTION_EXISTS(connect SYSTEM_CONNECT_EXISTS)
  IF(NOT SYSTEM_CONNECT_EXISTS)
    CHECK_LIBRARY_EXISTS(socket connect "" SYSTEM_CONNECT_EXISTS)
    IF(SYSTEM_CONNECT_EXISTS)
      SET(WT_SOCKET_LIBRARY "socket")
    ENDIF(SYSTEM_CONNECT_EXISTS)
  ELSE(NOT SYSTEM_CONNECT_EXISTS)
    SET(WT_SOCKET_LIBRARY "")
  ENDIF(NOT SYSTEM_CONNECT_EXISTS)
ENDIF(WIN32)


CHECK_FUNCTION_EXISTS(sin SYSTEM_SIN_EXISTS)
IF(NOT SYSTEM_SIN_EXISTS)
  CHECK_LIBRARY_EXISTS(m sin "" SYSTEM_SIN_EXISTS)
  IF(SYSTEM_SIN_EXISTS)
    SET(WT_SOCKET_LIBRARY "m")
  ENDIF(SYSTEM_SIN_EXISTS)
ELSE(NOT SYSTEM_SIN_EXISTS)
  SET(WT_MATH_LIBRARY "")
ENDIF(NOT SYSTEM_SIN_EXISTS)

