FindLua50.cmake 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #
  7. #
  8. #
  9. # Locate Lua library This module defines
  10. #
  11. # ::
  12. #
  13. # LUA50_FOUND, if false, do not try to link to Lua
  14. # LUA_LIBRARIES, both lua and lualib
  15. # LUA_INCLUDE_DIR, where to find lua.h and lualib.h (and probably lauxlib.h)
  16. #
  17. #
  18. #
  19. # Note that the expected include convention is
  20. #
  21. # ::
  22. #
  23. # #include "lua.h"
  24. #
  25. # and not
  26. #
  27. # ::
  28. #
  29. # #include <lua/lua.h>
  30. #
  31. # This is because, the lua location is not standardized and may exist in
  32. # locations other than lua/
  33. find_path(LUA_INCLUDE_DIR lua.h
  34. HINTS
  35. ENV LUA_DIR
  36. PATH_SUFFIXES include/lua50 include/lua5.0 include/lua5 include/lua include
  37. PATHS
  38. ~/Library/Frameworks
  39. /Library/Frameworks
  40. /sw # Fink
  41. /opt/local # DarwinPorts
  42. /opt/csw # Blastwave
  43. /opt
  44. )
  45. find_library(LUA_LIBRARY_lua
  46. NAMES lua50 lua5.0 lua-5.0 lua5 lua
  47. HINTS
  48. ENV LUA_DIR
  49. PATH_SUFFIXES lib
  50. PATHS
  51. ~/Library/Frameworks
  52. /Library/Frameworks
  53. /sw
  54. /opt/local
  55. /opt/csw
  56. /opt
  57. )
  58. # In an OS X framework, lualib is usually included as part of the framework
  59. # (like GLU in OpenGL.framework)
  60. if(${LUA_LIBRARY_lua} MATCHES "framework")
  61. set( LUA_LIBRARIES "${LUA_LIBRARY_lua}" CACHE STRING "Lua framework")
  62. else()
  63. find_library(LUA_LIBRARY_lualib
  64. NAMES lualib50 lualib5.0 lualib5 lualib
  65. HINTS
  66. ENV LUALIB_DIR
  67. ENV LUA_DIR
  68. PATH_SUFFIXES lib
  69. PATHS
  70. /sw
  71. /opt/local
  72. /opt/csw
  73. /opt
  74. )
  75. if(LUA_LIBRARY_lualib AND LUA_LIBRARY_lua)
  76. # include the math library for Unix
  77. if(UNIX AND NOT APPLE)
  78. find_library(MATH_LIBRARY_FOR_LUA m)
  79. set( LUA_LIBRARIES "${LUA_LIBRARY_lualib};${LUA_LIBRARY_lua};${MATH_LIBRARY_FOR_LUA}" CACHE STRING "This is the concatenation of lua and lualib libraries")
  80. # For Windows and Mac, don't need to explicitly include the math library
  81. else()
  82. set( LUA_LIBRARIES "${LUA_LIBRARY_lualib};${LUA_LIBRARY_lua}" CACHE STRING "This is the concatenation of lua and lualib libraries")
  83. endif()
  84. endif()
  85. endif()
  86. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  87. # handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if
  88. # all listed variables are TRUE
  89. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua50 DEFAULT_MSG LUA_LIBRARIES LUA_INCLUDE_DIR)
  90. mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARIES)