FindLua51.cmake 2.67 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#.rst:
# FindLua51
# ---------
#
#
#
# Locate Lua library This module defines
#
# ::
#
#   LUA51_FOUND, if false, do not try to link to Lua
#   LUA_LIBRARIES
#   LUA_INCLUDE_DIR, where to find lua.h
#   LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8)
#
#
17 18
#
# Note that the expected include convention is
19 20 21 22 23
#
# ::
#
#   #include "lua.h"
#
24
# and not
25 26 27 28 29 30 31
#
# ::
#
#   #include <lua/lua.h>
#
# This is because, the lua location is not standardized and may exist in
# locations other than lua/
32

33 34 35 36 37 38 39 40 41 42
#=============================================================================
# Copyright 2007-2009 Kitware, Inc.
#
# 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.
#=============================================================================
43
# (To distribute this file outside of CMake, substitute the full
44
#  License text for the above reference.)
45

46
find_path(LUA_INCLUDE_DIR lua.h
47
  HINTS
48
    ENV LUA_DIR
49
  PATH_SUFFIXES include/lua51 include/lua5.1 include/lua-5.1 include/lua include
50 51 52 53 54 55 56 57 58
  PATHS
  ~/Library/Frameworks
  /Library/Frameworks
  /sw # Fink
  /opt/local # DarwinPorts
  /opt/csw # Blastwave
  /opt
)

59
find_library(LUA_LIBRARY
60
  NAMES lua51 lua5.1 lua-5.1 lua
61
  HINTS
62
    ENV LUA_DIR
63
  PATH_SUFFIXES lib
64 65 66 67 68 69 70 71 72
  PATHS
  ~/Library/Frameworks
  /Library/Frameworks
  /sw
  /opt/local
  /opt/csw
  /opt
)

73
if(LUA_LIBRARY)
74
  # include the math library for Unix
75
  if(UNIX AND NOT APPLE AND NOT BEOS AND NOT HAIKU)
76 77
    find_library(LUA_MATH_LIBRARY m)
    set( LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries")
78
  # For Windows and Mac, don't need to explicitly include the math library
79
  else()
80
    set( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries")
81 82
  endif()
endif()
83

84 85
if(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h")
  file(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua .+\"")
86

87 88 89
  string(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}")
  unset(lua_version_str)
endif()
90

91
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
92
# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if
93
# all listed variables are TRUE
94 95 96
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua51
                                  REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR
                                  VERSION_VAR LUA_VERSION_STRING)
97

98
mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY)
99