FindLua50.cmake 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file LICENSE.rst or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindLua50
  5. ---------
  6. .. note::
  7. This module is specifically for Lua version branch 5.0, which is obsolete and
  8. not maintained anymore. In new code use the latest supported Lua version and
  9. the version-agnostic module :module:`FindLua` instead.
  10. Finds the Lua library:
  11. .. code-block:: cmake
  12. find_package(Lua50 [...])
  13. Lua is a embeddable scripting language.
  14. When working with Lua, its library headers are intended to be included in
  15. project source code as:
  16. .. code-block:: c
  17. #include <lua.h>
  18. and not:
  19. .. code-block:: c
  20. #include <lua/lua.h>
  21. This is because, the location of Lua headers may differ across platforms and may
  22. exist in locations other than ``lua/``.
  23. Result Variables
  24. ^^^^^^^^^^^^^^^^
  25. This module defines the following variables:
  26. ``Lua50_FOUND``
  27. .. versionadded:: 3.3
  28. Boolean indicating whether Lua was found.
  29. Cache Variables
  30. ^^^^^^^^^^^^^^^
  31. The following cache variables may also be set:
  32. ``LUA_INCLUDE_DIR``
  33. The directory containing the Lua header files, such as ``lua.h``,
  34. ``lualib.h``, and ``lauxlib.h``, needed to use Lua.
  35. ``LUA_LIBRARIES``
  36. Libraries needed to link against to use Lua. This list includes both ``lua``
  37. and ``lualib`` libraries.
  38. Deprecated Variables
  39. ^^^^^^^^^^^^^^^^^^^^
  40. The following variables are provided for backward compatibility:
  41. ``LUA50_FOUND``
  42. .. deprecated:: 4.2
  43. Use ``Lua50_FOUND``, which has the same value.
  44. Boolean indicating whether Lua was found.
  45. Examples
  46. ^^^^^^^^
  47. Finding the Lua 5.0 library and creating an interface :ref:`imported target
  48. <Imported Targets>` that encapsulates its usage requirements for linking to a
  49. project target:
  50. .. code-block:: cmake
  51. find_package(Lua50)
  52. if(Lua50_FOUND AND NOT TARGET Lua50::Lua50)
  53. add_library(Lua50::Lua50 INTERFACE IMPORTED)
  54. set_target_properties(
  55. Lua50::Lua50
  56. PROPERTIES
  57. INTERFACE_INCLUDE_DIRECTORIES "${LUA_INCLUDE_DIR}"
  58. INTERFACE_LINK_LIBRARIES "${LUA_LIBRARIES}"
  59. )
  60. endif()
  61. target_link_libraries(project_target PRIVATE Lua50::Lua50)
  62. See Also
  63. ^^^^^^^^
  64. * The :module:`FindLua` module to find Lua in version-agnostic way.
  65. #]=======================================================================]
  66. find_path(LUA_INCLUDE_DIR lua.h
  67. HINTS
  68. ENV LUA_DIR
  69. PATH_SUFFIXES lua50 lua5.0 lua5 lua
  70. PATHS
  71. ~/Library/Frameworks
  72. /Library/Frameworks
  73. /opt
  74. )
  75. find_library(LUA_LIBRARY_lua
  76. NAMES lua50 lua5.0 lua-5.0 lua5 lua
  77. HINTS
  78. ENV LUA_DIR
  79. PATH_SUFFIXES lib
  80. PATHS
  81. ~/Library/Frameworks
  82. /Library/Frameworks
  83. /opt
  84. )
  85. # In an OS X framework, lualib is usually included as part of the framework
  86. # (like GLU in OpenGL.framework)
  87. if(${LUA_LIBRARY_lua} MATCHES "framework")
  88. set( LUA_LIBRARIES "${LUA_LIBRARY_lua}" CACHE STRING "Lua framework")
  89. else()
  90. find_library(LUA_LIBRARY_lualib
  91. NAMES lualib50 lualib5.0 lualib5 lualib
  92. HINTS
  93. ENV LUALIB_DIR
  94. ENV LUA_DIR
  95. PATH_SUFFIXES lib
  96. PATHS
  97. /opt
  98. )
  99. if(LUA_LIBRARY_lualib AND LUA_LIBRARY_lua)
  100. # include the math library for Unix
  101. if(UNIX AND NOT APPLE)
  102. find_library(MATH_LIBRARY_FOR_LUA m)
  103. set( LUA_LIBRARIES "${LUA_LIBRARY_lualib};${LUA_LIBRARY_lua};${MATH_LIBRARY_FOR_LUA}" CACHE STRING "This is the concatenation of lua and lualib libraries")
  104. # For Windows and Mac, don't need to explicitly include the math library
  105. else()
  106. set( LUA_LIBRARIES "${LUA_LIBRARY_lualib};${LUA_LIBRARY_lua}" CACHE STRING "This is the concatenation of lua and lualib libraries")
  107. endif()
  108. endif()
  109. endif()
  110. include(FindPackageHandleStandardArgs)
  111. find_package_handle_standard_args(Lua50 DEFAULT_MSG LUA_LIBRARIES LUA_INCLUDE_DIR)
  112. mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARIES)