FindLua51.cmake 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. FindLua51
  5. ---------
  6. Locate Lua library This module defines
  7. ::
  8. LUA51_FOUND, if false, do not try to link to Lua
  9. LUA_LIBRARIES
  10. LUA_INCLUDE_DIR, where to find lua.h
  11. LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8)
  12. Note that the expected include convention is
  13. ::
  14. #include "lua.h"
  15. and not
  16. ::
  17. #include <lua/lua.h>
  18. This is because, the lua location is not standardized and may exist in
  19. locations other than lua/
  20. #]=======================================================================]
  21. find_path(LUA_INCLUDE_DIR lua.h
  22. HINTS
  23. ENV LUA_DIR
  24. PATH_SUFFIXES include/lua51 include/lua5.1 include/lua-5.1 include/lua include
  25. PATHS
  26. ~/Library/Frameworks
  27. /Library/Frameworks
  28. /sw # Fink
  29. /opt/local # DarwinPorts
  30. /opt/csw # Blastwave
  31. /opt
  32. )
  33. find_library(LUA_LIBRARY
  34. NAMES lua51 lua5.1 lua-5.1 lua
  35. HINTS
  36. ENV LUA_DIR
  37. PATH_SUFFIXES lib
  38. PATHS
  39. ~/Library/Frameworks
  40. /Library/Frameworks
  41. /sw
  42. /opt/local
  43. /opt/csw
  44. /opt
  45. )
  46. if(LUA_LIBRARY)
  47. # include the math library for Unix
  48. if(UNIX AND NOT APPLE AND NOT BEOS AND NOT HAIKU)
  49. find_library(LUA_MATH_LIBRARY m)
  50. set( LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries")
  51. # For Windows and Mac, don't need to explicitly include the math library
  52. else()
  53. set( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries")
  54. endif()
  55. endif()
  56. if(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h")
  57. file(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua .+\"")
  58. string(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}")
  59. unset(lua_version_str)
  60. endif()
  61. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  62. # handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if
  63. # all listed variables are TRUE
  64. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua51
  65. REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR
  66. VERSION_VAR LUA_VERSION_STRING)
  67. mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY)