Ticket #40228: FindLua52.cmake

File FindLua52.cmake, 2.6 KB (added by mojca (Mojca Miklavec), 11 years ago)

FindLua51.cmake with 5.1 replaced by 5.2

Line 
1# Locate Lua library
2# This module defines
3#  LUA52_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#=============================================================================
16# Copyright 2007-2009 Kitware, Inc.
17#
18# Distributed under the OSI-approved BSD License (the "License");
19# see accompanying file Copyright.txt for details.
20#
21# This software is distributed WITHOUT ANY WARRANTY; without even the
22# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23# See the License for more information.
24#=============================================================================
25# (To distribute this file outside of CMake, substitute the full
26#  License text for the above reference.)
27
28find_path(LUA_INCLUDE_DIR lua.h
29  HINTS
30    ENV LUA_DIR
31  PATH_SUFFIXES include/lua52 include/lua5.2 include/lua-5.2 include/lua include
32  PATHS
33  ~/Library/Frameworks
34  /Library/Frameworks
35  /sw # Fink
36  /opt/local # DarwinPorts
37  /opt/csw # Blastwave
38  /opt
39)
40
41find_library(LUA_LIBRARY
42  NAMES lua52 lua5.2 lua-5.2 lua
43  HINTS
44    ENV LUA_DIR
45  PATH_SUFFIXES lib
46  PATHS
47  ~/Library/Frameworks
48  /Library/Frameworks
49  /sw
50  /opt/local
51  /opt/csw
52  /opt
53)
54
55if(LUA_LIBRARY)
56  # include the math library for Unix
57  if(UNIX AND NOT APPLE AND NOT BEOS)
58    find_library(LUA_MATH_LIBRARY m)
59    set( LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries")
60  # For Windows and Mac, don't need to explicitly include the math library
61  else()
62    set( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries")
63  endif()
64endif()
65
66if(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h")
67  file(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua .+\"")
68
69  string(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}")
70  unset(lua_version_str)
71endif()
72
73include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
74# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if
75# all listed variables are TRUE
76FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua52
77                                  REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR
78                                  VERSION_VAR LUA_VERSION_STRING)
79
80mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY)
81