Skip to content

Commit 9b45404

Browse files
rcorreSiegeLord
authored andcommitted
Add FindEnet.cmake for enet examples.
1 parent 3c78462 commit 9b45404

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

cmake/FindENet.cmake

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# - Find ENet
2+
# Find the native ENet includes and libraries
3+
#
4+
# ENET_INCLUDE_DIR - where to find ENet headers.
5+
# ENET_LIBRARIES - List of libraries when using libenet.
6+
# ENET_FOUND - True if libenet found.
7+
8+
if(ENET_INCLUDE_DIR)
9+
# Already in cache, be silent
10+
set(ENET_FIND_QUIETLY TRUE)
11+
endif(ENET_INCLUDE_DIR)
12+
13+
find_path(ENET_INCLUDE_DIR enet/enet.h)
14+
15+
find_library(ENET_LIBRARY NAMES enet enet_static libenet libenet_static)
16+
17+
# Handle the QUIETLY and REQUIRED arguments and set ENET_FOUND to TRUE if
18+
# all listed variables are TRUE.
19+
include(FindPackageHandleStandardArgs)
20+
find_package_handle_standard_args(ENET DEFAULT_MSG
21+
ENET_INCLUDE_DIR ENET_LIBRARY)
22+
23+
if(ENET_FOUND)
24+
set(ENET_LIBRARIES ${ENET_LIBRARY})
25+
else(ENET_FOUND)
26+
set(ENET_LIBRARIES)
27+
endif(ENET_FOUND)
28+
29+
mark_as_advanced(ENET_INCLUDE_DIR ENET_LIBRARY)

examples/CMakeLists.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,12 @@ if(WANT_CURL_EXAMPLE)
245245
endif(CURL_FOUND)
246246
endif(WANT_CURL_EXAMPLE)
247247

248-
# The enet example won't compile if the enet library isn't available.
249-
# This example isn't important so it's disabled by default to prevent problems.
250-
option(WANT_ENET_EXAMPLE "Build ex_enet example" off)
251-
if(WANT_ENET_EXAMPLE)
252-
example(ex_enet_client -lenet ${PRIM})
253-
example(ex_enet_server -lenet)
254-
endif(WANT_ENET_EXAMPLE)
248+
# Only build the enet examples if libenet is installed
249+
find_package(ENet)
250+
if(ENET_FOUND)
251+
example(ex_enet_client ${ENET_LIBRARIES} ${PRIM})
252+
example(ex_enet_server ${ENET_LIBRARIES})
253+
endif(ENET_FOUND)
255254

256255
# example(ex_ogre3d ex_ogre3d.cpp)
257256
# include_directories(/usr/include/OGRE)

0 commit comments

Comments
 (0)