FindLua51.cmake 2.2 KB

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