FindLua51.cmake 2.6 KB

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