FindLua51.cmake 2.2 KB

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