Merge branch 'main/rendor-staging' into fixes
[ryzomcore.git] / CMakeModules / FindLuabind.cmake
blobf4c8331e0613881c0182afe17cfb607d6b94e725
1 # - Locate Luabind library
2 # This module defines
3 #  LUABIND_LIBRARIES, the libraries to link against
4 #  LUABIND_FOUND, if false, do not try to link to LUABIND
5 #  LUABIND_INCLUDE_DIR, where to find headers.
6 INCLUDE(FindHelpers)
8 MACRO(FIND_CORRECT_LUA_VERSION)
9   # Check Lua version linked to Luabind under Linux
10   IF(LUABIND_LIBRARY_RELEASE MATCHES "\\.so")
11     INCLUDE(CheckDepends)
13     # check for Lua 5.3
14     SET(LUA53_LIBRARIES liblua5.3 liblua-5.3 liblua.so.5.3)
16     FOREACH(_LIB ${LUA53_LIBRARIES})
17       CHECK_LINKED_LIBRARY(LUABIND_LIBRARY_RELEASE _LIB LUALIB_FOUND)
18       IF(LUALIB_FOUND)
19         MESSAGE(STATUS "Luabind is using Lua 5.3")
20         FIND_PACKAGE(Lua53 REQUIRED)
21         BREAK()
22       ENDIF()
23     ENDFOREACH()
25     IF(NOT LUALIB_FOUND)
26       # check for Lua 5.2
27       SET(LUA52_LIBRARIES liblua5.2 liblua-5.2 liblua.so.5.2)
29       FOREACH(_LIB ${LUA52_LIBRARIES})
30         CHECK_LINKED_LIBRARY(LUABIND_LIBRARY_RELEASE _LIB LUALIB_FOUND)
31         IF(LUALIB_FOUND)
32           MESSAGE(STATUS "Luabind is using Lua 5.2")
33           FIND_PACKAGE(Lua52 REQUIRED)
34           BREAK()
35         ENDIF()
36       ENDFOREACH()
37     ENDIF()
39     IF(NOT LUALIB_FOUND)
40       # check for Lua 5.1
41       SET(LUA51_LIBRARIES liblua5.1 liblua-5.1 liblua.so.5.1)
43       FOREACH(_LIB ${LUA51_LIBRARIES})
44         CHECK_LINKED_LIBRARY(LUABIND_LIBRARY_RELEASE _LIB LUALIB_FOUND)
45         IF(LUALIB_FOUND)
46           MESSAGE(STATUS "Luabind is using Lua 5.1")
47           FIND_PACKAGE(Lua51 REQUIRED)
48           BREAK()
49         ENDIF()
50       ENDFOREACH()
51     ENDIF()
53     IF(NOT LUALIB_FOUND)
54       # check for Lua 5.0
55       SET(LUA50_LIBRARIES liblua5.0 liblua-5.0 liblua.so.5.0)
57       FOREACH(_LIB ${LUA50_LIBRARIES})
58         CHECK_LINKED_LIBRARY(LUABIND_LIBRARY_RELEASE _LIB LUALIB_FOUND)
59         IF(LUALIB_FOUND)
60           MESSAGE(STATUS "Luabind is using Lua 5.0")
61           FIND_PACKAGE(Lua50 REQUIRED)
62           BREAK()
63         ENDIF()
64       ENDFOREACH()
65     ENDIF()
67     IF(NOT LUALIB_FOUND)
68       MESSAGE(FATAL_ERROR "Can't determine Lua version used by Luabind")
69     ENDIF()
70   ELSE()
71     # TODO: find a way to detect Lua version
72     IF(HUNTER_ENABLED)
73       HUNTER_ADD_PACKAGE(Lua)
74       FIND_PACKAGE(Lua CONFIG REQUIRED)
75       SET(LUA_LIBRARIES Lua::lua_lib)
76     ELSEIF(WITH_LUA54)
77       FIND_PACKAGE(Lua54 REQUIRED)
78     ELSEIF(WITH_LUA53)
79       FIND_PACKAGE(Lua53 REQUIRED)
80     ELSEIF(WITH_LUA52)
81       FIND_PACKAGE(Lua52 REQUIRED)
82     ELSEIF(WITH_LUA51)
83       FIND_PACKAGE(Lua51 REQUIRED)
84     ELSE()
85       FIND_PACKAGE(Lua50 REQUIRED)
86     ENDIF()
87   ENDIF()
88 ENDMACRO()
90 IF(LUABIND_LIBRARIES AND LUABIND_INCLUDE_DIR)
91   # in cache already
92   SET(Luabind_FIND_QUIETLY TRUE)
93 ENDIF()
95 SET(LIBRARY_NAME_RELEASE)
96 SET(LIBRARY_NAME_DEBUG)
98 IF(WITH_LUA54)
99   IF(WITH_STLPORT)
100     LIST(APPEND LIBRARY_NAME_RELEASE luabind_stlport_lua54)
101     LIST(APPEND LIBRARY_NAME_DEBUG luabind_stlport_lua54d)
102   ENDIF()
104   LIST(APPEND LIBRARY_NAME_RELEASE luabind_lua54)
105   LIST(APPEND LIBRARY_NAME_DEBUG luabind_lua54d)
106 ENDIF()
108 IF(HUNTER_ENABLED)
109   LIST(APPEND LIBRARY_NAME_RELEASE luabind luabind09)
110   LIST(APPEND LIBRARY_NAME_DEBUG luabindd luabind09-d)
111 ENDIF()
113 IF(WITH_LUA53)
114   IF(WITH_STLPORT)
115     LIST(APPEND LIBRARY_NAME_RELEASE luabind_stlport_lua53)
116     LIST(APPEND LIBRARY_NAME_DEBUG luabind_stlport_lua53d)
117   ENDIF()
119   LIST(APPEND LIBRARY_NAME_RELEASE luabind_lua53)
120   LIST(APPEND LIBRARY_NAME_DEBUG luabind_lua53d)
121 ENDIF()
123 IF(WITH_LUA52)
124   IF(WITH_STLPORT)
125     LIST(APPEND LIBRARY_NAME_RELEASE luabind_stlport_lua52)
126     LIST(APPEND LIBRARY_NAME_DEBUG luabind_stlport_lua52d)
127   ENDIF()
129   LIST(APPEND LIBRARY_NAME_RELEASE luabind_lua52)
130   LIST(APPEND LIBRARY_NAME_DEBUG luabind_lua52d)
131 ENDIF()
133 IF(WITH_LUA51)
134   IF(WITH_STLPORT)
135     LIST(APPEND LIBRARY_NAME_RELEASE luabind_stlport_lua51)
136     LIST(APPEND LIBRARY_NAME_DEBUG luabind_stlport_lua51d)
137   ENDIF()
139   LIST(APPEND LIBRARY_NAME_RELEASE luabind_lua51)
140   LIST(APPEND LIBRARY_NAME_DEBUG luabind_lua51d)
141 ENDIF()
143 IF(WITH_LUA50)
144   IF(WITH_STLPORT)
145     LIST(APPEND LIBRARY_NAME_RELEASE luabind_stlport_lua50)
146     LIST(APPEND LIBRARY_NAME_DEBUG luabind_stlport_lua50d)
147   ENDIF()
149   LIST(APPEND LIBRARY_NAME_RELEASE luabind_lua50)
150   LIST(APPEND LIBRARY_NAME_DEBUG luabind_lua50d)
151 ENDIF()
153 IF(WITH_STLPORT)
154   LIST(APPEND LIBRARY_NAME_RELEASE luabind_stlport)
155   LIST(APPEND LIBRARY_NAME_DEBUG luabind_stlportd)
156 ENDIF()
158 # generic libraries names
159 LIST(APPEND LIBRARY_NAME_RELEASE luabind libluabind)
160 LIST(APPEND LIBRARY_NAME_DEBUG luabind_d luabindd libluabind_d libluabindd)
162 FIND_PACKAGE_HELPER(Luabind luabind/luabind.hpp RELEASE ${LIBRARY_NAME_RELEASE} DEBUG ${LIBRARY_NAME_DEBUG})
164 FIND_PACKAGE(Boost REQUIRED)
166 IF(LUABIND_INCLUDE_DIR AND Boost_INCLUDE_DIR)
167   IF(LUABIND_LIBRARY_RELEASE AND LUABIND_LIBRARY_DEBUG)
168     # Case where both Release and Debug versions are provided
169     SET(LUABIND_FOUND TRUE)
170     SET(LUABIND_LIBRARIES optimized ${LUABIND_LIBRARY_RELEASE} debug ${LUABIND_LIBRARY_DEBUG})
171   ELSEIF(LUABIND_LIBRARY_RELEASE)
172     # Normal case
173     SET(LUABIND_FOUND TRUE)
174     SET(LUABIND_LIBRARIES ${LUABIND_LIBRARY_RELEASE})
175   ELSEIF(LUABIND_LIBRARY_DEBUG)
176     # Case where Luabind is compiled from sources (debug version is compiled by default)
177     SET(LUABIND_FOUND TRUE)
178     SET(LUABIND_LIBRARIES ${LUABIND_LIBRARY_DEBUG})
179   ENDIF()
180 ENDIF()
182 IF(LUABIND_FOUND)
183   SET(LUABIND_INCLUDE_DIR ${LUABIND_INCLUDE_DIR} ${Boost_INCLUDE_DIR})
184   # Check if luabind/version.hpp exists
185   FIND_FILE(LUABIND_VERSION_FILE luabind/version.hpp PATHS ${LUABIND_INCLUDE_DIR})
186   IF(LUABIND_VERSION_FILE)
187     SET(LUABIND_DEFINITIONS "-DHAVE_LUABIND_VERSION")
188   ENDIF()
190   FIND_CORRECT_LUA_VERSION()
192   IF(NOT Luabind_FIND_QUIETLY)
193     MESSAGE(STATUS "Found Luabind: ${LUABIND_LIBRARIES}")
194   ENDIF()
195 ELSE()
196   IF(NOT Luabind_FIND_QUIETLY)
197     MESSAGE(STATUS "Warning: Unable to find Luabind!")
198   ENDIF()
199 ENDIF()
201 MARK_AS_ADVANCED(LUABIND_LIBRARY_RELEASE LUABIND_LIBRARY_DEBUG Boost_LIB_DIAGNOSTIC_DEFINITIONS)