FindSDL_net.cmake 3.6 KB

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