zibbr

Random 3d and p2p stuff that was originally the beginnings of an overly ambitious p2p virtual world thingy
git clone https://code.literati.org/zibbr.git
Log | Files | Refs

FindENET.cmake (2780B)


      1 SET( ENET_DEFINITIONS "")
      2 
      3 ##
      4 # You're going to have to edit this file if you intend to use it for your own project
      5 ##
      6 SET( ENET_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/dependencies/enet )
      7  
      8 IF( EXISTS ${ENET_INCLUDE_DIR} )
      9     SET( ENET_FOUND TRUE )
     10     FILE(GLOB ENET_source ${ENET_INCLUDE_DIR}/*.c)
     11     ADD_LIBRARY(Enet_${PROJECT_NAME} ${ENET_source})
     12     SET(ENET_LIBRARIES Enet_${PROJECT_NAME})
     13     SET(ENET_INCLUDE_DIR ${ENET_INCLUDE_DIR}/include)
     14     IF (WINDOWS)
     15         IF (WIN32)
     16     	    TARGET_LINK_LIBRARIES(Enet_${PROJECT_NAME} "ws2_32.lib")
     17         ELSE (WIN32)
     18             TARGET_LINK_LIBRARIES(Enet_${PROJECT_NAME} "ws2_64.lib")
     19         ENDIF (WIN32)
     20     ELSE (WINDOWS) # unix
     21         INCLUDE(CheckCSourceCompiles)
     22         INCLUDE(CheckCXXSourceCompiles)
     23         INCLUDE(CheckStructMember)
     24         INCLUDE(CheckType)
     25         INCLUDE(CheckFunctionExists) 
     26         INCLUDE(CheckIncludeFiles) 
     27 
     28           
     29         CHECK_FUNCTION_EXISTS("gethostbyaddr_r"   _HAS_GETHOSTBYADDR_R)
     30         CHECK_FUNCTION_EXISTS("gethostbyname_r"   _HAS_GETHOSTBYNAME_R)
     31         CHECK_FUNCTION_EXISTS("poll"              _HAS_POLL)
     32         CHECK_FUNCTION_EXISTS("fcntl"             _HAS_FCNTL)
     33         CHECK_FUNCTION_EXISTS("inet_pton"         _HAS_INET_PTON)
     34         CHECK_FUNCTION_EXISTS("inet_ntop"         _HAS_INET_NTOP)
     35 
     36         CHECK_INCLUDE_FILES ("sys/socket.h"       _HAS_SOCKET_INCLUDE) 
     37         CHECK_INCLUDE_FILES ("sys/types.h"        _HAS_TYPES_INCLUDE) 
     38 
     39         CHECK_STRUCT_MEMBER("msghdr" "msg_flags" "sys/socket.h"  _HAS_MSGHDR_FLAGS)
     40         CHECK_TYPE(socklen_t "sys/types.h;sys/socket.h" _HAS_SOCKLEN_T)
     41 
     42         # list all from above here and add them to the definitions
     43         SET(_CHECKS HAS_GETHOSTBYADDR_R; HAS_GETHOSTBYNAME_R; HAS_POLL; HAS_FCNTL; HAS_INET_PTON; HAS_INET_NTOP; HAS_SOCKET_INCLUDE; HAS_TYPES_INCLUDE; HAS_MSGHDR_FLAGS; HAS_SOCKLEN_T;)
     44         FOREACH (it ${_CHECKS})
     45             IF (${_${it}})
     46                 SET(ENET_DEFINITIONS "${ENET_DEFINITIONS}-D${it}=1 ")
     47             ENDIF (${_${it}})
     48         ENDFOREACH (it)
     49 
     50         SET_SOURCE_FILES_PROPERTIES(${ENET_source} PROPERTIES COMPILE_FLAGS ${ENET_DEFINITIONS})
     51     ENDIF (WINDOWS)
     52 ENDIF( EXISTS ${ENET_INCLUDE_DIR} )
     53  
     54 IF( NOT ENET_FOUND)
     55     IF( NOT ENET_INCLUDE_DIR )
     56         IF (ENET_FIND_REQUIRED)
     57 	    	MESSAGE(FATAL_ERROR "Could not find Enet")
     58     	ENDIF (ENET_FIND_REQUIRED)
     59     ENDIF( NOT ENET_INCLUDE_DIR )
     60 ENDIF( NOT ENET_FOUND)
     61  
     62  
     63 # Finally, display informations if not in quiet mode
     64 IF( NOT ENET_FIND_QUIETLY )
     65   MESSAGE( STATUS "Enet found " )
     66   MESSAGE( STATUS " libraries : ${ENET_LIBRARIES}" )
     67   MESSAGE( STATUS " includes : ${ENET_INCLUDE_DIR}" )
     68 ENDIF( NOT ENET_FIND_QUIETLY )
     69  
     70 MARK_AS_ADVANCED(
     71   ENET_INCLUDE_DIR
     72   ENET_LIBRARIES
     73 )
     74