FindLua51.cmake 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #.rst:
  2. # FindLua51
  3. # ---------
  4. #
  5. #
  6. #
  7. # Locate Lua library This module defines
  8. #
  9. # ::
  10. #
  11. # LUA51_FOUND, if false, do not try to link to Lua
  12. # LUA_LIBRARIES
  13. # LUA_INCLUDE_DIR, where to find lua.h
  14. # LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8)
  15. #
  16. #
  17. #
  18. # Note that the expected include convention is
  19. #
  20. # ::
  21. #
  22. # #include "lua.h"
  23. #
  24. # and not
  25. #
  26. # ::
  27. #
  28. # #include <lua/lua.h>
  29. #
  30. # This is because, the lua location is not standardized and may exist in
  31. # locations other than lua/
  32. #=============================================================================
  33. # Copyright 2007-2009 Kitware, Inc.
  34. #
  35. # Distributed under the OSI-approved BSD License (the "License");
  36. # see accompanying file Copyright.txt for details.
  37. #
  38. # This software is distributed WITHOUT ANY WARRANTY; without even the
  39. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  40. # See the License for more information.
  41. #=============================================================================
  42. # (To distribute this file outside of CMake, substitute the full
  43. # License text for the above reference.)
  44. find_path(LUA_INCLUDE_DIR lua.h
  45. HINTS
  46. ENV LUA_DIR
  47. PATH_SUFFIXES include/lua51 include/lua5.1 include/lua-5.1 include/lua include
  48. PATHS
  49. ~/Library/Frameworks
  50. /Library/Frameworks
  51. /sw # Fink
  52. /opt/local # DarwinPorts
  53. /opt/csw # Blastwave
  54. /opt
  55. )
  56. find_library(LUA_LIBRARY
  57. NAMES lua51 lua5.1 lua-5.1 lua
  58. HINTS
  59. ENV LUA_DIR
  60. PATH_SUFFIXES lib
  61. PATHS
  62. ~/Library/Frameworks
  63. /Library/Frameworks
  64. /sw
  65. /opt/local
  66. /opt/csw
  67. /opt
  68. )
  69. if(LUA_LIBRARY)
  70. # include the math library for Unix
  71. if(UNIX AND NOT APPLE AND NOT BEOS AND NOT HAIKU)
  72. find_library(LUA_MATH_LIBRARY m)
  73. set( LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries")
  74. # For Windows and Mac, don't need to explicitly include the math library
  75. else()
  76. set( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries")
  77. endif()
  78. endif()
  79. if(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h")
  80. file(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua .+\"")
  81. string(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}")
  82. unset(lua_version_str)
  83. endif()
  84. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  85. # handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if
  86. # all listed variables are TRUE
  87. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua51
  88. REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR
  89. VERSION_VAR LUA_VERSION_STRING)
  90. mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY)