FindLua50.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. FindLua50
  5. ---------
  6. Locate Lua library.
  7. This module defines::
  8. ::
  9. LUA50_FOUND, if false, do not try to link to Lua
  10. LUA_LIBRARIES, both lua and lualib
  11. LUA_INCLUDE_DIR, where to find lua.h and lualib.h (and probably lauxlib.h)
  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/lua50 include/lua5.0 include/lua5 include/lua include
  25. PATHS
  26. ~/Library/Frameworks
  27. /Library/Frameworks
  28. /opt
  29. )
  30. find_library(LUA_LIBRARY_lua
  31. NAMES lua50 lua5.0 lua-5.0 lua5 lua
  32. HINTS
  33. ENV LUA_DIR
  34. PATH_SUFFIXES lib
  35. PATHS
  36. ~/Library/Frameworks
  37. /Library/Frameworks
  38. /opt
  39. )
  40. # In an OS X framework, lualib is usually included as part of the framework
  41. # (like GLU in OpenGL.framework)
  42. if(${LUA_LIBRARY_lua} MATCHES "framework")
  43. set( LUA_LIBRARIES "${LUA_LIBRARY_lua}" CACHE STRING "Lua framework")
  44. else()
  45. find_library(LUA_LIBRARY_lualib
  46. NAMES lualib50 lualib5.0 lualib5 lualib
  47. HINTS
  48. ENV LUALIB_DIR
  49. ENV LUA_DIR
  50. PATH_SUFFIXES lib
  51. PATHS
  52. /opt
  53. )
  54. if(LUA_LIBRARY_lualib AND LUA_LIBRARY_lua)
  55. # include the math library for Unix
  56. if(UNIX AND NOT APPLE)
  57. find_library(MATH_LIBRARY_FOR_LUA m)
  58. set( LUA_LIBRARIES "${LUA_LIBRARY_lualib};${LUA_LIBRARY_lua};${MATH_LIBRARY_FOR_LUA}" CACHE STRING "This is the concatenation of lua and lualib libraries")
  59. # For Windows and Mac, don't need to explicitly include the math library
  60. else()
  61. set( LUA_LIBRARIES "${LUA_LIBRARY_lualib};${LUA_LIBRARY_lua}" CACHE STRING "This is the concatenation of lua and lualib libraries")
  62. endif()
  63. endif()
  64. endif()
  65. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  66. # handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if
  67. # all listed variables are TRUE
  68. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua50 DEFAULT_MSG LUA_LIBRARIES LUA_INCLUDE_DIR)
  69. mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARIES)