Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fe6f2b62aea1fe80f74457ae18448ad2dd8bfdb6
[simgrid.git] / tools / cmake / Modules / FindLua51Simgrid.cmake
1 include(./FindLua)
2 find_program(HAVE_LUA_BIN NAMES lua)
3 mark_as_advanced(HAVE_LUA_BIN)
4
5 message(STATUS "Looking for lua.h")
6 if(LUA_INCLUDE_DIR)
7   message(STATUS "Looking for lua.h - found")
8 else()
9   message(STATUS "Looking for lua.h - not found")
10 endif()
11
12 if(HAVE_LUA_BIN)
13   message(STATUS "Found Lua: ${HAVE_LUA_BIN}")
14 endif()
15
16 set(LIB_LUA_NAME "")
17
18 foreach(lib_path ${LUA_LIBRARIES})
19   if(NOT LIB_LUA_NAME)
20     string(REGEX MATCH "liblua.*$" LIB_LUA_NAME "${lib_path}")
21     string(REPLACE ".${LIB_EXE}" "" LIB_LUA_NAME "${LIB_LUA_NAME}")
22     string(REPLACE "lib" "" LIB_LUA_NAME "${LIB_LUA_NAME}")
23     if(LIB_LUA_NAME)
24       string(REPLACE "/lib${LIB_LUA_NAME}.${LIB_EXE}" "" LUA_LIBRARY_DIR ${lib_path})
25     endif()
26   endif()
27 endforeach(lib_path ${LUA_LIBRARIES})
28
29 message(STATUS "Looking for lib lua")
30 if(LUA_LIBRARY_DIR)
31   message(STATUS "Looking for lib lua - found")
32   message(STATUS "Lua version: ${LUA_VERSION_STRING}")
33   message(STATUS "Lib path   : ${LUA_LIBRARY_DIR}")
34 else()
35   message(STATUS "Looking for lib lua - not found")
36 endif()
37
38 if(LUA_FOUND)
39   if(LUA_VERSION_MAJOR EQUAL 5 AND LUA_VERSION_MINOR EQUAL 3)
40     set(HAVE_LUA 1)
41     include_directories(${LUA_INCLUDE_DIR})
42     link_directories(${LUA_LIBRARY_DIR})
43   else()
44     message(FATAL_ERROR "Error: Lua version 5.3 is required, but version ${LUA_VERSION_STRING} found instead.")
45   endif()
46 else()
47   message(FATAL_ERROR "Error: Lua version 5.3 is required, but Lua not found.")
48 endif()