FindLua51.cmake 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. 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. #include "lua.h"
  14. and not::
  15. #include <lua/lua.h>
  16. This is because, the lua location is not standardized and may exist in
  17. locations other than lua/
  18. #]=======================================================================]
  19. cmake_policy(PUSH)
  20. cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>
  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. /opt
  29. )
  30. find_library(LUA_LIBRARY
  31. NAMES lua51 lua5.1 lua-5.1 lua
  32. HINTS
  33. ENV LUA_DIR
  34. PATH_SUFFIXES lib
  35. PATHS
  36. ~/Library/Frameworks
  37. /Library/Frameworks
  38. /opt
  39. )
  40. if(LUA_LIBRARY)
  41. # include the math library for Unix
  42. if(UNIX AND NOT APPLE AND NOT BEOS AND NOT HAIKU)
  43. find_library(LUA_MATH_LIBRARY m)
  44. set( LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries")
  45. # For Windows and Mac, don't need to explicitly include the math library
  46. else()
  47. set( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries")
  48. endif()
  49. endif()
  50. if(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h")
  51. file(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua .+\"")
  52. string(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}")
  53. unset(lua_version_str)
  54. endif()
  55. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  56. # handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if
  57. # all listed variables are TRUE
  58. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua51
  59. REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR
  60. VERSION_VAR LUA_VERSION_STRING)
  61. mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY)
  62. cmake_policy(POP)