Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/cmake/tools/FindLua5.1.cmake @ 12067

Last change on this file since 12067 was 11100, checked in by muemart, 9 years ago

Update FindLua5.1.cmake to work with newer versions. Also added another path suffix for include directories.

  • Property svn:eol-style set to native
File size: 3.9 KB
RevLine 
[2626]1 #
2 #             ORXONOX - the hottest 3D action shooter ever to exist
3 #                             > www.orxonox.net <
4 #
5 #        This program is free software; you can redistribute it and/or
6 #         modify it under the terms of the GNU General Public License
7 #        as published by the Free Software Foundation; either version 2
8 #            of the License, or (at your option) any later version.
9 #
10 #       This program is distributed in the hope that it will be useful,
11 #        but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #                 GNU General Public License for more details.
14 #
15 #   You should have received a copy of the GNU General Public License along
16 #      with this program; if not, write to the Free Software Foundation,
17 #     Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 #
19 #
20 #  Author:
21 #    Reto Grieder
22 #  Description:
[7944]23 #    Finds Lua 5.1 on the system.
24 #    Handles REQUIRED and QUIET arguments.
[2626]25 #    When the search was successful, the following variables are set:
[7944]26 #    LUA5.1_INCLUDE_DIR, LUA5.1_LIBRARY, LUA5.1_VERSION, LUA5.1_FOUND
[2626]27 #
28
[2615]29INCLUDE(CompareVersionStrings)
30INCLUDE(FindPackageHandleAdvancedArgs)
31INCLUDE(HandleLibraryTypes)
32
[11100]33# Macro that determines Lua version. Should work for versions 2.2 and above (current release: 5.3.2)
[2615]34FUNCTION(DETERMINE_LUA_VERSION _file _varname)
35  IF(EXISTS ${_file})
36    FILE(STRINGS ${_file} _file_content REGEX "LUA_VERSION|LUA_RELEASE")
[2624]37  ELSE()
[2615]38    SET(${_varname} "0" PARENT_SCOPE)
39    RETURN()
[2624]40  ENDIF()
[2615]41  STRING(REGEX REPLACE "^.*LUA_RELEASE[ \t]+\"Lua[ \t]+([.0-9]+)\".*$" "\\1" ${_varname} "${_file_content}")
42  IF(${_varname} STREQUAL "${_file_content}")
43    # At most version 5.1.0
44    STRING(REGEX REPLACE "^.*LUA_VERSION[ \t]+\"Lua[ \t]+([.0-9]+)\".*$" "\\1" ${_varname} "${_file_content}")
45    IF(${_varname} STREQUAL "${_file_content}")
[11100]46      # Last chance, search for LUA_VERSION_MAJOR and LUA_VERSION_MINOR
47      STRING(REGEX REPLACE "^.*LUA_VERSION_MAJOR[ \t]+\"([0-9]+)\".*$" "\\1" _major "${_file_content}")
48      STRING(REGEX REPLACE "^.*LUA_VERSION_MINOR[ \t]+\"([0-9]+)\".*$" "\\1" _minor "${_file_content}")
49      IF(_major STREQUAL "${_file_content}" OR _minor STREQUAL "${_file_content}")
50        MESSAGE(FATAL_ERROR "Could not determine Lua version which means this script has a bug")
51      ENDIF()
52      SET(${_varname} "${_major}.${_minor}")
[2624]53    ENDIF()
[2615]54    IF(${_varname} MATCHES "^[0-9]+\\.[0-9]+$")
55      SET(${_varname} "${${_varname}}.0") # E.g. "3.2" is "3.2.0" actually
[2624]56    ENDIF()
57  ENDIF()
[2615]58  SET(${_varname} "${${_varname}}" PARENT_SCOPE)
59ENDFUNCTION(DETERMINE_LUA_VERSION)
60
61
[7944]62# Find include path
63FIND_PATH(LUA5.1_INCLUDE_DIR lua.h
[8285]64  PATHS $ENV{LUA5.1_DIR} $ENV{LUA_DIR}
[11100]65  PATH_SUFFIXES lua5.1 include/lua51 include/lua5.1 include/lua include
[2615]66)
[7944]67
68# Check whether we really found Lua version 5.1
69IF(LUA5.1_INCLUDE_DIR)
70  DETERMINE_LUA_VERSION(${LUA5.1_INCLUDE_DIR}/lua.h LUA5.1_VERSION)
71  COMPARE_VERSION_STRINGS("${LUA5.1_VERSION}" "5.1" _version_compare TRUE)
[2615]72  IF(NOT _version_compare EQUAL 0)
[7944]73    # Wrong version
[7951]74    MESSAGE(SEND_ERROR "Version of Lua header found is not 5.1")
[7944]75    SET(LUA5.1_INCLUDE_DIR "LUA5.1_INCLUDE_DIR-NOTFOUND" CACHE PATH "" FORCE)
[2615]76  ENDIF(NOT _version_compare EQUAL 0)
[7944]77ENDIF(LUA5.1_INCLUDE_DIR)
[2615]78
[7944]79# Find library
80FIND_LIBRARY(LUA5.1_LIBRARY_OPTIMIZED
81  NAMES lua51 lua5.1 lua
82  PATHS $ENV{LUA5.1_DIR} $ENV{LUA_DIR}
83  PATH_SUFFIXES lib64 lib
[2615]84)
[7944]85FIND_LIBRARY(LUA5.1_LIBRARY_DEBUG
86  NAMES lua51d lua51_d lua5.1d lua5.1_d
87        lua51D lua51_D lua5.1D lua5.1_D
88        luad lua_d luad lua_D
89  PATHS $ENV{LUA5.1_DIR} $ENV{LUA_DIR}
90  PATH_SUFFIXES lib64 lib
91)
[2615]92
[7944]93# Handle the REQUIRED argument and set LUA5.1_FOUND
[7951]94FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua5.1 DEFAULT_MSG
95  LUA5.1_LIBRARY_OPTIMIZED
[7944]96  LUA5.1_INCLUDE_DIR
[2615]97)
98
[7944]99# Collect optimized and debug libraries
100HANDLE_LIBRARY_TYPES(LUA5.1)
[2615]101
102MARK_AS_ADVANCED(
[7944]103  LUA5.1_INCLUDE_DIR
104  LUA5.1_LIBRARY_OPTIMIZED
105  LUA5.1_LIBRARY_DEBUG
[2615]106)
Note: See TracBrowser for help on using the repository browser.