| 1 | # - Try to find enet | 
|---|
| 2 | # Once done this will define | 
|---|
| 3 | # | 
|---|
| 4 | #  ENET_FOUND - system has enet | 
|---|
| 5 | #  ENet_INCLUDE_DIR - the enet include directory | 
|---|
| 6 | #  ENet_LIBRARY - the library needed to link against enet | 
|---|
| 7 | # | 
|---|
| 8 | # $ENETDIR is an environment variable used for finding enet. | 
|---|
| 9 | # | 
|---|
| 10 | #  Borrowed from The Mana World | 
|---|
| 11 | #  http://themanaworld.org/ | 
|---|
| 12 | # | 
|---|
| 13 | # Several changes and additions by Fabian 'x3n' Landau | 
|---|
| 14 | # Lots of simplifications by Adrian Friedli and Reto Grieder | 
|---|
| 15 | # Version checking by Reto Grieder | 
|---|
| 16 | #                 > www.orxonox.net < | 
|---|
| 17 |  | 
|---|
| 18 | INCLUDE(FindPackageHandleAdvancedArgs) | 
|---|
| 19 | INCLUDE(HandleLibraryTypes) | 
|---|
| 20 |  | 
|---|
| 21 | FIND_PATH(ENET_INCLUDE_DIR enet/enet.h | 
|---|
| 22 | PATHS $ENV{ENETDIR} | 
|---|
| 23 | PATH_SUFFIXES include | 
|---|
| 24 | ) | 
|---|
| 25 | FIND_LIBRARY(ENET_LIBRARY_OPTIMIZED | 
|---|
| 26 | NAMES enet | 
|---|
| 27 | PATHS $ENV{ENETDIR} | 
|---|
| 28 | PATH_SUFFIXES lib | 
|---|
| 29 | ) | 
|---|
| 30 | FIND_LIBRARY(ENET_LIBRARY_DEBUG | 
|---|
| 31 | NAMES enetd enet_d enet_D | 
|---|
| 32 | PATHS $ENV{ENETDIR} | 
|---|
| 33 | PATH_SUFFIXES lib | 
|---|
| 34 | ) | 
|---|
| 35 |  | 
|---|
| 36 | # Only works for 1.2.2 and higher, otherwise see below | 
|---|
| 37 | DETERMINE_VERSION(ENET ${ENET_INCLUDE_DIR}/enet/enet.h) | 
|---|
| 38 | IF(${ENET_VERSION} STREQUAL "0.0.0") | 
|---|
| 39 | # Try to determine the version. Note that enet only stores the major | 
|---|
| 40 | # version in the header file. So we check for existing functions. | 
|---|
| 41 | # Hence the this script only distinguishes between 1.0, 1.1 and 1.2 | 
|---|
| 42 | FILE(STRINGS ${ENET_INCLUDE_DIR}/enet/enet.h _enet_header REGEX "ENET_") | 
|---|
| 43 | IF(_enet_header MATCHES "ENET_VERSION[ \t]*=[ \t]*1") | 
|---|
| 44 | IF(_enet_header MATCHES "enet_socket_set_option") | 
|---|
| 45 | SET(ENET_VERSION 1.2) | 
|---|
| 46 | ELSEIF(_enet_header MATCHES "enet_peer_disconnect_later") | 
|---|
| 47 | SET(ENET_VERSION 1.1) | 
|---|
| 48 | ELSE() | 
|---|
| 49 | SET(ENET_VERSION 1.0) | 
|---|
| 50 | ENDIF() | 
|---|
| 51 | ELSE() | 
|---|
| 52 | SET(ENET_VERSION 0) # Script doesn't support versions below 1.0 | 
|---|
| 53 | ENDIF() | 
|---|
| 54 | ENDIF() | 
|---|
| 55 |  | 
|---|
| 56 | # Handle the REQUIRED argument and set ENET_FOUND | 
|---|
| 57 | # Also check the the version requirements | 
|---|
| 58 | FIND_PACKAGE_HANDLE_ADVANCED_ARGS(ENet DEFAULT_MSG ${ENET_VERSION} | 
|---|
| 59 | ENET_LIBRARY_OPTIMIZED | 
|---|
| 60 | ENET_INCLUDE_DIR | 
|---|
| 61 | ) | 
|---|
| 62 |  | 
|---|
| 63 | COMPARE_VERSION_STRINGS(${ENET_VERSION} 1.2 _comparison TRUE) | 
|---|
| 64 | IF(${_comparison} EQUAL 1) | 
|---|
| 65 | MESSAGE(STATUS "Warning: Using ENet version 1.3, which is not protocol compatible with 1.1 and 1.2.") | 
|---|
| 66 | ENDIF() | 
|---|
| 67 |  | 
|---|
| 68 | # Collect optimized and debug libraries | 
|---|
| 69 | IF(NOT LINK_ENET_DYNAMIC AND WIN32) | 
|---|
| 70 | # ENet is linked statically, hence we need to add some windows dependencies | 
|---|
| 71 | HANDLE_LIBRARY_TYPES(ENET ws2_32 winmm) | 
|---|
| 72 | ELSE() | 
|---|
| 73 | HANDLE_LIBRARY_TYPES(ENET) | 
|---|
| 74 | ENDIF() | 
|---|
| 75 |  | 
|---|
| 76 | MARK_AS_ADVANCED( | 
|---|
| 77 | ENET_INCLUDE_DIR | 
|---|
| 78 | ENET_LIBRARY_OPTIMIZED | 
|---|
| 79 | ENET_LIBRARY_DEBUG | 
|---|
| 80 | ) | 
|---|