summary refs log tree commit diff stats
path: root/cmake/FindSDL2_net.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/FindSDL2_net.cmake')
-rw-r--r--cmake/FindSDL2_net.cmake73
1 files changed, 73 insertions, 0 deletions
diff --git a/cmake/FindSDL2_net.cmake b/cmake/FindSDL2_net.cmake new file mode 100644 index 0000000..31eae0a --- /dev/null +++ b/cmake/FindSDL2_net.cmake
@@ -0,0 +1,73 @@
1# - Find SDL2_net library and headers
2#
3# Find module for SDL_net 2.0 (http://www.libsdl.org/projects/SDL_net/).
4# It defines the following variables:
5# SDL2_NET_INCLUDE_DIRS - The location of the headers, e.g., SDL_net.h.
6# SDL2_NET_LIBRARIES - The libraries to link against to use SDL2_net.
7# SDL2_NET_FOUND - If false, do not try to use SDL2_net.
8# SDL2_NET_VERSION_STRING
9# Human-readable string containing the version of SDL2_net.
10#
11# Also defined, but not for general use are:
12# SDL2_NET_INCLUDE_DIR - The directory that contains SDL_net.h.
13# SDL2_NET_LIBRARY - The location of the SDL2_net library.
14#
15
16#=============================================================================
17# Copyright 2013 Benjamin Eikel
18#
19# Distributed under the OSI-approved BSD License (the "License");
20# see accompanying file Copyright.txt for details.
21#
22# This software is distributed WITHOUT ANY WARRANTY; without even the
23# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24# See the License for more information.
25#=============================================================================
26# (To distribute this file outside of CMake, substitute the full
27# License text for the above reference.)
28
29find_package(PkgConfig QUIET)
30pkg_check_modules(PC_SDL2_NET QUIET SDL2_net)
31
32find_path(SDL2_NET_INCLUDE_DIR
33 NAMES SDL_net.h
34 HINTS
35 ${PC_SDL2_NET_INCLUDEDIR}
36 ${PC_SDL2_NET_INCLUDE_DIRS}
37 PATH_SUFFIXES SDL2
38)
39
40find_library(SDL2_NET_LIBRARY
41 NAMES SDL2_net
42 HINTS
43 ${PC_SDL2_NET_LIBDIR}
44 ${PC_SDL2_NET_LIBRARY_DIRS}
45 PATH_SUFFIXES x64 x86
46)
47
48if(SDL2_NET_INCLUDE_DIR AND EXISTS "${SDL2_NET_INCLUDE_DIR}/SDL_net.h")
49 file(STRINGS "${SDL2_NET_INCLUDE_DIR}/SDL_net.h" SDL2_NET_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_NET_MAJOR_VERSION[ \t]+[0-9]+$")
50 file(STRINGS "${SDL2_NET_INCLUDE_DIR}/SDL_net.h" SDL2_NET_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_NET_MINOR_VERSION[ \t]+[0-9]+$")
51 file(STRINGS "${SDL2_NET_INCLUDE_DIR}/SDL_net.h" SDL2_NET_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_NET_PATCHLEVEL[ \t]+[0-9]+$")
52 string(REGEX REPLACE "^#define[ \t]+SDL_NET_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_NET_VERSION_MAJOR "${SDL2_NET_VERSION_MAJOR_LINE}")
53 string(REGEX REPLACE "^#define[ \t]+SDL_NET_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_NET_VERSION_MINOR "${SDL2_NET_VERSION_MINOR_LINE}")
54 string(REGEX REPLACE "^#define[ \t]+SDL_NET_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_NET_VERSION_PATCH "${SDL2_NET_VERSION_PATCH_LINE}")
55 set(SDL2_NET_VERSION_STRING ${SDL2_NET_VERSION_MAJOR}.${SDL2_NET_VERSION_MINOR}.${SDL2_NET_VERSION_PATCH})
56 unset(SDL2_NET_VERSION_MAJOR_LINE)
57 unset(SDL2_NET_VERSION_MINOR_LINE)
58 unset(SDL2_NET_VERSION_PATCH_LINE)
59 unset(SDL2_NET_VERSION_MAJOR)
60 unset(SDL2_NET_VERSION_MINOR)
61 unset(SDL2_NET_VERSION_PATCH)
62endif()
63
64set(SDL2_NET_INCLUDE_DIRS ${SDL2_NET_INCLUDE_DIR})
65set(SDL2_NET_LIBRARIES ${SDL2_NET_LIBRARY})
66
67include(FindPackageHandleStandardArgs)
68
69find_package_handle_standard_args(SDL2_net
70 REQUIRED_VARS SDL2_NET_INCLUDE_DIRS SDL2_NET_LIBRARIES
71 VERSION_VAR SDL2_NET_VERSION_STRING)
72
73mark_as_advanced(SDL2_NET_INCLUDE_DIR SDL2_NET_LIBRARY) \ No newline at end of file