FindLua50.cmake 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # Locate Lua library
  2. # This module defines
  3. # LUA50_FOUND, if false, do not try to link to Lua
  4. # LUA_LIBRARIES, both lua and lualib
  5. # LUA_INCLUDE_DIR, where to find lua.h and lualib.h (and probably lauxlib.h)
  6. #
  7. # Note that the expected include convention is
  8. # #include "lua.h"
  9. # and not
  10. # #include <lua/lua.h>
  11. # This is because, the lua location is not standardized and may exist
  12. # in locations other than lua/
  13. #=============================================================================
  14. # Copyright 2007-2009 Kitware, Inc.
  15. #
  16. # Distributed under the OSI-approved BSD License (the "License");
  17. # see accompanying file Copyright.txt for details.
  18. #
  19. # This software is distributed WITHOUT ANY WARRANTY; without even the
  20. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  21. # See the License for more information.
  22. #=============================================================================
  23. # (To distribute this file outside of CMake, substitute the full
  24. # License text for the above reference.)
  25. find_path(LUA_INCLUDE_DIR lua.h
  26. HINTS
  27. $ENV{LUA_DIR}
  28. PATH_SUFFIXES include/lua50 include/lua5.0 include/lua5 include/lua include
  29. PATHS
  30. ~/Library/Frameworks
  31. /Library/Frameworks
  32. /sw # Fink
  33. /opt/local # DarwinPorts
  34. /opt/csw # Blastwave
  35. /opt
  36. )
  37. find_library(LUA_LIBRARY_lua
  38. NAMES lua50 lua5.0 lua-5.0 lua5 lua
  39. HINTS
  40. $ENV{LUA_DIR}
  41. PATH_SUFFIXES lib64 lib
  42. PATHS
  43. ~/Library/Frameworks
  44. /Library/Frameworks
  45. /sw
  46. /opt/local
  47. /opt/csw
  48. /opt
  49. )
  50. # In an OS X framework, lualib is usually included as part of the framework
  51. # (like GLU in OpenGL.framework)
  52. if(${LUA_LIBRARY_lua} MATCHES "framework")
  53. set( LUA_LIBRARIES "${LUA_LIBRARY_lua}" CACHE STRING "Lua framework")
  54. else()
  55. find_library(LUA_LIBRARY_lualib
  56. NAMES lualib50 lualib5.0 lualib5 lualib
  57. HINTS
  58. $ENV{LUALIB_DIR}
  59. $ENV{LUA_DIR}
  60. PATH_SUFFIXES lib64 lib
  61. PATHS
  62. /sw
  63. /opt/local
  64. /opt/csw
  65. /opt
  66. )
  67. if(LUA_LIBRARY_lualib AND LUA_LIBRARY_lua)
  68. # include the math library for Unix
  69. if(UNIX AND NOT APPLE)
  70. find_library(MATH_LIBRARY_FOR_LUA m)
  71. set( LUA_LIBRARIES "${LUA_LIBRARY_lualib};${LUA_LIBRARY_lua};${MATH_LIBRARY_FOR_LUA}" CACHE STRING "This is the concatentation of lua and lualib libraries")
  72. # For Windows and Mac, don't need to explicitly include the math library
  73. else()
  74. set( LUA_LIBRARIES "${LUA_LIBRARY_lualib};${LUA_LIBRARY_lua}" CACHE STRING "This is the concatentation of lua and lualib libraries")
  75. endif()
  76. endif()
  77. endif()
  78. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  79. # handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if
  80. # all listed variables are TRUE
  81. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua50 DEFAULT_MSG LUA_LIBRARIES LUA_INCLUDE_DIR)
  82. mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARIES)