FindLua51 — CMake 4.4.2 Documentation

# 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 `FindLua` instead.

Finds the Lua library:

    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:

    #include <lua.h>

and not:

    #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`

  Added in version 3.3.

  Boolean indicating whether (the requested version of) Lua was found.

`Lua51_VERSION`

  Added in version 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 since version 4.2: Use `Lua51_FOUND`, which has the same value.

  Boolean indicating whether (the requested version of) Lua was found.

`LUA_VERSION_STRING`

  Deprecated since version 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 imported target that encapsulates its usage requirements for linking to a project target:

    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 `FindLua` module to find Lua in version-agnostic way.