Imported Upstream version 3.25.0
[platform/upstream/cmake.git] / Modules / FindSDL_net.cmake
1 # Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
3
4 #[=======================================================================[.rst:
5 FindSDL_net
6 -----------
7
8 Locate SDL_net library
9
10 This module defines:
11
12 ::
13
14   SDL_NET_LIBRARIES, the name of the library to link against
15   SDL_NET_INCLUDE_DIRS, where to find the headers
16   SDL_NET_FOUND, if false, do not try to link against
17   SDL_NET_VERSION_STRING - human-readable string containing the version of SDL_net
18
19
20
21 For backward compatibility the following variables are also set:
22
23 ::
24
25   SDLNET_LIBRARY (same value as SDL_NET_LIBRARIES)
26   SDLNET_INCLUDE_DIR (same value as SDL_NET_INCLUDE_DIRS)
27   SDLNET_FOUND (same value as SDL_NET_FOUND)
28
29
30
31 $SDLDIR is an environment variable that would correspond to the
32 ./configure --prefix=$SDLDIR used in building SDL.
33 #]=======================================================================]
34
35 if(NOT SDL_NET_INCLUDE_DIR AND SDLNET_INCLUDE_DIR)
36   set(SDL_NET_INCLUDE_DIR ${SDLNET_INCLUDE_DIR} CACHE PATH "directory cache
37 entry initialized from old variable name")
38 endif()
39 find_path(SDL_NET_INCLUDE_DIR SDL_net.h
40   HINTS
41     ENV SDLNETDIR
42     ENV SDLDIR
43   PATH_SUFFIXES SDL
44                 # path suffixes to search inside ENV{SDLDIR}
45                 include/SDL include/SDL12 include/SDL11 include
46 )
47
48 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
49   set(VC_LIB_PATH_SUFFIX lib/x64)
50 else()
51   set(VC_LIB_PATH_SUFFIX lib/x86)
52 endif()
53
54 if(NOT SDL_NET_LIBRARY AND SDLNET_LIBRARY)
55   set(SDL_NET_LIBRARY ${SDLNET_LIBRARY} CACHE FILEPATH "file cache entry
56 initialized from old variable name")
57 endif()
58 find_library(SDL_NET_LIBRARY
59   NAMES SDL_net
60   HINTS
61     ENV SDLNETDIR
62     ENV SDLDIR
63   PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
64 )
65
66 if(SDL_NET_INCLUDE_DIR AND EXISTS "${SDL_NET_INCLUDE_DIR}/SDL_net.h")
67   file(STRINGS "${SDL_NET_INCLUDE_DIR}/SDL_net.h" SDL_NET_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_NET_MAJOR_VERSION[ \t]+[0-9]+$")
68   file(STRINGS "${SDL_NET_INCLUDE_DIR}/SDL_net.h" SDL_NET_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_NET_MINOR_VERSION[ \t]+[0-9]+$")
69   file(STRINGS "${SDL_NET_INCLUDE_DIR}/SDL_net.h" SDL_NET_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_NET_PATCHLEVEL[ \t]+[0-9]+$")
70   string(REGEX REPLACE "^#define[ \t]+SDL_NET_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_NET_VERSION_MAJOR "${SDL_NET_VERSION_MAJOR_LINE}")
71   string(REGEX REPLACE "^#define[ \t]+SDL_NET_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_NET_VERSION_MINOR "${SDL_NET_VERSION_MINOR_LINE}")
72   string(REGEX REPLACE "^#define[ \t]+SDL_NET_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL_NET_VERSION_PATCH "${SDL_NET_VERSION_PATCH_LINE}")
73   set(SDL_NET_VERSION_STRING ${SDL_NET_VERSION_MAJOR}.${SDL_NET_VERSION_MINOR}.${SDL_NET_VERSION_PATCH})
74   unset(SDL_NET_VERSION_MAJOR_LINE)
75   unset(SDL_NET_VERSION_MINOR_LINE)
76   unset(SDL_NET_VERSION_PATCH_LINE)
77   unset(SDL_NET_VERSION_MAJOR)
78   unset(SDL_NET_VERSION_MINOR)
79   unset(SDL_NET_VERSION_PATCH)
80 endif()
81
82 set(SDL_NET_LIBRARIES ${SDL_NET_LIBRARY})
83 set(SDL_NET_INCLUDE_DIRS ${SDL_NET_INCLUDE_DIR})
84
85 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
86
87 FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL_net
88                                   REQUIRED_VARS SDL_NET_LIBRARIES SDL_NET_INCLUDE_DIRS
89                                   VERSION_VAR SDL_NET_VERSION_STRING)
90
91 # for backward compatibility
92 set(SDLNET_LIBRARY ${SDL_NET_LIBRARIES})
93 set(SDLNET_INCLUDE_DIR ${SDL_NET_INCLUDE_DIRS})
94 set(SDLNET_FOUND ${SDL_NET_FOUND})
95
96 mark_as_advanced(SDL_NET_LIBRARY SDL_NET_INCLUDE_DIR)