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