1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file LICENSE.rst or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
FindLua51
---------
.. note::
This module is intended specifically for Lua version branch 5.1, which is
obsolete and not maintained anymore. In new code use the latest supported
Lua version and the version-agnostic module :module:`FindLua` instead.
Finds the Lua library:
.. code-block:: cmake
find_package(Lua51 [<version>] [...])
Lua is a embeddable scripting language.
When working with Lua, its library headers are intended to be included in
project source code as:
.. code-block:: c
#include <lua.h>
and not:
.. code-block:: c
#include <lua/lua.h>
This is because, the location of Lua headers may differ across platforms and may
exist in locations other than ``lua/``.
Result Variables
^^^^^^^^^^^^^^^^
This module defines the following variables:
``Lua51_FOUND``
.. versionadded:: 3.3
Boolean indicating whether (the requested version of) Lua was found.
``Lua51_VERSION``
.. versionadded:: 4.2
The version of Lua 5.1 found.
Cache Variables
^^^^^^^^^^^^^^^
The following cache variables may also be set:
``LUA_INCLUDE_DIR``
The directory containing the Lua header files, such as ``lua.h``,
``lualib.h``, and ``lauxlib.h``, needed to use Lua.
``LUA_LIBRARIES``
Libraries needed to link against to use Lua.
Deprecated Variables
^^^^^^^^^^^^^^^^^^^^
The following variables are provided for backward compatibility:
``LUA51_FOUND``
.. deprecated:: 4.2
Use ``Lua51_FOUND``, which has the same value.
Boolean indicating whether (the requested version of) Lua was found.
``LUA_VERSION_STRING``
.. deprecated:: 4.2
Use ``Lua51_VERSION``, which has the same value.
The version of Lua 5.1 found.
Examples
^^^^^^^^
Finding the Lua 5.1 library and creating an interface :ref:`imported target
<Imported Targets>` that encapsulates its usage requirements for linking to a
project target:
.. code-block:: cmake
find_package(Lua51)
if(Lua51_FOUND AND NOT TARGET Lua51::Lua51)
add_library(Lua51::Lua51 INTERFACE IMPORTED)
set_target_properties(
Lua51::Lua51
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${LUA_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "${LUA_LIBRARIES}"
)
endif()
target_link_libraries(project_target PRIVATE Lua51::Lua51)
See Also
^^^^^^^^
* The :module:`FindLua` module to find Lua in version-agnostic way.
#]=======================================================================]
cmake_policy(PUSH)
cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>
find_path(LUA_INCLUDE_DIR lua.h
HINTS
ENV LUA_DIR
PATH_SUFFIXES lua51 lua5.1 lua-5.1 lua
PATHS
~/Library/Frameworks
/Library/Frameworks
/opt
)
find_library(LUA_LIBRARY
NAMES lua51 lua5.1 lua-5.1 lua
HINTS
ENV LUA_DIR
PATH_SUFFIXES lib
PATHS
~/Library/Frameworks
/Library/Frameworks
/opt
)
if(LUA_LIBRARY)
# include the math library for Unix
if(UNIX AND NOT APPLE AND NOT BEOS AND NOT HAIKU)
find_library(LUA_MATH_LIBRARY m)
set( LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries")
# For Windows and Mac, don't need to explicitly include the math library
else()
set( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries")
endif()
endif()
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 .+\"")
string(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([^\"]+)\".*" "\\1" Lua51_VERSION "${lua_version_str}")
set(LUA_VERSION_STRING "${Lua51_VERSION}")
unset(lua_version_str)
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Lua51
REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR
VERSION_VAR Lua51_VERSION)
mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY)
cmake_policy(POP)
|