3 # LUA_FOUND - if false, do not try to link to Lua
4 # LUA_LIBRARIES - both lua and lualib
5 # LUA_INCLUDE_DIR - where to find lua.h
6 # LUA_VERSION_STRING - the version of Lua found
7 # LUA_VERSION_MAJOR - the major version of Lua
8 # LUA_VERSION_MINOR - the minor version of Lua
9 # LUA_VERSION_PATCH - the patch version of Lua
11 # Note that the expected include convention is
14 # #include <lua/lua.h>
15 # This is because, the lua location is not standardized and may exist
16 # in locations other than lua/
18 #=============================================================================
19 # CMake - Cross Platform Makefile Generator
20 # Copyright 2000-2014 Kitware, Inc.
21 # Copyright 2000-2011 Insight Software Consortium
22 # All rights reserved.
24 # Redistribution and use in source and binary forms, with or without
25 # modification, are permitted provided that the following conditions
28 # * Redistributions of source code must retain the above copyright
29 # notice, this list of conditions and the following disclaimer.
31 # * Redistributions in binary form must reproduce the above copyright
32 # notice, this list of conditions and the following disclaimer in the
33 # documentation and/or other materials provided with the distribution.
35 # * Neither the names of Kitware, Inc., the Insight Software Consortium,
36 # nor the names of their contributors may be used to endorse or promote
37 # products derived from this software without specific prior written
40 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
44 # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51 #=============================================================================
52 # See the copyright notice: http://www.cmake.org/licensing/
54 unset(_lua_include_subdirs)
55 unset(_lua_library_names)
57 # this is a function only to have all the variables inside go away automatically
58 function(set_lua_version_vars)
59 set(LUA_VERSIONS5 5.3 5.2 5.1 5.0)
61 if (Lua_FIND_VERSION_EXACT)
62 if (Lua_FIND_VERSION_COUNT GREATER 1)
63 set(lua_append_versions ${Lua_FIND_VERSION_MAJOR} ${Lua_FIND_VERSION_MINOR})
65 elseif (Lua_FIND_VERSION)
66 # once there is a different major version supported this should become a loop
67 if (NOT Lua_FIND_VERSION_MAJOR GREATER 5)
68 if (Lua_FIND_VERSION_COUNT EQUAL 1)
69 set(lua_append_versions ${LUA_VERSIONS5})
71 foreach (subver IN LISTS LUA_VERSIONS5)
72 if (NOT subver VERSION_LESS ${Lua_FIND_VERSION})
73 list(APPEND lua_append_versions ${subver})
79 # once there is a different major version supported this should become a loop
80 set(lua_append_versions ${LUA_VERSIONS5})
83 foreach (ver IN LISTS lua_append_versions)
84 string(REGEX MATCH "^([0-9]+)\\.([0-9]+)$" _ver "${ver}")
85 list(APPEND _lua_include_subdirs
86 include/lua${CMAKE_MATCH_1}${CMAKE_MATCH_2}
87 include/lua${CMAKE_MATCH_1}.${CMAKE_MATCH_2}
88 include/lua-${CMAKE_MATCH_1}.${CMAKE_MATCH_2}
90 list(APPEND _lua_library_names
91 lua${CMAKE_MATCH_1}${CMAKE_MATCH_2}
92 lua${CMAKE_MATCH_1}.${CMAKE_MATCH_2}
93 lua-${CMAKE_MATCH_1}.${CMAKE_MATCH_2}
97 set(_lua_include_subdirs "${_lua_include_subdirs}" PARENT_SCOPE)
98 set(_lua_library_names "${_lua_library_names}" PARENT_SCOPE)
99 endfunction(set_lua_version_vars)
101 set_lua_version_vars()
103 find_path(LUA_INCLUDE_DIR lua.h
106 PATH_SUFFIXES ${_lua_include_subdirs} include/lua include
111 /opt/local # DarwinPorts
115 unset(_lua_include_subdirs)
117 find_library(LUA_LIBRARY
118 NAMES ${_lua_library_names} lua
130 unset(_lua_library_names)
133 # include the math library for Unix
134 if (UNIX AND NOT APPLE AND NOT BEOS)
135 find_library(LUA_MATH_LIBRARY m)
136 set(LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}")
137 # For Windows and Mac, don't need to explicitly include the math library
139 set(LUA_LIBRARIES "${LUA_LIBRARY}")
143 if (LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h")
144 # At least 5.[012] have different ways to express the version
145 # so all of them need to be tested. Lua 5.2 defines LUA_VERSION
146 # and LUA_RELEASE as joined by the C preprocessor, so avoid those.
147 file(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_strings
148 REGEX "^#define[ \t]+LUA_(RELEASE[ \t]+\"Lua [0-9]|VERSION([ \t]+\"Lua [0-9]|_[MR])).*")
150 string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MAJOR[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_MAJOR ";${lua_version_strings};")
151 if (LUA_VERSION_MAJOR MATCHES "^[0-9]+$")
152 string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MINOR[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_MINOR ";${lua_version_strings};")
153 string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_RELEASE[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_PATCH ";${lua_version_strings};")
154 set(LUA_VERSION_STRING "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}.${LUA_VERSION_PATCH}")
156 string(REGEX REPLACE ".*;#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" LUA_VERSION_STRING ";${lua_version_strings};")
157 if (NOT LUA_VERSION_STRING MATCHES "^[0-9.]+$")
158 string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" LUA_VERSION_STRING ";${lua_version_strings};")
160 string(REGEX REPLACE "^([0-9]+)\\.[0-9.]*$" "\\1" LUA_VERSION_MAJOR "${LUA_VERSION_STRING}")
161 string(REGEX REPLACE "^[0-9]+\\.([0-9]+)[0-9.]*$" "\\1" LUA_VERSION_MINOR "${LUA_VERSION_STRING}")
162 string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]).*" "\\1" LUA_VERSION_PATCH "${LUA_VERSION_STRING}")
165 unset(lua_version_strings)
168 include(FindPackageHandleStandardArgs)
169 # handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if
170 # all listed variables are TRUE
171 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua
172 REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR
173 VERSION_VAR LUA_VERSION_STRING)
176 mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARY LUA_MATH_LIBRARY)