#.rst: # FindLua # ------- # # # # Locate Lua library This module defines # # :: # # LUA_FOUND - if false, do not try to link to Lua # LUA_EXECUTABLE - path to lua executable # LUA_LIBRARIES - both lua and lualib # LUA_INCLUDE_DIR - where to find lua.h # LUA_VERSION_STRING - the version of Lua found # LUA_VERSION_MAJOR - the major version of Lua # LUA_VERSION_MINOR - the minor version of Lua # LUA_VERSION_PATCH - the patch version of Lua # # # # Note that the expected include convention is # # :: # # #include "lua.h" # # and not # # :: # # #include # # This is because, the lua location is not standardized and may exist in # locations other than lua/ #============================================================================= # Copyright 2007-2009 Kitware, Inc. # Copyright 2013 Rolf Eike Beer # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. # # This software is distributed WITHOUT ANY WARRANTY; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the License for more information. #============================================================================= # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) find_program(LUA_EXECUTABLE NAMES lua luajit lua51 lua5.1 lua52 lua5.2 lua53 lua5.3 luajit21 luajit20 DOC "lua executable") if (APPLE AND LUA_EXECUTABLE MATCHES "\\.luaenv/shims") execute_process(COMMAND luaenv which lua RESULT_VARIABLE STATUS OUTPUT_VARIABLE LUA_EXECUTABLE ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) endif() if (LUA_EXECUTABLE) get_filename_component(LUAENV_ROOT ${LUA_EXECUTABLE} DIRECTORY) get_filename_component(LUAENV_ROOT ${LUAENV_ROOT} DIRECTORY) endif() find_path(LUA_INCLUDE_DIR lua.h HINTS ENV LUA_DIR PATH_SUFFIXES include/lua51 include/lua5.1 include/lua-5.1 include/lua52 include/lua5.2 include/lua-5.2 include/lua53 include/lua5.3 include/lua-5.3 include/luajit-2.1 include/luajit-2.0 include/lua include PATHS ${LUAENV_ROOT} ~/Library/Frameworks /Library/Frameworks /sw # Fink /opt/local # DarwinPorts /opt/csw # Blastwave /opt ) find_library(LUA_LIBRARY NAMES lua5.1 lua51 lua5.2 lua52 lua5.3 lua53 luajit-5.1 lua HINTS ENV LUA_DIR PATH_SUFFIXES lib PATHS ${LUAENV_ROOT} ~/Library/Frameworks /Library/Frameworks /sw /opt/local /opt/csw /opt ) if (LUA_LIBRARY) # include the math library for Unix if (UNIX AND NOT APPLE AND NOT BEOS) find_library(LUA_MATH_LIBRARY m) set(LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}") # For Windows and Mac, don't need to explicitly include the math library else () set(LUA_LIBRARIES "${LUA_LIBRARY}") endif () endif() if (LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h") # At least 5.[012] have different ways to express the version # so all of them need to be tested. Lua 5.2 defines LUA_VERSION # and LUA_RELEASE as joined by the C preprocessor, so avoid those. file(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_strings REGEX "^#define[ \t]+LUA_(RELEASE[ \t]+\"Lua [0-9]|VERSION([ \t]+\"Lua [0-9]|_[MR])).*") string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MAJOR[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_MAJOR ";${lua_version_strings};") if (LUA_VERSION_MAJOR MATCHES "^[0-9]+$") string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MINOR[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_MINOR ";${lua_version_strings};") string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_RELEASE[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_PATCH ";${lua_version_strings};") set(LUA_VERSION_STRING "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}.${LUA_VERSION_PATCH}") else () string(REGEX REPLACE ".*;#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" LUA_VERSION_STRING ";${lua_version_strings};") if (NOT LUA_VERSION_STRING MATCHES "^[0-9.]+$") string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" LUA_VERSION_STRING ";${lua_version_strings};") endif () string(REGEX REPLACE "^([0-9]+)\\.[0-9.]*$" "\\1" LUA_VERSION_MAJOR "${LUA_VERSION_STRING}") string(REGEX REPLACE "^[0-9]+\\.([0-9]+)[0-9.]*$" "\\1" LUA_VERSION_MINOR "${LUA_VERSION_STRING}") string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]).*" "\\1" LUA_VERSION_PATCH "${LUA_VERSION_STRING}") endif () unset(lua_version_strings) endif() include(FindPackageHandleStandardArgs) # handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if # all listed variables are TRUE find_package_handle_standard_args(Lua REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR VERSION_VAR LUA_VERSION_STRING) mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARY LUA_MATH_LIBRARY)