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 | # Try to determine the version. Note that enet only stores the major |
---|
37 | # version in the header file. So we check for existing functions. |
---|
38 | # Hence the this script only distinguishes between 1.0, 1.1 and 1.2 |
---|
39 | FILE(STRINGS ${ENET_INCLUDE_DIR}/enet/enet.h _enet_header REGEX "ENET_") |
---|
40 | IF(_enet_header MATCHES "ENET_VERSION[ \t]*=[ \t]*1") |
---|
41 | IF(_enet_header MATCHES "enet_socket_set_option") |
---|
42 | SET(ENET_VERSION 1.2) |
---|
43 | ELSEIF(_enet_header MATCHES "enet_peer_disconnect_later") |
---|
44 | SET(ENET_VERSION 1.1) |
---|
45 | ELSE() |
---|
46 | SET(ENET_VERSION 1.0) |
---|
47 | ENDIF() |
---|
48 | ELSE() |
---|
49 | SET(ENET_VERSION 0) # Script doesn't support versions below 1.0 |
---|
50 | ENDIF() |
---|
51 | |
---|
52 | # Handle the REQUIRED argument and set ENET_FOUND |
---|
53 | # Also check the the version requirements |
---|
54 | FIND_PACKAGE_HANDLE_ADVANCED_ARGS(ENet DEFAULT_MSG ${ENET_VERSION} |
---|
55 | ENET_LIBRARY_OPTIMIZED |
---|
56 | ENET_INCLUDE_DIR |
---|
57 | ) |
---|
58 | |
---|
59 | # Collect optimized and debug libraries |
---|
60 | IF(NOT LINK_ENET_DYNAMIC AND WIN32) |
---|
61 | # ENet is linked statically, hence we need to add some windows dependencies |
---|
62 | HANDLE_LIBRARY_TYPES(ENET ws2_32 winmm) |
---|
63 | ELSE() |
---|
64 | HANDLE_LIBRARY_TYPES(ENET) |
---|
65 | ENDIF() |
---|
66 | |
---|
67 | MARK_AS_ADVANCED( |
---|
68 | ENET_INCLUDE_DIR |
---|
69 | ENET_LIBRARY_OPTIMIZED |
---|
70 | ENET_LIBRARY_DEBUG |
---|
71 | ) |
---|