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_LIBRARIES - the libraries needed to use 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 |
---|
15 | # > www.orxonox.net < |
---|
16 | |
---|
17 | INCLUDE(FindPackageHandleAdvancedArgs) |
---|
18 | INCLUDE(HandleLibraryTypes) |
---|
19 | |
---|
20 | FIND_PATH(ENET_INCLUDE_DIR enet/enet.h |
---|
21 | PATHS $ENV{ENETDIR} |
---|
22 | PATH_SUFFIXES include |
---|
23 | ) |
---|
24 | FIND_LIBRARY(ENET_LIBRARY_OPTIMIZED |
---|
25 | NAMES enet |
---|
26 | PATHS $ENV{ENETDIR} |
---|
27 | PATH_SUFFIXES lib |
---|
28 | ) |
---|
29 | FIND_LIBRARY(ENET_LIBRARY_DEBUG |
---|
30 | NAMES enetd enet_d |
---|
31 | PATHS $ENV{ENETDIR} |
---|
32 | PATH_SUFFIXES lib |
---|
33 | ) |
---|
34 | |
---|
35 | # Try to determine the version. Note that enet only stores the major |
---|
36 | # version in the header file. So we check for existing functions. |
---|
37 | # Hence the this script only distinguishes between 1.0, 1.1 and 1.2 |
---|
38 | FILE(STRINGS ${ENET_INCLUDE_DIR}/enet/enet.h _enet_header REGEX "ENET_") |
---|
39 | IF(_enet_header MATCHES "ENET_VERSION[ \t]*=[ \t]*1") |
---|
40 | IF(_enet_header MATCHES "enet_socket_set_option") |
---|
41 | SET(ENET_VERSION 1.2) |
---|
42 | ELSEIF(_enet_header MATCHES "enet_peer_disconnect_later") |
---|
43 | SET(ENET_VERSION 1.1) |
---|
44 | ELSE(_enet_header MATCHES "enet_socket_set_option") |
---|
45 | SET(ENET_VERSION 1.0) |
---|
46 | ENDIF(_enet_header MATCHES "enet_socket_set_option") |
---|
47 | ELSE(_enet_header MATCHES "ENET_VERSION[ \t]*=[ \t]*1") |
---|
48 | SET(ENET_VERSION 0) # Script doesn't support versions below 1.0 |
---|
49 | ENDIF(_enet_header MATCHES "ENET_VERSION[ \t]*=[ \t]*1") |
---|
50 | |
---|
51 | # Handle the REQUIRED argument and set ENET_FOUND |
---|
52 | # Also check the the version requirements |
---|
53 | FIND_PACKAGE_HANDLE_ADVANCED_ARGS(ENet DEFAULT_MSG ${ENET_VERSION} |
---|
54 | ENET_INCLUDE_DIR |
---|
55 | ENET_LIBRARY_OPTIMIZED |
---|
56 | ) |
---|
57 | |
---|
58 | # Collect optimized and debug libraries |
---|
59 | IF(NOT LINK_ENET_DYNAMIC AND WIN32) |
---|
60 | # ENet is linked statically, hence we need to add some windows dependencies |
---|
61 | HANDLE_LIBRARY_TYPES(ENET ws2_32 winmm) |
---|
62 | ELSE(NOT LINK_ENET_DYNAMIC AND WIN32) |
---|
63 | HANDLE_LIBRARY_TYPES(ENET) |
---|
64 | ENDIF(NOT LINK_ENET_DYNAMIC AND WIN32) |
---|
65 | |
---|
66 | MARK_AS_ADVANCED( |
---|
67 | ENET_INCLUDE_DIR |
---|
68 | ENET_LIBRARY_OPTIMIZED |
---|
69 | ENET_LIBRARY_DEBUG |
---|
70 | ) |
---|