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: |
---|
23 | # Finds either Lua 5.0 or Lua 5.1 on the system. The script regards the |
---|
24 | # VERSION, EXACT, REQUIRED and QUIET arguments. A note about the EXACT |
---|
25 | # argument: EXACT 5 will match all Lua 5 versions. |
---|
26 | # When the search was successful, the following variables are set: |
---|
27 | # LUA_INCLUDE_DIR, LUA_LIBRARIES, LUA_VERSION, LUA_FOUND |
---|
28 | # |
---|
29 | |
---|
30 | INCLUDE(CompareVersionStrings) |
---|
31 | INCLUDE(FindPackageHandleAdvancedArgs) |
---|
32 | INCLUDE(HandleLibraryTypes) |
---|
33 | |
---|
34 | # Macro that determines Lua version. Should work for versions 2.2 and above (current release: 5.1.4) |
---|
35 | FUNCTION(DETERMINE_LUA_VERSION _file _varname) |
---|
36 | IF(EXISTS ${_file}) |
---|
37 | FILE(STRINGS ${_file} _file_content REGEX "LUA_VERSION|LUA_RELEASE") |
---|
38 | ELSE() |
---|
39 | SET(${_varname} "0" PARENT_SCOPE) |
---|
40 | RETURN() |
---|
41 | ENDIF() |
---|
42 | STRING(REGEX REPLACE "^.*LUA_RELEASE[ \t]+\"Lua[ \t]+([.0-9]+)\".*$" "\\1" ${_varname} "${_file_content}") |
---|
43 | IF(${_varname} STREQUAL "${_file_content}") |
---|
44 | # At most version 5.1.0 |
---|
45 | STRING(REGEX REPLACE "^.*LUA_VERSION[ \t]+\"Lua[ \t]+([.0-9]+)\".*$" "\\1" ${_varname} "${_file_content}") |
---|
46 | IF(${_varname} STREQUAL "${_file_content}") |
---|
47 | MESSAGE(FATAL_ERROR "Could not determine Lua version which means this script has a bug") |
---|
48 | ENDIF() |
---|
49 | IF(${_varname} MATCHES "^[0-9]+\\.[0-9]+$") |
---|
50 | SET(${_varname} "${${_varname}}.0") # E.g. "3.2" is "3.2.0" actually |
---|
51 | ENDIF() |
---|
52 | ENDIF() |
---|
53 | SET(${_varname} "${${_varname}}" PARENT_SCOPE) |
---|
54 | ENDFUNCTION(DETERMINE_LUA_VERSION) |
---|
55 | |
---|
56 | |
---|
57 | # Find Lua 5.1 |
---|
58 | FIND_PATH(LUA_5.1_INCLUDE_DIR lua.h |
---|
59 | PATHS $ENV{LUA_DIR} |
---|
60 | PATH_SUFFIXES include/lua51 include/lua5.1 include/lua include |
---|
61 | ) |
---|
62 | IF(LUA_5.1_INCLUDE_DIR) |
---|
63 | DETERMINE_LUA_VERSION(${LUA_5.1_INCLUDE_DIR}/lua.h LUA_5.1_VERSION) |
---|
64 | COMPARE_VERSION_STRINGS("${LUA_5.1_VERSION}" "5.1" _version_compare TRUE) |
---|
65 | IF(NOT _version_compare EQUAL 0) |
---|
66 | # Incorrect version found, abort search |
---|
67 | SET(LUA_5.1_INCLUDE_DIR "LUA_5.1_INCLUDE_DIR-NOTFOUND" CACHE PATH "" FORCE) |
---|
68 | ELSE() |
---|
69 | FIND_LIBRARY(LUA_5.1_LIBRARY_OPTIMIZED |
---|
70 | NAMES lua51 lua5.1 lua |
---|
71 | PATHS $ENV{LUA_DIR} |
---|
72 | PATH_SUFFIXES lib64 lib |
---|
73 | ) |
---|
74 | FIND_LIBRARY(LUA_5.1_LIBRARY_DEBUG |
---|
75 | NAMES lua51d lua51_d lua5.1d lua5.1_d luad lua_d |
---|
76 | PATHS $ENV{LUA_DIR} |
---|
77 | PATH_SUFFIXES lib64 lib |
---|
78 | ) |
---|
79 | HANDLE_LIBRARY_TYPES(LUA_5.1) |
---|
80 | SET(LUA_5.1_LIBRARIES ${LUA_5.1_LIBRARY}) |
---|
81 | IF(LUA_5.1_LIBRARIES) |
---|
82 | SET(LUA_5.1_FOUND TRUE) |
---|
83 | ENDIF() |
---|
84 | ENDIF(NOT _version_compare EQUAL 0) |
---|
85 | ENDIF(LUA_5.1_INCLUDE_DIR) |
---|
86 | |
---|
87 | |
---|
88 | # Find Lua 5.0 |
---|
89 | FIND_PATH(LUA_5.0_INCLUDE_DIR lua.h |
---|
90 | PATHS $ENV{LUA_DIR} |
---|
91 | PATH_SUFFIXES include/lua50 include/lua5.0 include/lua5 include/lua include |
---|
92 | ) |
---|
93 | IF(LUA_5.0_INCLUDE_DIR) |
---|
94 | DETERMINE_LUA_VERSION(${LUA_5.0_INCLUDE_DIR}/lua.h LUA_5.0_VERSION) |
---|
95 | COMPARE_VERSION_STRINGS("${LUA_5.0_VERSION}" "5.0" _version_compare TRUE) |
---|
96 | IF(NOT _version_compare EQUAL 0) |
---|
97 | # Incorrect version found, abourt search |
---|
98 | SET(LUA_5.0_INCLUDE_DIR "LUA_5.0_INCLUDE_DIR-NOTFOUND" CACHE PATH "" FORCE) |
---|
99 | ELSE() |
---|
100 | FIND_LIBRARY(LUA_5.0_LUA_LIBRARY_OPTIMIZED |
---|
101 | NAMES lua50 lua5.0 lua5 lua |
---|
102 | PATHS $ENV{LUA_DIR} |
---|
103 | PATH_SUFFIXES lib64 lib |
---|
104 | ) |
---|
105 | FIND_LIBRARY(LUA_5.0_LUA_LIBRARY_DEBUG |
---|
106 | NAMES lua50d lua50_d lua5.0d lua5.0_d lua5d lua5_d luad lua_d |
---|
107 | PATHS $ENV{LUA_DIR} |
---|
108 | PATH_SUFFIXES lib64 lib |
---|
109 | ) |
---|
110 | HANDLE_LIBRARY_TYPES(LUA_5.0_LUA) |
---|
111 | |
---|
112 | # In an OS X framework, lualib is usually included as part of the framework |
---|
113 | # (like GLU in OpenGL.framework) |
---|
114 | IF(${LUA_5.0_LUA_LIBRARY} MATCHES "framework") |
---|
115 | SET(LUA_5.0_LIBRARIES ${LUA_5.0_LUA_LIBRARY}) |
---|
116 | ELSE() |
---|
117 | FIND_LIBRARY(LUA_5.0_LUALIB_LIBRARY_OPTIMIZED |
---|
118 | NAMES lualib50 lualib5.0 lualib5 lualib |
---|
119 | PATHS $ENV{LUALIB_DIR} $ENV{LUA_DIR} |
---|
120 | PATH_SUFFIXES lib64 lib |
---|
121 | ) |
---|
122 | FIND_LIBRARY(LUA_5.0_LUALIB_LIBRARY_DEBUG |
---|
123 | NAMES lualib50d lualib50_d lualib5.0d lualib5.0_d |
---|
124 | lualib5d lualib5_d lualibd lualib_d |
---|
125 | PATHS $ENV{LUALIB_DIR} $ENV{LUA_DIR} |
---|
126 | PATH_SUFFIXES lib64 lib |
---|
127 | ) |
---|
128 | HANDLE_LIBRARY_TYPES(LUA_5.0_LUALIB) |
---|
129 | # Both libraries are required for Lua 5.0 to be found |
---|
130 | IF(LUA_5.0_LUA_LIBRARY AND LUA_5.0_LUALIB_LIBRARY) |
---|
131 | SET(LUA_5.0_LIBRARIES ${LUA_5.0_LUA_LIBRARY} ${LUA_5.0_LUALIB_LIBRARY}) |
---|
132 | ENDIF() |
---|
133 | ENDIF(${LUA_5.0_LUA_LIBRARY} MATCHES "framework") |
---|
134 | |
---|
135 | IF(LUA_5.0_LIBRARIES) |
---|
136 | SET(LUA_5.0_FOUND TRUE) |
---|
137 | ENDIF() |
---|
138 | ENDIF(NOT _version_compare EQUAL 0) |
---|
139 | ENDIF(LUA_5.0_INCLUDE_DIR) |
---|
140 | |
---|
141 | # Pick the right version |
---|
142 | IF(Lua_FIND_VERSION_EXACT AND NOT Lua_FIND_VERSION MATCHES "^[0-9]*$") |
---|
143 | STRING(REGEX REPLACE "^([0-9]+\\.[0-9]+)(\\..*)?$" "\\1" LUA_VERSION_SELECTION ${Lua_FIND_VERSION}) |
---|
144 | ELSE() |
---|
145 | IF(LUA_5.1_FOUND) # Prefer version 5.1 if found |
---|
146 | SET(LUA_VERSION_SELECTION "5.1") |
---|
147 | ELSEIF(LUA_5.0_FOUND) |
---|
148 | SET(LUA_VERSION_SELECTION "5.0") |
---|
149 | ENDIF() |
---|
150 | ENDIF() |
---|
151 | |
---|
152 | SET(LUA_INCLUDE_DIR "${LUA_${LUA_VERSION_SELECTION}_INCLUDE_DIR}") |
---|
153 | SET(LUA_LIBRARIES "${LUA_${LUA_VERSION_SELECTION}_LIBRARIES}") |
---|
154 | SET(LUA_VERSION_LONG "${LUA_${LUA_VERSION_SELECTION}_VERSION}") |
---|
155 | SET(LUA_VERSION "${LUA_VERSION_SELECTION}") |
---|
156 | |
---|
157 | FIND_PACKAGE_HANDLE_ADVANCED_ARGS(Lua DEFAULT_MSG "${LUA_VERSION_LONG}" |
---|
158 | LUA_LIBRARIES |
---|
159 | LUA_INCLUDE_DIR |
---|
160 | ) |
---|
161 | |
---|
162 | # Include the math library for Unix only |
---|
163 | IF(LUA_FOUND) |
---|
164 | IF(UNIX AND NOT APPLE) |
---|
165 | FIND_LIBRARY(UNIX_MATH_LIBRARY m) |
---|
166 | SET(LUA_LIBRARIES ${LUA_LIBRARIES} ${UNIX_MATH_LIBRARY}) |
---|
167 | ENDIF() |
---|
168 | ENDIF(LUA_FOUND) |
---|
169 | |
---|
170 | MARK_AS_ADVANCED( |
---|
171 | LUA_5.0_INCLUDE_DIR |
---|
172 | LUA_5.0_LUA_LIBRARY_OPTIMIZED |
---|
173 | LUA_5.0_LUA_LIBRARY_DEBUG |
---|
174 | LUA_5.0_LUALIB_LIBRARY_OPTIMIZED |
---|
175 | LUA_5.0_LUALIB_LIBRARY_DEBUG |
---|
176 | LUA_5.1_INCLUDE_DIR |
---|
177 | LUA_5.1_LIBRARY_OPTIMIZED |
---|
178 | LUA_5.1_LIBRARY_DEBUG |
---|
179 | UNIX_MATH_LIBRARY |
---|
180 | ) |
---|