OPTION (INCLUDE_TCP "Include the TCP transport layer" ON)
OPTION (INCLUDE_UDP "Include the UDP transport layer" ON)

INCLUDE_DIRECTORIES (${PROJECT_BINARY_DIR}/libplayercore)
# Possibly use our own copy of XDR
IF (NOT HAVE_XDR)
    INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR}/replace)
ENDIF (NOT HAVE_XDR)
IF (NOT PTHREAD_INCLUDE_DIR STREQUAL "")
    INCLUDE_DIRECTORIES (${PTHREAD_INCLUDE_DIR})
ENDIF (NOT PTHREAD_INCLUDE_DIR STREQUAL "")
IF (NOT PTHREAD_LIB_DIR STREQUAL "")
    LINK_DIRECTORIES (${PTHREAD_LIB_DIR})
ENDIF (NOT PTHREAD_LIB_DIR STREQUAL "")

IF (PLAYER_OS_QNX)
    SET (socketLibs socket)
    SET (socketLibsFlags -lsocket)
ELSEIF (PLAYER_OS_SOLARIS)
    SET (socketLibs socket nsl)
    SET (socketLibsFlags "-lsocket -lnsl")
ELSE (PLAYER_OS_QNX)
    SET (socketLibs)
    SET (socketLibsFlags)
ENDIF (PLAYER_OS_QNX)

IF (INCLUDE_TCP)
    OPTION (ENABLE_TCP_NODELAY "Turn off Nagel's buffering algorithm (which may increase socket latency when used)" OFF)

    SET (playertcpSrcs socket_util.c playertcp.cc tcpremote_driver.cc)
    IF (NOT HAVE_POLL)
        SET (playerreplaceLib playerreplace)
    ENDIF (NOT HAVE_POLL)
    IF (NOT HAVE_COMPRESSBOUND)
        SET (playerreplaceLib playerreplace)
    ENDIF (NOT HAVE_COMPRESSBOUND)
    IF (NOT HAVE_NANOSLEEP)
        SET (playerreplaceLib playerreplace)
    ENDIF (NOT HAVE_NANOSLEEP)
    PLAYER_ADD_LIBRARY (playertcp ${playertcpSrcs})
    TARGET_LINK_LIBRARIES (playertcp playercore playercommon playerinterface
                           ${playerreplaceLib} ${SOCKET_LIBS})
    IF (PLAYER_OS_WIN)
        TARGET_LINK_LIBRARIES (playertcp Ws2_32)
    ENDIF (PLAYER_OS_WIN)
    IF (SOCKET_LIBS)
        PLAYERCORE_ADD_INT_LINK_LIB (${SOCKET_LIBS})
    ENDIF (SOCKET_LIBS)
    IF (HAVE_Z)
        TARGET_LINK_LIBRARIES (playertcp z)
        PLAYERCORE_ADD_INT_LINK_LIB (z)
        SET (zLibFlag -lz)
    ENDIF (HAVE_Z)
    IF (PLAYER_OS_SOLARIS)
        TARGET_LINK_LIBRARIES (playertcp rt)
        PLAYERCORE_ADD_INT_LINK_LIB (rt)
        SET (rtLibFlag -lrt)
    ENDIF (PLAYER_OS_SOLARIS)
    PLAYER_MAKE_PKGCONFIG ("playertcp" "Player TCP messaging library - part of the Player Project"
                           "playercommon playercore ${playerreplaceLib}" "" ""
                           "${zLibFlag} ${rtLibFlag} ${SOCKET_LIBS_FLAGS}")

    PLAYER_INSTALL_HEADERS (playertcp playertcp.h playertcp_errutils.h)
ENDIF (INCLUDE_TCP)

IF (INCLUDE_UDP)
    SET (playerudpSrcs playerudp.cc)
    IF (NOT HAVE_POLL)
        SET (playerreplaceLib playerreplace)
    ENDIF  (NOT HAVE_POLL)
    IF (NOT HAVE_COMPRESSBOUND)
        SET (playerreplaceLib playerreplace)
    ENDIF (NOT HAVE_COMPRESSBOUND)
    PLAYER_ADD_LIBRARY (playerudp ${playerudpSrcs})
    TARGET_LINK_LIBRARIES (playerudp playercore playercommon playerinterface
                           ${playerreplaceLib} ${SOCKET_LIBS})
    IF (PLAYER_OS_WIN)
        TARGET_LINK_LIBRARIES (playerudp Ws2_32)
    ENDIF (PLAYER_OS_WIN)
    IF (SOCKET_LIBS)
        PLAYERCORE_ADD_INT_LINK_LIB (${SOCKET_LIBS})
    ENDIF (SOCKET_LIBS)
    IF (HAVE_Z)
        TARGET_LINK_LIBRARIES (playerudp z)
        PLAYERCORE_ADD_INT_LINK_LIB (z)
        SET (zLibFlag -lz)
    ELSE (HAVE_Z)
        SET (zLibFlag)
    ENDIF (HAVE_Z)
    PLAYER_MAKE_PKGCONFIG ("playerudp" "Player UDP messaging library - part of the Player Project"
                           "playercommon playercore ${playerreplaceLib}" "" ""
                           "${zLibFlag} ${SOCKET_LIBS_FLAGS}")

    PLAYER_INSTALL_HEADERS (playertcp playerudp.h playertcp_errutils.h)
ENDIF (INCLUDE_UDP)
