diff --git a/Modules/FindLua.cmake b/Modules/FindLua.cmake index 396e7d1ab2..50f37f63d5 100644 --- a/Modules/FindLua.cmake +++ b/Modules/FindLua.cmake @@ -5,42 +5,79 @@ FindLua ------- -Locate Lua library. +Finds the Lua library. Lua is a embeddable scripting language. .. versionadded:: 3.18 Support for Lua 5.4. -This module defines: - -``LUA_FOUND`` - if false, do not try to link to Lua -``LUA_LIBRARIES`` - both lua and lualib -``LUA_INCLUDE_DIR`` - where to find lua.h -``LUA_VERSION_STRING`` - the version of Lua found -``LUA_VERSION_MAJOR`` - the major version of Lua -``LUA_VERSION_MINOR`` - the minor version of Lua -``LUA_VERSION_PATCH`` - the patch version of Lua - -Note that the expected include convention is +When working with Lua, its library headers are intended to be included in +project source code as: .. code-block:: c - #include "lua.h" + #include -and not +and not: .. code-block:: c #include -This is because, the lua location is not standardized and may exist in -locations other than lua/ +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: + +``Lua_FOUND`` + Boolean indicating whether (the requested version of) Lua is found. For + backward compatibility, the ``LUA_FOUND`` variable is also set to the same + value. +``LUA_VERSION_STRING`` + The version of Lua found. +``LUA_VERSION_MAJOR`` + The major version of Lua found. +``LUA_VERSION_MINOR`` + The minor version of Lua found. +``LUA_VERSION_PATCH`` + The patch version of Lua found. +``LUA_LIBRARIES`` + Libraries needed to link against to use Lua. This list includes both ``lua`` + and ``lualib`` libraries. + +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. + +Examples +^^^^^^^^ + +Finding the Lua library and creating an interface :ref:`imported target +` that encapsulates its usage requirements for linking to a +project target: + +.. code-block:: cmake + + find_package(Lua) + + if(Lua_FOUND AND NOT TARGET Lua::Lua) + add_library(Lua::Lua INTERFACE IMPORTED) + set_target_properties( + Lua::Lua + PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${LUA_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES "${LUA_LIBRARIES}" + ) + endif() + + target_link_libraries(project_target PRIVATE Lua::Lua) #]=======================================================================] cmake_policy(PUSH) # Policies apply to functions at definition-time @@ -231,8 +268,6 @@ if (LUA_LIBRARY) endif () include(FindPackageHandleStandardArgs) -# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if -# all listed variables are TRUE find_package_handle_standard_args(Lua REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR VERSION_VAR LUA_VERSION_STRING) diff --git a/Modules/FindLua50.cmake b/Modules/FindLua50.cmake index 418b44df5d..ac36c86640 100644 --- a/Modules/FindLua50.cmake +++ b/Modules/FindLua50.cmake @@ -5,19 +5,20 @@ FindLua50 --------- -Locate Lua library. +.. note:: -This module defines:: + This module is specifically for Lua version branch 5.0, which is obsolete and + not maintained anymore. In new code use the latest supported Lua version and + the version-agnostic module :module:`FindLua` instead. - LUA50_FOUND, if false, do not try to link to Lua - LUA_LIBRARIES, both lua and lualib - LUA_INCLUDE_DIR, where to find lua.h and lualib.h (and probably lauxlib.h) +Finds the Lua library. Lua is a embeddable scripting language. -Note that the expected include convention is: +When working with Lua, its library headers are intended to be included in +project source code as: .. code-block:: c - #include "lua.h" + #include and not: @@ -25,8 +26,58 @@ and not: #include -This is because, the lua location is not standardized and may exist in -locations other than lua/ +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: + +``Lua50_FOUND`` + Boolean indicating whether Lua is found. For backward compatibility, the + ``LUA50_FOUND`` variable is also set to the same value. + +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. This list includes both ``lua`` + and ``lualib`` libraries. + +Examples +^^^^^^^^ + +Finding the Lua 5.0 library and creating an interface :ref:`imported target +` that encapsulates its usage requirements for linking to a +project target: + +.. code-block:: cmake + + find_package(Lua50) + + if(Lua50_FOUND AND NOT TARGET Lua50::Lua50) + add_library(Lua50::Lua50 INTERFACE IMPORTED) + set_target_properties( + Lua50::Lua50 + PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${LUA_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES "${LUA_LIBRARIES}" + ) + endif() + + target_link_libraries(project_target PRIVATE Lua50::Lua50) + +See Also +^^^^^^^^ + +* The :module:`FindLua` module to find Lua in version-agnostic way. #]=======================================================================] find_path(LUA_INCLUDE_DIR lua.h @@ -76,10 +127,7 @@ else() endif() endif() - include(FindPackageHandleStandardArgs) -# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if -# all listed variables are TRUE find_package_handle_standard_args(Lua50 DEFAULT_MSG LUA_LIBRARIES LUA_INCLUDE_DIR) mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARIES) diff --git a/Modules/FindLua51.cmake b/Modules/FindLua51.cmake index 750c2ee0c9..cba30e4b58 100644 --- a/Modules/FindLua51.cmake +++ b/Modules/FindLua51.cmake @@ -5,20 +5,20 @@ FindLua51 --------- -Locate Lua library. -This module defines:: +.. note:: - 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) + This module is 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. Lua is a embeddable scripting language. -Note that the expected include convention is: +When working with Lua, its library headers are intended to be included in +project source code as: .. code-block:: c - #include "lua.h" + #include and not: @@ -26,8 +26,58 @@ and not: #include -This is because, the lua location is not standardized and may exist in -locations other than lua/ +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`` + Boolean indicating whether Lua is found. For backward compatibility, the + ``LUA51_FOUND`` variable is also set to the same value. +``LUA_VERSION_STRING`` + The version of Lua 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. + +Examples +^^^^^^^^ + +Finding the Lua 5.1 library and creating an interface :ref:`imported target +` 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) @@ -73,8 +123,6 @@ if(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h") endif() include(FindPackageHandleStandardArgs) -# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if -# all listed variables are TRUE find_package_handle_standard_args(Lua51 REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR VERSION_VAR LUA_VERSION_STRING)