FindLua.cmake 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # Locate Lua library
  2. # This module defines
  3. # LUA_EXECUTABLE, if found
  4. # LUA_FOUND, if false, do not try to link to Lua
  5. # LUA_LIBRARIES
  6. # LUA_INCLUDE_DIR, where to find lua.h
  7. # LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8)
  8. #
  9. # Note that the expected include convention is
  10. # #include "lua.h"
  11. # and not
  12. # #include <lua/lua.h>
  13. # This is because, the lua location is not standardized and may exist
  14. # in locations other than lua/
  15. #=============================================================================
  16. # Copyright 2007-2009 Kitware, Inc.
  17. # Modified to support Lua 5.2 by LuaDist 2012
  18. #
  19. # Distributed under the OSI-approved BSD License (the "License");
  20. # see accompanying file Copyright.txt for details.
  21. #
  22. # This software is distributed WITHOUT ANY WARRANTY; without even the
  23. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  24. # See the License for more information.
  25. #=============================================================================
  26. # (To distribute this file outside of CMake, substitute the full
  27. # License text for the above reference.)
  28. #
  29. # The required version of Lua can be specified using the
  30. # standard syntax, e.g. FIND_PACKAGE(Lua 5.1)
  31. # Otherwise the module will search for any available Lua implementation
  32. # Always search for non-versioned lua first (recommended)
  33. SET(_POSSIBLE_LUA_INCLUDE include include/lua)
  34. SET(_POSSIBLE_LUA_EXECUTABLE lua)
  35. SET(_POSSIBLE_LUA_LIBRARY lua)
  36. # Determine possible naming suffixes (there is no standard for this)
  37. IF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR)
  38. SET(_POSSIBLE_SUFFIXES "${Lua_FIND_VERSION_MAJOR}${Lua_FIND_VERSION_MINOR}" "${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}" "-${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}")
  39. ELSE(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR)
  40. SET(_POSSIBLE_SUFFIXES "52" "5.2" "-5.2" "51" "5.1" "-5.1")
  41. ENDIF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR)
  42. # Set up possible search names and locations
  43. FOREACH(_SUFFIX ${_POSSIBLE_SUFFIXES})
  44. LIST(APPEND _POSSIBLE_LUA_INCLUDE "include/lua${_SUFFIX}")
  45. LIST(APPEND _POSSIBLE_LUA_EXECUTABLE "lua${_SUFFIX}")
  46. LIST(APPEND _POSSIBLE_LUA_LIBRARY "lua${_SUFFIX}")
  47. ENDFOREACH(_SUFFIX)
  48. # Find the lua executable
  49. FIND_PROGRAM(LUA_EXECUTABLE
  50. NAMES ${_POSSIBLE_LUA_EXECUTABLE}
  51. )
  52. # Find the lua header
  53. FIND_PATH(LUA_INCLUDE_DIR lua.h
  54. HINTS
  55. $ENV{LUA_DIR}
  56. PATH_SUFFIXES ${_POSSIBLE_LUA_INCLUDE}
  57. PATHS
  58. ~/Library/Frameworks
  59. /Library/Frameworks
  60. /usr/local
  61. /usr
  62. /sw # Fink
  63. /opt/local # DarwinPorts
  64. /opt/csw # Blastwave
  65. /opt
  66. )
  67. # Find the lua library
  68. FIND_LIBRARY(LUA_LIBRARY
  69. NAMES ${_POSSIBLE_LUA_LIBRARY}
  70. HINTS
  71. $ENV{LUA_DIR}
  72. PATH_SUFFIXES lib64 lib
  73. PATHS
  74. ~/Library/Frameworks
  75. /Library/Frameworks
  76. /usr/local
  77. /usr
  78. /sw
  79. /opt/local
  80. /opt/csw
  81. /opt
  82. )
  83. IF(LUA_LIBRARY)
  84. # include the math library for Unix
  85. IF(UNIX AND NOT APPLE)
  86. FIND_LIBRARY(LUA_MATH_LIBRARY m)
  87. SET( LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries")
  88. # For Windows and Mac, don't need to explicitly include the math library
  89. ELSE(UNIX AND NOT APPLE)
  90. SET( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries")
  91. ENDIF(UNIX AND NOT APPLE)
  92. ENDIF(LUA_LIBRARY)
  93. # Determine Lua version
  94. IF(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h")
  95. FILE(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua .+\"")
  96. STRING(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}")
  97. UNSET(lua_version_str)
  98. ENDIF()
  99. INCLUDE(FindPackageHandleStandardArgs)
  100. # handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if
  101. # all listed variables are TRUE
  102. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua
  103. REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR
  104. VERSION_VAR LUA_VERSION_STRING)
  105. MARK_AS_ADVANCED(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY LUA_EXECUTABLE)